[2.2.x] G_SetCustomExitVars overrides special stages
At some point, the behavior of G_SetCustomExitVars was changed to set the map's next level, superseding emerald tokens. This really doesn't feel like super well thought through behavior though, as there's some important ramifications:
Its no longer possible to create a standard, Super Mario World style alternate exit using Lua, unless you want it to replace special stages.
Its no longer possible to create a standard, Super Mario World style alternate exit using linedef type 2, as it goes through the same code path that the G_SetCustomExitVars change modified. Thus, linedef type 2 overrides the special stage, eating an emerald token.
Its unreasonable to work around this behavior by using G_SetCustomExitVars to warp to the special stage manually, as the player will get stuck in a loop of going to special stages unless you manually set the exit of that special stage, forcing the Lua programmer to recreate the emerald token logic, including accounting for what happens when the player still has emerald tokens left.
Regular exit:
Custom exit (using linedef type 2):