How to teleport to a new map at the same location

Hello, I've been trying to get a teleport on a keypress to work all day, unfortunately, I can seem to be able to do it.
Basically, all I would like to do it on Key press A, teleport from any location on Map1 to the same location on Map2.

At the moment I have it set to teleport the player after 60f
1736024935936.png

Code:
// Get the current player's coordinates
var x = $gamePlayer.x;
var y = $gamePlayer.y;

// Defines target map ID
var currentMapId = $gameMap.mapId(1);
var targetMapId = (currentMapId === 1) ? 2 : 1; // Swap between Map001 (ID: 1) and Map002 (ID: 2)

// Transfers the player to the same location on the other map
$gamePlayer.reserveTransfer(targetMapId, x, y, $gamePlayer.direction(), 0);

But really I wanna add it to a key like the Q Key.

I have tried doing
Input.isPressed('L');
and
Input.isPressed('Q');
but it didn't work for some reason.

I followed this little Key Code off a youtube tutorial
1736025021657.png

I would be grateful of any help.
Cheers

I tried this...
1736025212667.png


It didnt work 🙁
L and Q are not mapped by default. You need to put in a plugin file (or run the script in the game, but it won't save, so if you do it that way you'll have to rerun the script every time you launch the game)

Input.keyMapper[76] = 'l';
Input.keyMapper[81] = 'q';

if you put something like this inside a plugin file it should do what you're looking for, but might need further customization like setting restrictions on when the button can be pressed.

JavaScript:
(() => {
    Input.keyMapper[81] = 'q';
  
    _Game_Map_update_alias = Game_Map.prototype.update;
    Game_Map.prototype.update = function() {
        _Game_Map_update_alias.call(this);
        if (Input.isPressed("q")) {
            TransferPlayerOnButtonPress();
        }
    }
  
    TransferPlayerOnButtonPress = function() {
        var x = $gamePlayer.x;
        var y = $gamePlayer.y;

        // Defines target map ID
        var currentMapId = $gameMap.mapId();
        var targetMapId = (currentMapId === 1) ? 2 : 1; // Swap between Map001 (ID: 1) and Map002 (ID: 2)

        // Transfers the player to the same location on the other map
        $gamePlayer.reserveTransfer(targetMapId, x, y, $gamePlayer.direction(), 0);
    }
})();
why are you using script at all?

what you want is a basic ability of the transfer event command.

control variable : game data : player x
control variable : game data : player y
control variable : game data : map id
conditional branch if mapid == 1
> control variable map ID = 2
else
> control variable map id = 1
transfer player (variable based)
L and Q are not mapped by default. You need to put in a plugin file (or run the script in the game, but it won't save, so if you do it that way you'll have to rerun the script every time you launch the game)

Input.keyMapper[76] = 'l';
Input.keyMapper[81] = 'q';

Works perfectly thankyou.

why are you using script at all?

what you want is a basic ability of the transfer event command.

control variable : game data : player x
control variable : game data : player y
control variable : game data : map id
conditional branch if mapid == 1
> control variable map ID = 2
else
> control variable map id = 1
transfer player (variable based)
Yeah I did this as I said at the beginning of this thread, but For some reason it didn't work, so I used a script instead. It will be down to a lack of knowledge of MV. When it came to transfer player, I couldnt seem to set the map ID variables properly.
if you want to swap between maps that happens often, use this [plugin].
it's far easier, than a keymapper to transfer on the spot or anytime.

make sure the maps has the same size to do so 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-to-teleport-to-a-new-map-at-the-same-location.174421/