// ╒══════════════════════════════════════════════════════════════════════════════════╕
// █▐▐ [MV] Map Transfer Common Event
// ╞══════════════════════════════════════════════════════════════════════════════════╡
/*:
* @plugindesc Instantly run a specified common event when entering or exiting a map.
*
* @author Exhydra
*
* @param
*
* @desc
*
* @default
*
* @help
*/
// ╘══════════════════════════════════════════════════════════════════════════════════╛
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Plugin
// ╘══════════════════════════════════════════════════════════════════════════════════╛
var Exhydra = Exhydra || {};
Exhydra.MTCV = Exhydra.MTCV || {};
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Game_Map
// ╘══════════════════════════════════════════════════════════════════════════════════╛
// ┌──────────────────────────────────────────────────────────────────────────────────┐
// □ [Function] setup
// └──────────────────────────────────────────────────────────────────────────────────┘
Exhydra.MTCV.Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
// Run exit common event
if ($dataMap && $gamePlayer.newMapId() != $gameMap.mapId()) {
$gameMap.instantCommonEvent(this._metaExitEvent);
}
Exhydra.MTCV.Game_Map_setup.call(this, mapId);
// The new map is already loaded before the setup function is called, thus
// overwriting the meta data for the previous map. So I save the exit common
// event id in a variable which is then used in the above code.
this._metaExitEvent = $dataMap['meta'].mtcvEx || 0;
// Run enter common event
if ($dataMap && $gamePlayer.newMapId() == $gameMap.mapId()) {
$gameMap.instantCommonEvent($dataMap['meta'].mtcvEn);
}
}; // Game_Map ‹‹ setup
// ┌──────────────────────────────────────────────────────────────────────────────────┐
// □ [Function] instantCommonEvent
// └──────────────────────────────────────────────────────────────────────────────────┘
Game_Map.prototype.instantCommonEvent = function(cevId) {
if (cevId > 0) {
$gameTemp.reserveCommonEvent(cevId);
this._interpreter.setupReservedCommonEvent();
// The enter common event runs fine without the following code, however the
// exit common event will not execute at all without force-running
// executeCommand() for each entry in the common event. The code works, but
// it is rather ugly.
this._interpreter._list.forEach(function(tempCommon) {
$gameMap._interpreter.executeCommand();
});
}
}; // Game_Map ‹‹ instantCommonEvent
// ▌▌██████████████████████████████████████ EOF █████████████████████████████████████▐▐