Advertisement
exhydra

[RPG Maker MV] Map Transfer Common Event

Jul 6th, 2016
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ╒══════════════════════════════════════════════════════════════════════════════════╕
  2. // █▐▐  Map Transfer Common Event
  3. // ╞══════════════════════════════════════════════════════════════════════════════════╡
  4. // █▐▐  Alias(s) and/or Addition(s)
  5. // ├──────────────────────────────────────────────────────────────────────────────────┤
  6. // ├── Game_Map
  7. // │   ├ [ALIAS] initialize
  8. // │   ├ [ALIAS] setup
  9. // │   └ [NEW]   mtceRunCommonEvent
  10. // ╞══════════════════════════════════════════════════════════════════════════════════╡
  11. /*:
  12.  *  @plugindesc Run a specified common event when entering or exiting a map.
  13.  *  @author Exhydra
  14.  *
  15.  *  @help
  16.  * ▄ Plugin       ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
  17.  *
  18.  *   ┌─ Version : 1.0
  19.  *   ├─ Release : 6th July 2016
  20.  *   ├─ Updated : 6th July 2016
  21.  *   └─ License : Free for Commercial and Non-Commercial Usage
  22.  *
  23.  * ▄ Usage        ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
  24.  *
  25.  *     Place the following tag(s) into the 'note' box of the map you wish to
  26.  *   use the 'Map Transfer Common Event' plugin on.
  27.  *
  28.  *   <mtceEn:commonEventId>
  29.  *   ├─Run specified common event when entering the map.
  30.  *   │
  31.  *   ├─commonEventId
  32.  *   ├ Value ► Numeric
  33.  *   └ The ID of the common event.
  34.  *
  35.  *   <mtceEx:commonEventId>
  36.  *   ├─Run specified common event when exiting the map.
  37.  *   │
  38.  *   ├─commonEventId
  39.  *   ├ Value ► Numeric
  40.  *   └ The ID of the common event.
  41.  *
  42.  * ▄ Example(s)   ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
  43.  *
  44.  *   <mtceEn:3>
  45.  *   └─Run common event with the ID of 3 when entering the map.
  46.  *
  47.  *   <mtceEx:11>
  48.  *   └─Run common event with the ID of 11 when exiting the map.
  49.  *
  50.  */
  51. // ╘══════════════════════════════════════════════════════════════════════════════════╛
  52.  
  53. // ╒══════════════════════════════════════════════════════════════════════════════════╕
  54. // ■ [Object] Plugin
  55. // ╘══════════════════════════════════════════════════════════════════════════════════╛
  56.  
  57. var Imported = Imported || {};
  58. Imported.EXA_MapTransferCommonEvent = true;
  59.  
  60. var EXA  = EXA      || {};
  61. EXA.MTCE = EXA.MTCE || {};
  62.  
  63. // ╒══════════════════════════════════════════════════════════════════════════════════╕
  64. // ■ [Object] Game_Map
  65. // ╘══════════════════════════════════════════════════════════════════════════════════╛
  66.  
  67. // ALIAS ─────────────────────────────────────────────────────────────────────────────┐
  68. // □ [Function] initialize
  69. // └──────────────────────────────────────────────────────────────────────────────────┘
  70.  
  71. EXA.MTCE.Game_Map_initialize = Game_Map.prototype.initialize;
  72.  
  73. Game_Map.prototype.initialize = function() {
  74.    
  75.     this._mtceInterpreter = new Game_Interpreter();
  76.     this._mtceEnterEvent  = 0;
  77.     this._mtceExitEvent   = 0;
  78.    
  79.     EXA.MTCE.Game_Map_initialize.call(this)
  80.    
  81. }; // Game_Map ‹‹ initialize
  82.  
  83. // ALIAS ─────────────────────────────────────────────────────────────────────────────┐
  84. // □ [Function] setup
  85. // └──────────────────────────────────────────────────────────────────────────────────┘
  86.  
  87. EXA.MTCE.Game_Map_setup = Game_Map.prototype.setup;
  88.  
  89. Game_Map.prototype.setup = function(mapId) {
  90.  
  91.     if ($gamePlayer.newMapId() != $gameMap.mapId()) {
  92.         $gameMap.mtceRunCommonEvent(this._mtceExitEvent);
  93.     }
  94.  
  95.     EXA.MTCE.Game_Map_setup.call(this, mapId);
  96.    
  97.     this._mtceEnterEvent = $dataMap.meta.mtceEn || 0;
  98.     this._mtceExitEvent  = $dataMap.meta.mtceEx || 0;
  99.  
  100.     if ($gamePlayer.newMapId() == $gameMap.mapId()) {
  101.         $gameMap.mtceRunCommonEvent(this._mtceEnterEvent);
  102.     }
  103.  
  104. }; // Game_Map ‹‹ setup
  105.  
  106. // NEW ───────────────────────────────────────────────────────────────────────────────┐
  107. // □ [Function] mtceCommonEvent
  108. // └──────────────────────────────────────────────────────────────────────────────────┘
  109.  
  110. Game_Map.prototype.mtceRunCommonEvent = function(cevId) {
  111.    
  112.     if (cevId <= 0) return;
  113.    
  114.     var mtceEvent = $dataCommonEvents[cevId];
  115.     this._mtceInterpreter.setup(mtceEvent.list);
  116.    
  117.     for (var i = 0; i < mtceEvent.list.length; i++) {
  118.         this._mtceInterpreter.executeCommand();
  119.     }
  120.    
  121.     this._mtceInterpreter.clear;
  122.    
  123. }; // Game_Map ‹‹ mtceCommonEvent
  124.  
  125. // ▌▌██████████████████████████████████████ EOF █████████████████████████████████████▐▐
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement