Equipment Common Events

● ARCHIVED · READ-ONLY
Started by gilgamar 33 posts Page 1 of 2 View original ↗
  1. Equipment Common Events v1.02


    Instruction
    Add equip/remove common events to weapons and armor via notetags. Ex:

    <EquipCE Event: 1 onequip>
    <EquipCE Event: 2 onremove>


    The preceding lines will run common event ID 0001 on equip and common event ID 0002 on remove for the weapon or armor tagged.


    The event does not run until menu is closed. If the item is equipped or removed multiple times before closing the menu only the last event will run.


    Compatibility


    Should be compatible with most everything but let me know if you encounter issues.


    Use Case Examples


    Want to make a cursed ring? Sprint shoes? Teleportation wand? You can do all these things and more with EquipCE.


    Known Bugs


    - If you switch from an item having onremove to an item having onequip only one of the common events will run.


    Using Tsukihime's CommonEventQueue will fix this.


    http://himeworks.com/2015/10/common-event-queue-mv/


    Version 1.02


    - Event runs immediately by closing out the main menu.


    Script v1.02

    Spoiler
    /*=============================================================================
    * Gilgamar - Equip Common Event
    * By Gilgamar
    * G_EquipCE.js
    * Version: 1.02
    * Free for commercial and non commercial use.
    *=============================================================================*/

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

    var EquipCE = {};

    /*:
    * @plugindesc v1.02 Enable equipment common events.
    * @author Gilgamar
    *
    * @help
    * ============================================================================
    * Introduction
    * ============================================================================
    * Enables weapon and armor equip/remove common events via notetags. Ex:
    *
    * <EquipCE Event: 1 onequip>
    * <EquipCE Event: 2 onremove>
    *
    * The precedling lines will run common event ID 001 on equip and common event
    * ID 002 on remove for the weapon or armor tagged.
    *
    * The event does not run until menu is closed. If the item is equipped or
    * removed multiple times before closing the menu only the last event will run.
    *
    * ============================================================================
    * Changelog
    * ============================================================================
    * Version 1.02:
    * - Added SceneManager.goto(Scene_Map) after common event so the event will
    * run immediately on equip/remove
    *
    * Version 1.01:
    * - Moved event check into Game_Actor.changeEquip() so it works on optimize
    *
    * Version 1.00:
    * - Enables weapon and armor equip/remove common events via notetags
    */

    //=============================================================================
    // Notetags
    //=============================================================================

    EquipCE.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
    DataManager.isDatabaseLoaded = function() {
    if (!EquipCE.DataManager_isDatabaseLoaded.call(this)) return false;
    DataManager.processEQUIPCENotetags1($dataWeapons);
    DataManager.processEQUIPCENotetags1($dataArmors);
    return true;
    };

    DataManager.processEQUIPCENotetags1 = function(group) {
    // Check if function called more than once
    if (DataManager.processEQUIPCENotetags1.calledTimes++ > 1) return;

    var note1 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONEQUIP)>/i;
    var note2 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONREMOVE)>/i;

    for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);
    // console.log(notedata)
    obj.commonEvents = [];
    for (var i = 0; i < notedata.length; i++) {
    var line = notedata;
    if (line.match(note1)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onequip'
    });
    } else if (line.match(note2)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onremove'
    });
    }
    }
    }
    // console.log(group)

    };
    DataManager.processEQUIPCENotetags1.calledTimes = 0;

    //=============================================================================
    // EquipCE Functions
    //=============================================================================

    EquipCE.changeEquip = function(item, occurs) {
    if (!item) return;
    for (var i = 0; i < item.commonEvents.length; i++){
    var commonEvent = item.commonEvents;
    if (commonEvent.occurs === occurs) {
    // console.log(commonEvent)
    $gameTemp.reserveCommonEvent(commonEvent.eventId);
    SceneManager.goto(Scene_Map);
    }
    }
    }
    EquipCE.onEquip = function(item) {this.changeEquip(item, 'onequip')}
    EquipCE.onRemove = function(item) {this.changeEquip(item, 'onremove')}

    //=============================================================================
    // RPG Maker Overrides
    //=============================================================================

    EquipCE.Game_Actor_changeEquip = Game_Actor.prototype.changeEquip;
    Game_Actor.prototype.changeEquip = function(slotId, item) {
    var oldItem = this.equips()[slotId];
    var newItem = item;
    EquipCE.Game_Actor_changeEquip.call(this, slotId, item);
    if (this.equips()[slotId] === newItem) {
    // Change equip succeeded or same item equipped
    EquipCE.onEquip(newItem); // Check equip events
    EquipCE.onRemove(oldItem); // Check remove events
    }
    };

    // Game_Actor.prototype.changeEquip = function(slotId, item) {
    // if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
    // (!item || this.equipSlots()[slotId] === item.etypeId)) {
    // this._equips[slotId].setObject(item);
    // this.refresh();
    // }
    // };






    Script v1.01

    Spoiler
    /*=============================================================================
    * Gilgamar - Equip Common Event
    * By Gilgamar
    * G_EquipCE.js
    * Version: 1.01
    * Free for commercial and non commercial use.
    *=============================================================================*/

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

    var EquipCE = {};

    /*:
    * @plugindesc v1.01 Enable equipment common events.
    * @author Gilgamar
    *
    * @help
    * ============================================================================
    * Introduction
    * ============================================================================
    * Enables weapon and armor equip/remove common events via notetags. Ex:
    *
    * <EquipCE Event: 1 onequip>
    * <EquipCE Event: 2 onremove>
    *
    * The precedling lines will run common event ID 001 on equip and common event
    * ID 002 on remove for the weapon or armor tagged.
    *
    * The event does not run until menu is closed. If the item is equipped or
    * removed multiple times before closing the menu only the last event will run.
    *
    * ============================================================================
    * Changelog
    * ============================================================================
    * Version 1.01:
    * - Moved event check into Game_Actor.changeEquip() so it works on optimize.
    *
    * Version 1.00:
    * - Enables weapon and armor equip/remove common events via notetags
    */

    //=============================================================================
    // Notetags
    //=============================================================================

    EquipCE.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
    DataManager.isDatabaseLoaded = function() {
    if (!EquipCE.DataManager_isDatabaseLoaded.call(this)) return false;
    DataManager.processEQUIPCENotetags1($dataWeapons);
    DataManager.processEQUIPCENotetags1($dataArmors);
    return true;
    };

    DataManager.processEQUIPCENotetags1 = function(group) {
    // Check if function called more than once
    if (DataManager.processEQUIPCENotetags1.calledTimes++ > 1) return;

    var note1 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONEQUIP)>/i;
    var note2 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONREMOVE)>/i;

    for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);
    // console.log(notedata)
    obj.commonEvents = [];
    for (var i = 0; i < notedata.length; i++) {
    var line = notedata;
    if (line.match(note1)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onequip'
    });
    } else if (line.match(note2)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onremove'
    });
    }
    }
    }
    console.log(group)

    };
    DataManager.processEQUIPCENotetags1.calledTimes = 0;

    //=============================================================================
    // EquipCE Functions
    //=============================================================================

    EquipCE.changeEquip = function(item, occurs) {
    if (!item) return;
    for (var i = 0; i < item.commonEvents.length; i++){
    var commonEvent = item.commonEvents;
    if (commonEvent.occurs === occurs) {
    console.log(commonEvent)
    $gameTemp.reserveCommonEvent(commonEvent.eventId)
    }
    }
    }
    EquipCE.onEquip = function(item) {this.changeEquip(item, 'onequip')}
    EquipCE.onRemove = function(item) {this.changeEquip(item, 'onremove')}

    //=============================================================================
    // RPG Maker Overrides
    //=============================================================================

    // Game_Actor.prototype.changeEquip = function(slotId, item) {
    // if (this.tradeItemWithParty(item, this.equips()[slotId]) &&
    // (!item || this.equipSlots()[slotId] === item.etypeId)) {
    // this._equips[slotId].setObject(item);
    // this.refresh();
    // }
    // };

    EquipCE.Game_Actor_changeEquip = Game_Actor.prototype.changeEquip
    Game_Actor.prototype.changeEquip = function(slotId, item) {
    var oldItem = this.equips()[slotId];
    var newItem = item;
    EquipCE.Game_Actor_changeEquip.call(this, slotId, item);
    if (this.equips()[slotId] === newItem) {
    // Change equip succeeded or same item equipped
    EquipCE.onEquip(newItem); // Check onEquip events
    EquipCE.onRemove(oldItem); // Check onRemove events
    }
    };






    Script v1.00

    Spoiler
    /*=============================================================================
    * Gilgamar - Equip Common Event
    * By Gilgamar
    * G_EquipCE.js
    * Version: 1.00
    * Free for commercial and non commercial use.
    *=============================================================================*/

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

    var EquipCE = {};

    /*:
    * @plugindesc v1.00 Enable equipment common events.
    * @author Gilgamar
    *
    * @help
    * ============================================================================
    * Introduction
    * ============================================================================
    * Add equip/remove common events to weapons and armor via notetags. Ex:
    *
    * <EquipCE Event: 1 onequip>
    * <EquipCE Event: 2 onremove>
    *
    * The preceding lines will run common event ID 001 on equip and common event
    * ID 002 on remove for the weapon or armor tagged.
    *
    * The event does not run until menu is closed. If the item is equipped or
    * removed multiple times before closing the menu only the last event will run.
    *
    * ============================================================================
    * Changelog
    * ============================================================================
    * Version 1.00:
    * - Enables weapon and armor onequip/onremove common events via notetags
    */

    //=============================================================================
    // Notetags
    //=============================================================================

    EquipCE.DataManager_isDatabaseLoaded = DataManager.isDatabaseLoaded;
    DataManager.isDatabaseLoaded = function() {
    if (!EquipCE.DataManager_isDatabaseLoaded.call(this)) return false;
    DataManager.processEQUIPCENotetags1($dataWeapons);
    DataManager.processEQUIPCENotetags1($dataArmors);
    return true;
    };

    DataManager.processEQUIPCENotetags1 = function(group) {
    // Check if function called more than once
    if (DataManager.processEQUIPCENotetags1.calledTimes++ > 1) return;

    var note1 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONEQUIP)>/i;
    var note2 = /<(?:EQUIPCE EVENT):[ ](\d+)[ ](ONREMOVE)>/i;

    for (var n = 1; n < group.length; n++) {
    var obj = group[n];
    var notedata = obj.note.split(/[\r\n]+/);
    // console.log(notedata)
    obj.commonEvents = [];
    for (var i = 0; i < notedata.length; i++) {
    var line = notedata;
    if (line.match(note1)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onequip'
    });
    } else if (line.match(note2)) {
    obj.commonEvents.push({
    eventId: parseInt(RegExp.$1),
    occurs: 'onremove'
    });
    }
    }
    }
    console.log(group)

    };
    DataManager.processEQUIPCENotetags1.calledTimes = 0;

    //=============================================================================
    // EquipCE Functions
    //=============================================================================

    EquipCE.checkEvent = function(sceneEquip, occurs){
    var slotId = sceneEquip._slotWindow.index()
    var itemId = sceneEquip.actor()._equips[slotId].itemId()
    var item = $dataArmors[itemId]
    if (!item) return;
    for (var i = 0; i < item.commonEvents.length; i++){
    var commonEvent = item.commonEvents;
    if (commonEvent.occurs === occurs) {
    console.log(commonEvent)
    $gameTemp.reserveCommonEvent(commonEvent.eventId)
    }
    }
    }

    //=============================================================================
    // RPG Maker Overrides
    //=============================================================================

    EquipCE.Scene_Equip_onItemOk = Scene_Equip.prototype.onItemOk
    Scene_Equip.prototype.onItemOk = function() {
    EquipCE.checkEvent(this, 'onremove');
    EquipCE.Scene_Equip_onItemOk.call(this);
    EquipCE.checkEvent(this, 'onequip');
    };






    Terms of use and Credits


    Free to use in any project.


    Credit me as Gilgamar if you use this!
  2. I haven't updated the scripts here yet but I changed the behavior of equip event so it would close the menu and immediately take effect. This is how an item common event works so I wanted to maintain consistency. Also, it makes for a really cool ring of teleportation effect (just be sure to remove the ring in the common event). If someone uses this script and wants to add this feature just put:"  SceneManager.goto(Scene_Map); " directly below the $gameTemp.reserveCommonEvent line in EquipCE.changeEquip.
  3. This is just what I needed for my project. Although there is a error that crashes the game on one of my saves when I use the optimize commands. But I started a fresh character and tried it with the same conditions and it worked fine.

    I'll let you know if any other weird errors crop up, otherwise its working great.
  4. There was an optimize error in version 1.00. I thought I fixed it in 1.01 but I only briefly tested it. If the old save was prior to using this script I then it would probably crash due to differing database entries for the equipment.


    I have another script that works very similar to this one called StateCE which enables common events on States. One feature I added to StateCE is the ability to check which actor was affected by the state in the common event. I am thinking of adding this same feature to EquipCE so you can check who was changing equip. I'm not sure it's possible to determine who is equipping/removing gear in this script at the moment so if you need this feature let me know and I'll add it right away.


    If there are any other features you need let me know and I'll be happy to add it.
  5. works perfectly, and just saved me endless headaches. thank you gilgamar!!!  BD
  6. Great like always!


    Its normal, that the menu will closed after eqip the weapon/armor, with the common event?
  7. Bumb?^^
  8. Bump?
  9. Just stumbled on this, very handy! how do I download it? xD


    thanks
  10. @2FaSt I think you actually need to copy the content of the spoiler with the newest version into an .js file.
  11. Thanks @waynee95 I have no experience in js department haha, how do I make a js file? thanks for helping out pal.,
  12. @2FaSt Open your normal text editor, paste the plugin in there and then click 'Save as', name it 'G_EquipCE.js' and very important click on type and then choose 'All types' and it will save it as a .js file.
  13. wow thanks @waynee95 pretty handy information for anyone using rpg maker mv.
  14. This crashes on startup. Says "undefined is not a function"
  15. Same thing happens to me. Game just crash at the beginning. I really need this plugin.

    Here's a screen shot of the error.
    a> https://ibb.co/mPYVqa
  16. Same thing happens to me.
    So, I look some code in this plugin and do some fix.
    Worked on my project, but in yours, it's not guaranteed and I cannot support about this.
    However, hope this will useful...

    P.S.
    If @gilgamar watching this, please verify my fix and merge to yours...
  17. Sorry I've neglected RPG Maker for nearly two years but hoping to get back at it. There's just been so many changes to the main engine that it may take some reworking to get things to run again.

    @AUXturnA If your fix works it might fix all my plugins which would be really awesome as I think it's just some incompatibility with the latest engine.
  18. Wow, I haven't upgraded in a long time so my script's still working -- had no idea it was broken! Thanks gilgamar for keeping this fantastic script up to date.
  19. gilgamar said:
    Sorry I've neglected RPG Maker for nearly two years but hoping to get back at it. There's just been so many changes to the main engine that it may take some reworking to get things to run again.

    @AUXturnA If your fix works it might fix all my plugins which would be really awesome as I think it's just some incompatibility with the latest engine.
    Well, I cannot fix all of your works as I'm not using it,
    but State Common Events was suffered by similar incompatibility and I did quick-fix for me(it works for me, but at RMMV 1.5.0).
    I upload that file here, so please recheck it(take diff, do some test, etc.), and release it.
  20. Nice! I am trying to ponder how to make teleportation more unique in my game. I want a system where you can pick berries from special trees in the different towns you visit and teleport there. This will be useful for that!

    Just for clarification, is this free to use in commercial projects as well?