How do I make battle events that move a player to a different room?

I'm working on a project where I'm using a battle as part of the storytelling - basically, you're suddenly attacked, told some cryptic stuff, then the battle ends after a few turns, transferring you to a different map in the process.
What I've been doing is I've got a Troop made up of a single enemy. It's designed to use 3 'attacks,' in order after each other. They just trigger a common event that has the two characters talk.
In the 3rd event, it's supposed to [Abort Battle] then transfer the player to a different map and add more text. Instead, it simply ends the event with aborting the battle, and nothing else.

How do I fix this?
The trick is doing things in the right order/placement so that the player doesn't see the map change.

It doesn't work inside of battle because at that time the game is in battle, not the map, so there is no player to transfer.

I would try one of these things.
1 - If the battle is initiated by an event, then add the transfer player on the line before battle processing.

2 - Or, have the event inside battle with the cryptic stuff set a switch. On the map where the player was, put an event with a page 2 that has that switch as the condition. That page is Autorun, does transfer player, then sets a self-switch to a blank page 3.
To hide the transfer, you can use a Fadeout Screen command in the troop event, then Fadein Screen in the map event that starts the battle, e.g.

◆Battle Processing:WeDoALittleTalking ◆Transfer Player:MAP002 (7,4) (Fade: None) ◆Fadein Screen
...but yeah, that is weird. 😅
Spoiler: technical ramble + possible "fix"?
In the core script for both MV and MZ, it seems the Transfer Player command is deliberately programmed to lock the event interpreter indefinitely if used in battle: it returns false ("unsuccessful") and offers no way to advance to the next command, meaning the event retries that command every frame - endless loop! 👋

I can't see why it's written like that, since the map data ($gameMap) certainly does still exist when in battle. I'm guessing it's a bug. You're not seeing the game lock up in your case because the successful Abort Battle command takes precedence: it moves the battle into the "aborting" phase, which causes it to change scene next frame regardless of what the event interpreter is doing. The troop interpreter doesn't get updated on the map scene, and gets cleared if/when the next battle starts.

It's probably safest to just work around it as suggested, but another option is to transfer via a script call, e.g.

var mapId = 2; var x = 3; var y = 4; var d = 0; // 0 = Retain, 2 = Down, 4 = Left, 6 = Right, 8 = Up var fadeType = 0; // 0 = Black, 1 = White, 2 = None $gamePlayer.reserveTransfer(mapId, x, y, d, fadeType);

Or you could try loading this as a plugin, to let the Transfer Player command work in battle:
Spoiler: plugin code
JavaScript:
/*:
 * @target MV
 * @plugindesc Allow Transfer Player in troop events.
 * @help Free to use and/or modify for any project, no credit required.
 */
// Override!
Game_Interpreter.prototype.command201 = function() {
    if (!$gameMessage.isBusy()) {  // <- edit 1 of 2
        var mapId, x, y;
        if (this._params[0] === 0) {  // Direct designation
            mapId = this._params[1];
            x = this._params[2];
            y = this._params[3];
        } else {  // Designation with variables
            mapId = $gameVariables.value(this._params[1]);
            x = $gameVariables.value(this._params[2]);
            y = $gameVariables.value(this._params[3]);
        }
        $gamePlayer.reserveTransfer(mapId, x, y, this._params[4], this._params[5]);
        if (!$gameParty.inBattle()) this.setWaitMode('transfer');  // <- edit 2 of 2
        this._index++;
    }
    return false;
};
This moves the "in battle?" check so it only excludes the wait mode. It's an override, so for maximum compatibility with other plugins, put it near the top of your load order.
I don't exactly understand how the 'technical' fix' works or how to implement it...
I'm using the random encounters to make these battles, since sometimes I have the battle occur in a wide area.
Would there be any way to get around the hardcoded inability to transfer during battles? Is that what caethyril's fix is supposed to do?
My "fix" is plugin code. You'd save it as a .js file (copy it into a text editor, e.g. Notepad, then Save As -> File Type: All Files, Filename: whateverYouLike.js), then import it like any other plugin (via the Plugin Manager).

Personally, though, I would recommend you either:
  1. Use a Script command instead of Transfer Player - this avoids the problem entirely:
    var mapId = 2; var x = 3; var y = 4; var d = 0; // 0 = Retain, 2 = Down, 4 = Left, 6 = Right, 8 = Up var fadeType = 0; // 0 = Black, 1 = White, 2 = None $gamePlayer.reserveTransfer(mapId, x, y, d, fadeType);

  2. Alternatively, use event commands. For random encounters, you can just use an Autorun common event, enabled by turning on its switch in the troop event. This works because by default Autorun/Parallel events only run on the map. (Remember to turn the switch off again at the end of the common event otherwise it will keep repeating.)

    Example:
    • Troop event:

      ◆Tint Screen:(-255,-255,-255,0), 60 frames (Wait) ◆Control Switches:#0010 Battle Transfer = ON ◆Abort Battle
    • Autorun common event:

      ◆Transfer Player:Another Map (7,4) (Fade: None) ◆Tint Screen:(0,0,0,0), 60 frames (Wait) ◆Control Switches:#0010 Battle Transfer = OFF
I've used Tint Screen here, because that's what worked for me. I tried with Fadeout/Fadein Screen but for some reason it didn't fade in again properly (everything else worked). 😴

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-battle-events-that-move-a-player-to-a-different-room.152812/