Equipment Common Events

Discussion in 'JS Plugins In Development' started by gilgamar, Feb 21, 2016.

    Tags:
  1. gilgamar

    gilgamar Veteran Veteran

    Messages:
    132
    Likes Received:
    55
    Location:
    Alberta, Canada
    First Language:
    English
    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

    /*=============================================================================
    * 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

    /*=============================================================================
    * 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

    /*=============================================================================
    * 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!
     
    Last edited by a moderator: Mar 9, 2016
    #1
    SoftCloud, fizzly, SpookySoul and 2 others like this.
  2. gilgamar

    gilgamar Veteran Veteran

    Messages:
    132
    Likes Received:
    55
    Location:
    Alberta, Canada
    First Language:
    English
    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.
     
    #2
  3. PhantomCooper

    PhantomCooper Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    English
    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.
     
    #3
  4. gilgamar

    gilgamar Veteran Veteran

    Messages:
    132
    Likes Received:
    55
    Location:
    Alberta, Canada
    First Language:
    English
    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.
     
    #4
  5. cuby

    cuby Villager Member

    Messages:
    18
    Likes Received:
    3
    First Language:
    English
    works perfectly, and just saved me endless headaches. thank you gilgamar!!!  BD
     
    #5
  6. styx92

    styx92 Veteran Veteran

    Messages:
    310
    Likes Received:
    38
    First Language:
    German
    Great like always!


    Its normal, that the menu will closed after eqip the weapon/armor, with the common event?
     
    #6
  7. styx92

    styx92 Veteran Veteran

    Messages:
    310
    Likes Received:
    38
    First Language:
    German
    Bumb?^^
     
    #7
  8. styx92

    styx92 Veteran Veteran

    Messages:
    310
    Likes Received:
    38
    First Language:
    German
    Bump?
     
    #8
  9. SoSick.

    SoSick. Veteran Veteran

    Messages:
    199
    Likes Received:
    174
    Location:
    UK
    First Language:
    english
    Primarily Uses:
    RMMV
    Just stumbled on this, very handy! how do I download it? xD


    thanks
     
    #9
  10. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    589
    Likes Received:
    458
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    @2FaSt I think you actually need to copy the content of the spoiler with the newest version into an .js file.
     
    Last edited by a moderator: Nov 2, 2016
    #10
  11. SoSick.

    SoSick. Veteran Veteran

    Messages:
    199
    Likes Received:
    174
    Location:
    UK
    First Language:
    english
    Primarily Uses:
    RMMV
    Thanks @waynee95 I have no experience in js department haha, how do I make a js file? thanks for helping out pal.,
     
    #11
  12. waynee95

    waynee95 Lunatic Coder Veteran

    Messages:
    589
    Likes Received:
    458
    Location:
    Germany
    First Language:
    German
    Primarily Uses:
    RMMV
    @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.
     
    Last edited by a moderator: Nov 2, 2016
    #12
  13. SoSick.

    SoSick. Veteran Veteran

    Messages:
    199
    Likes Received:
    174
    Location:
    UK
    First Language:
    english
    Primarily Uses:
    RMMV
    wow thanks @waynee95 pretty handy information for anyone using rpg maker mv.
     
    #13
  14. DelphiniumVII

    DelphiniumVII Villager Member

    Messages:
    8
    Likes Received:
    1
    First Language:
    English
    This crashes on startup. Says "undefined is not a function"
     
    #14
  15. krain11

    krain11 Villager Member

    Messages:
    11
    Likes Received:
    0
    First Language:
    English
    Primarily Uses:
    RMMV
    Same thing happens to me. Game just crash at the beginning. I really need this plugin.

    Here's a screen shot of the error.
    [​IMG] https://ibb.co/mPYVqa
     
    Last edited: Apr 6, 2017
    #15
  16. AUXturnA

    AUXturnA Villager Member

    Messages:
    5
    Likes Received:
    2
    First Language:
    Japanese
    Primarily Uses:
    RMMV
    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...
     

    Attached Files:

    Last edited: Jul 4, 2017
    #16
    Matt Slykhuis and Uzuki like this.
  17. gilgamar

    gilgamar Veteran Veteran

    Messages:
    132
    Likes Received:
    55
    Location:
    Alberta, Canada
    First Language:
    English
    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.
     
    #17
    cuby likes this.
  18. cuby

    cuby Villager Member

    Messages:
    18
    Likes Received:
    3
    First Language:
    English
    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.
     
    #18
  19. AUXturnA

    AUXturnA Villager Member

    Messages:
    5
    Likes Received:
    2
    First Language:
    Japanese
    Primarily Uses:
    RMMV
    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.
     

    Attached Files:

    #19
  20. Canini

    Canini Veteran Veteran

    Messages:
    941
    Likes Received:
    612
    First Language:
    Swedish
    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?
     
    #20

Share This Page