The RPG Maker Resource Kit

RMRK RPG Maker Creation => MV => MV Scripts Database => Topic started by: exhydra on July 06, 2016, 11:10:05 PM

Title: Map Transfer Common Event
Post by: exhydra on July 06, 2016, 11:10:05 PM
Map Transfer Common Event
Version: 1.0.0
Author: Exhydra
Date: 6 July 2016

Version History



Description


This script lets you instantly run a specified common event when exiting or entering a map.

Features



Instructions


Place the script in your plugins folder and import it through the Plugin Manager.

Include the following tag(s) into the 'note' box of the map you wish to use the 'Map Transfer Common Event' plugin on.

Code: [Select]
   <mtceEn:commonEventId>
   ├─Run specified common event when entering the map.
   │
   ├─commonEventId
   ├ Value ► Numeric
   └ The ID of the common event.

   <mtceEx:commonEventId>
   ├─Run specified common event when exiting the map.
   │
   ├─commonEventId
   ├ Value ► Numeric
   └ The ID of the common event.

Plugin


Pastebin Link: http://pastebin.com/iq2iyYbm

Code: [Select]
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// █▐▐  Map Transfer Common Event
// ╞══════════════════════════════════════════════════════════════════════════════════╡
// █▐▐  Alias(s) and/or Addition(s)
// ├──────────────────────────────────────────────────────────────────────────────────┤
// ├── Game_Map
// │   ├ [ALIAS] initialize
// │   ├ [ALIAS] setup
// │   └ [NEW]   mtceRunCommonEvent
// ╞══════════════════════════════════════════════════════════════════════════════════╡
/*:
 *  @plugindesc Run a specified common event when entering or exiting a map.
 *  @author Exhydra
 *
 *  @help
 * ▄ Plugin       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
 *
 *   ┌─ Version : 1.0
 *   ├─ Release : 6th July 2016
 *   ├─ Updated : 6th July 2016
 *   └─ License : Free for Commercial and Non-Commercial Usage
 *
 * ▄ Usage        ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
 *
 *     Place the following tag(s) into the 'note' box of the map you wish to
 *   use the 'Map Transfer Common Event' plugin on.
 *
 *   <mtceEn:commonEventId>
 *   ├─Run specified common event when entering the map.
 *   │
 *   ├─commonEventId
 *   ├ Value ► Numeric
 *   └ The ID of the common event.
 *
 *   <mtceEx:commonEventId>
 *   ├─Run specified common event when exiting the map.
 *   │
 *   ├─commonEventId
 *   ├ Value ► Numeric
 *   └ The ID of the common event.
 *
 * ▄ Example(s)   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
 *
 *   <mtceEn:3>
 *   └─Run common event with the ID of 3 when entering the map.
 *
 *   <mtceEx:11>
 *   └─Run common event with the ID of 11 when exiting the map.
 *
 */
// ╘══════════════════════════════════════════════════════════════════════════════════╛
 
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Plugin
// ╘══════════════════════════════════════════════════════════════════════════════════╛

var Imported = Imported || {};
Imported.EXA_MapTransferCommonEvent = true;

var EXA  = EXA      || {};
EXA.MTCE = EXA.MTCE || {};

// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Game_Map
// ╘══════════════════════════════════════════════════════════════════════════════════╛

// ALIAS ─────────────────────────────────────────────────────────────────────────────┐
// □ [Function] initialize
// └──────────────────────────────────────────────────────────────────────────────────┘

EXA.MTCE.Game_Map_initialize = Game_Map.prototype.initialize;

Game_Map.prototype.initialize = function() {

this._mtceInterpreter = new Game_Interpreter();
this._mtceEnterEvent  = 0;
this._mtceExitEvent   = 0;

    EXA.MTCE.Game_Map_initialize.call(this)

}; // Game_Map ‹‹ initialize

// ALIAS ─────────────────────────────────────────────────────────────────────────────┐
// □ [Function] setup
// └──────────────────────────────────────────────────────────────────────────────────┘

EXA.MTCE.Game_Map_setup = Game_Map.prototype.setup;

Game_Map.prototype.setup = function(mapId) {

if ($gamePlayer.newMapId() != $gameMap.mapId()) {
$gameMap.mtceRunCommonEvent(this._mtceExitEvent);
}

    EXA.MTCE.Game_Map_setup.call(this, mapId);

this._mtceEnterEvent = $dataMap.meta.mtceEn || 0;
this._mtceExitEvent  = $dataMap.meta.mtceEx || 0;

if ($gamePlayer.newMapId() == $gameMap.mapId()) {
$gameMap.mtceRunCommonEvent(this._mtceEnterEvent);
}

}; // Game_Map ‹‹ setup

// NEW ───────────────────────────────────────────────────────────────────────────────┐
// □ [Function] mtceCommonEvent
// └──────────────────────────────────────────────────────────────────────────────────┘
 
Game_Map.prototype.mtceRunCommonEvent = function(cevId) {

if (cevId <= 0) return;

var mtceEvent = $dataCommonEvents[cevId];
this._mtceInterpreter.setup(mtceEvent.list);

for (var i = 0; i < mtceEvent.list.length; i++) {
this._mtceInterpreter.executeCommand();
}

this._mtceInterpreter.clear;

}; // Game_Map ‹‹ mtceCommonEvent

// ▌▌██████████████████████████████████████ EOF █████████████████████████████████████▐▐

Credit



Support


Post in this thread if you have any comments or questions.

Author's Notes


RPG Maker MV port of modern algebra's Map Transfer Common Event for RPG Maker VXA.

Terms of Use


Free for commercial and non-commercial usage.
Title: Re: Map Transfer Common Event
Post by: yuyu! on July 07, 2016, 09:25:42 PM
Nice!! Thanks for the port! :-)