Script Map ID $gameMap._mapId

The Control Variables command DOES give you the ID of the current map. It didn't work for you because after you ran that command, you ran another one overwriting what was in the variable with something else.

You don't need to use a script when you have an event command that does exactly what you want.
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/script-map-id-gamemap-_mapid.99719/