gilgamar

Veteran
Veteran
Joined
Jan 28, 2016
Messages
132
Reaction score
60
First Language
English
Primarily Uses
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:

gilgamar

Veteran
Veteran
Joined
Jan 28, 2016
Messages
132
Reaction score
60
First Language
English
Primarily Uses
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.
 

PhantomCooper

Villager
Member
Joined
Dec 3, 2015
Messages
6
Reaction score
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.
 

gilgamar

Veteran
Veteran
Joined
Jan 28, 2016
Messages
132
Reaction score
60
First Language
English
Primarily Uses
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.
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
83
Reaction score
17
First Language
English
Primarily Uses
RMMV
works perfectly, and just saved me endless headaches. thank you gilgamar!!!  BD
 

styx92

Veteran
Veteran
Joined
Jan 7, 2016
Messages
310
Reaction score
39
First Language
German
Primarily Uses
Great like always!


Its normal, that the menu will closed after eqip the weapon/armor, with the common event?
 

styx92

Veteran
Veteran
Joined
Jan 7, 2016
Messages
310
Reaction score
39
First Language
German
Primarily Uses

styx92

Veteran
Veteran
Joined
Jan 7, 2016
Messages
310
Reaction score
39
First Language
German
Primarily Uses

SoSick.

Veteran
Veteran
Joined
Jun 29, 2016
Messages
224
Reaction score
192
First Language
english
Primarily Uses
RMMV
Just stumbled on this, very handy! how do I download it? xD


thanks
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
691
Reaction score
615
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:

SoSick.

Veteran
Veteran
Joined
Jun 29, 2016
Messages
224
Reaction score
192
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.,
 

waynee95

Inactive
Veteran
Joined
Jul 2, 2016
Messages
691
Reaction score
615
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:

SoSick.

Veteran
Veteran
Joined
Jun 29, 2016
Messages
224
Reaction score
192
First Language
english
Primarily Uses
RMMV
wow thanks @waynee95 pretty handy information for anyone using rpg maker mv.
 

DelphiniumVII

Villager
Member
Joined
Oct 27, 2015
Messages
8
Reaction score
1
First Language
English
This crashes on startup. Says "undefined is not a function"
 

krain11

Villager
Member
Joined
Mar 24, 2017
Messages
11
Reaction score
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.
a>
https://ibb.co/mPYVqa
 
Last edited:

AUXturnA

Villager
Member
Joined
Jan 28, 2017
Messages
8
Reaction score
7
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...
 

Attachments

  • EquipCommonEvent.js
    4.7 KB · Views: 238
Last edited:

gilgamar

Veteran
Veteran
Joined
Jan 28, 2016
Messages
132
Reaction score
60
First Language
English
Primarily Uses
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.
 

cuby

Perpetual Toil
Veteran
Joined
Jun 20, 2015
Messages
83
Reaction score
17
First Language
English
Primarily Uses
RMMV
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.
 

AUXturnA

Villager
Member
Joined
Jan 28, 2017
Messages
8
Reaction score
7
First Language
Japanese
Primarily Uses
RMMV
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.
 

Attachments

  • StateCommonEvent.js
    9.4 KB · Views: 83

Canini

Veteran
Veteran
Joined
Mar 29, 2016
Messages
1,025
Reaction score
691
First Language
Swedish
Primarily Uses
RMVXA
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?
 

Latest Threads

Latest Posts

Latest Profile Posts

Finally started working on Grim Trigger episode 2 today :LZScat: it's half comic/half visual novel!

GfY3Rwj.png
Is it interesting to get more backstory on villains? A key moment in their past, their childhood, or maybe something that shows they've always been that way? To see or not to see?
"Everything tastes like chicken until it's chicken, then it doesn't taste like chicken."
Context: chicken samosas do not taste like chicken. I thought it was veggie samosas.
Just another ordinary evening.
This pig girl is a merchant and playable character.
Currently there's no name for her yet. a suggestion is welcomed.
Merchant.jpg
Merchant-1.jpg
Want for a Nail: I'm trying to figure out what controllers work with MZ, one support thread, a plugin request thread, a dead controller, and a $48 eBay purchase, and a PS1/PS2 USB adapter later. Still stuck with keyboard controls...

Forum statistics

Threads
110,353
Messages
1,052,581
Members
143,394
Latest member
flopinou74
Top