Is there a way to trigger an event on map exit? Ideally this would be universal – there's a little thing I'd like to do every time a player switches to a new area.
Trigger an event on map exit?
Javascript/Plugin SupportDoes MV have common events? Then you won't need a plugin. Just make a common event that does whatever you'd like to happen on map change, and Call Common Event after the transfer command in each map transfer event.
That's a lot of extra work to have to add that to every single place there's a map transfer event which makes my programmer brain cry. It violates the DRY principle ("Don't Repeat Yourself").
Sure, it would work (but begging for potentially sneaky bugs if I happen to miss an event somewhere). There Has To Be A Better Way.
How about this?
alias_Game_Interpreter_command201 = Game_Interpreter.prototype.command201;
Game_Interpreter.prototype.command201 = function () {
$gameTemp.reserveCommonEvent(1);
alias_Game_Interpreter_command201.call(this);
};
Runs whenever you use the Transfer Player event command. Change 1 to the id of the common event.
Edit: Here's a version where it the common event is only called when the next map is not the same:
alias_Game_Interpreter_command201 = Game_Interpreter.prototype.command201;
Game_Interpreter.prototype.command201 = function () {
$gameTemp.reserveCommonEvent(1);
alias_Game_Interpreter_command201.call(this);
};
Runs whenever you use the Transfer Player event command. Change 1 to the id of the common event.
Edit: Here's a version where it the common event is only called when the next map is not the same:
Code:
alias_Game_Interpreter_command201 = Game_Interpreter.prototype.command201;
Game_Interpreter.prototype.command201 = function () {
if (this._params[1] !== $gameMap.mapId()) {
$gameTemp.reserveCommonEvent(1);
}
alias_Game_Interpreter_command201.call(this);
};
command ... 201? 🤔
that certainly looks like exactly what I need, thank you, there is no way I would have ever found that on my own. It's getting late, so I'm probably not going to get this working tomorrow, but I'm gonna trust you & call this solved.
It's just the transfer player command. I edited my post but here's a better solution for you again so you see it, it checks if the command is transferring the player to a new map instead of just another location in the current
alias_Game_Interpreter_command201 = Game_Interpreter.prototype.command201;
Game_Interpreter.prototype.command201 = function () {
if (this._params[1] !== $gameMap.mapId()) {
$gameTemp.reserveCommonEvent(1);
}
alias_Game_Interpreter_command201.call(this);
};
I've tested it and it works.
Original thread: https://forums.rpgmakerweb.com/threads/trigger-an-event-on-map-exit.59126/