Advertisement
Guest User

IsiahEquipCommonEvents

a guest
Aug 15th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.48 KB | Software | 0 0
  1. //=============================================================================
  2. // IsiahEquipCommonEvents                                                  
  3. //=============================================================================
  4.  
  5. /*:
  6.  *
  7.  * @author Isiah Brighton
  8.  * @plugindesc v1.00 Allows common events to be called when changing equipment
  9.  *
  10.  * @help
  11.  *
  12.  * ============================================================================
  13.  * Weapon and Armor Notetags
  14.  * ============================================================================
  15.  *
  16.  * <Equip Common Event X>
  17.  * Replace X with the common event ID. When this equipment is equipped, it will
  18.  * execute the common event with that ID.
  19.  *
  20.  *
  21.  * <Unequip Common Event X>
  22.  * <Remove Common Event X>
  23.  * Replace X with the common event ID. When this equipment is removed, it will
  24.  * execute the common event with that ID.
  25.  *
  26.  *
  27.  * ============================================================================
  28.  * Note about common events in the menu
  29.  * ============================================================================
  30.  *
  31.  * RPG Maker MV does not traditionally support common events inside a menu.
  32.  * For that reason, some Event Commands are not supported within this system.
  33.  *
  34.  * That means if a player equips and then unequips an item, or equips 2 items,
  35.  * they will not execute properly. So these types of commands should be
  36.  * avoided.
  37.  *
  38.  * All commands *should* execute properly except:
  39.  * -The Message category of commands (Show Text, Show Choices etc)
  40.  * -The Movement category
  41.  * -The Picture category
  42.  * -Map category
  43.  * -Battle category
  44.  *
  45.  * Additionally, while the Wait command works, I recommend against using it as
  46.  * the player still has input during this time, and if they exit the menu the
  47.  * common event will stop processing.
  48.  *
  49.  * Finally, the Show Message command works once the player returns to the map,
  50.  * but only the first message is shown.
  51.  *
  52.  *
  53.  * If the player's equipment is changed outside of the menu, such as on the
  54.  * map or in battle, the common events should execute normally.
  55.  *
  56.  *
  57.  * ============================================================================
  58.  * Version History
  59.  * ============================================================================
  60.  *
  61.  * v1.0 - Finished plugin
  62.  *
  63. */
  64.  
  65.  
  66. var Isiah = Isiah || {};
  67.  
  68. Isiah.Game_Actor_changeEquip = Game_Actor.prototype.changeEquip;
  69. Game_Actor.prototype.changeEquip = function (slotId, item)
  70. {
  71.     var oldEquip = this._equips[slotId].object();
  72.     Isiah.Game_Actor_changeEquip.call(this, slotId, item);
  73.     if (this._equips[slotId].object() != oldEquip)
  74.     {
  75.         if (oldEquip && oldEquip._unequipCommonEvent)
  76.             Isiah.__callCommonEventOnMenu(oldEquip._unequipCommonEvent);
  77.  
  78.         if (item && item._equipCommonEvent)
  79.             Isiah.__callCommonEventOnMenu(item._equipCommonEvent);
  80.     }
  81. };
  82.  
  83. Isiah.__callCommonEventOnMenu = function (commonEventId)
  84. {
  85.     if (SceneManager._scene instanceof Scene_MenuBase)
  86.     {
  87.         this.__interpreter = new Game_Interpreter();
  88.         this.__interpreter.setup($dataCommonEvents[commonEventId].list);
  89.     }
  90.     else
  91.         $gameTemp.reserveCommonEvent(commonEventId);
  92. };
  93.  
  94. Isiah.__Scene_MenuBase_update = Scene_MenuBase.prototype.update;
  95. Scene_MenuBase.prototype.update = function ()
  96. {
  97.     Isiah.__Scene_MenuBase_update.call(this);
  98.     this.updateIsiahInterpreter();
  99. };
  100.  
  101. Scene_MenuBase.prototype.updateIsiahInterpreter = function ()
  102. {
  103.     if (Isiah.__interpreter)
  104.     {
  105.         Isiah.__interpreter.update();
  106.     }
  107. };
  108.  
  109. Isiah.EquipCommon_isDatabaseLoaded = DataManager.isDatabaseLoaded;
  110. DataManager.isDatabaseLoaded = function ()
  111. {
  112.     if (!Isiah.EquipCommon_isDatabaseLoaded.call(this)) return false;
  113.     if (!Isiah.loaded_EquipCommon)
  114.     {
  115.         DataManager.processIsiahCommonEventNotetags($dataWeapons);
  116.         DataManager.processIsiahCommonEventNotetags($dataArmors);
  117.  
  118.         Isiah.loaded_EquipCommon = true;
  119.     }
  120.  
  121.     return true;
  122. }
  123.  
  124. DataManager.processIsiahCommonEventNotetags = function (group)
  125. {
  126.     var note = /<equip common event (\d*)/i;
  127.     var unequipNote = /<unequip common event (\d*)/i;
  128.     var unequipNote2 = /<discard common event (\d*)/i;
  129.     for (n = 1; n < group.length; n++)
  130.     {
  131.         var obj = group[n];
  132.         var notedata = obj.note.split(/[\r\n]+/);
  133.         for (var i = 0; i < notedata.length; i++)
  134.         {
  135.             var line = notedata[i];
  136.             if (line.match(note))
  137.             {
  138.                 obj._equipCommonEvent = RegExp.$1;
  139.             }
  140.             else if (line.match(unequipNote) || line.match(unequipNote2))
  141.             {
  142.                 obj._unequipCommonEvent = RegExp.$1;
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement