Is there a way to attach variables to a piece of equipment based on if it is equipped?

Hey guys, I'm in the very early stages of development in a project and I am a tad inexperienced with RPGMaker MV, but I was wondering if there was any way I could attach a variable to a piece of equipment so that it would increase or decrease based on whether or not it is equipped.


If that doesn't make sense, the purpose of my question is so that I can implement a feature where the main character's sprite would change based off of what kind of armor they were wearing. I have three different sprites I plan to alternate with, including Light Armor, Medium Armor and Heavy Armor, and what I want to do is include a variable attached to pieces of equipment that tallies up how many pieces of each type of armor a character is wearing, and have their sprite match the highest value for armor. (Like say, if they have 2 pieces of light armor, 3 pieces of medium armor and 4 pieces of heavy armor, that their sprite would match the one designated for heavy armor).


Any insight into this would be greatly appreciated. Thanks 🙂
The best way to handle this is with a plugin that will calculate the values when equipment is changed.


The easiest non-scripting way to do it (well, a small script mod is required) is to turn on a switch when the player opens the Equip window, and have a parallel process common event conditioned by that switch do all your checks and calculations and change the sprite when necessary, and then turn the switch off again.


What will happen is that when the player opens the Equip window, the switch will be turned on.  Whether they change equipment or not, on any character, that switch will be on when you return to the map, so your common event will run.  In the common event you'll go through for each character and check what kind of armor they have and change the sprite accordingly.  At the end you'll turn off the switch so the common event doesn't run again until they go back into the equip window.


Your common event might be simple or complicated depending on how many actors you have that you need to do this for, and how you're identifying a piece of armor as light, medium or heavy (I don't recall there being a flag, but if there is, it'd make things easier).


State which way you want to go (small script change and do everything in a common event, or have a plugin written to handle the whole lot for you) and if necessary I'll move this to the correct forum.
Before I decide which route to go with that, you say it would be less complicated depending on how many actors I have? I'm intending only to have one actor playable throughout the entire game, so I'm hoping maybe that will make it less complex to implement? 


And second, what do you think would be the best route to take? Common eventing or a script/plugin?
how do you determine whether an armor item is light, medium or heavy?


If you only have one actor, I suspect the easiest route to go would be a small script change to turn on the switch, and handle everything with a common event.
As of right now since i'm in relatively early development phase, I'm just marking each item with what type of armor it is (light, medium, heavy). I haven't made any variables or anything yet.
forget about variables.  How are you "marking" each item?  Is it just in the name, or what?  Can you show a screenshot of a couple of your armor items so I can see what you're doing?
Oh! That's what you mean. Basically I'm marking them in the description with the tag [Light Armor]
alright - I'll do something up for you.  Check back here in half an hour or so for results.


Oops ... I messed up and lost what I was working on, so I'm just going to do this from memory. If you try it and it doesn't work, let me know.  Post any error messages that it gives you.


In the rpg_scene.js file, look for this section (in my version it's line 836):

Code:
Scene_Menu.prototype.onPersonalOk = function() {
    switch (this._commandWindow.currentSymbol()) {
    case 'skill':
        SceneManager.push(Scene_Skill);
        break;
    case 'equip':
        SceneManager.push(Scene_Equip);
        break;
    case 'status':
        SceneManager.push(Scene_Status);
        break;
    }
};

Add a line to turn on a switch when the equip scene is loaded.  I'll use switch 5, but you use whatever numbered switch you have available - no leading zeros.

Code:
Scene_Menu.prototype.onPersonalOk = function() {
    switch (this._commandWindow.currentSymbol()) {
    case 'skill':
        SceneManager.push(Scene_Skill);
        break;
    case 'equip':
        $gameSwitches.setValue(5, true); // turn on a switch when the equip scene is opened
        SceneManager.push(Scene_Equip);
        break;
    case 'status':
        SceneManager.push(Scene_Status);
        break;
    }
};



Now create a common event, set to parallel processing, and conditioned by switch 5 (or whatever switch you're going to use).  We'll use 3 variables - one to count light equipment, one to count medium, and one to count heavy.  Substitute whatever variables you're going to use.

Code:
Control Variables: [0001: Light Equipment] = Script: $gameParty.leader().armors().filter(function(item) { return item && item.meta.weight === "light"; }).length
Control Variables: [0002: Medium Equipment] = Script: $gameParty.leader().armors().filter(function(item) { return item && item.meta.weight === "medium"; }).length
Control Variables: [0003: Heavy Equipment] = Script: $gameParty.leader().armors().filter(function(item) { return item && item.meta.weight === "heavy"; }).length

Conditional Branch: Script: $gameVariables.value(3) >= $gameVariables.value(2) && $gameVariables.value(3) >= $gameVariables.value(1)
  ... player has more heavy armor equipped - change sprite to heavy armor
Else
  Conditional Branch: Script: $gameVariables.value(2) >= $gameVariables.value(3) && $gameVariables.value(2) >= $gameVariables.value(1)
    ... player has more medium armor equipped - change sprite to medium armor
  Else
    Conditional Branch: Variable [0001: Light Equipment] > 0
      ... player only has light armor equipped - change sprite to light armor
    Else
      ... player has no armor equipped - change sprite to no armor
    Branch End
  Branch End
Branch End

Control Switches [0005: Equip Window Opened] = OFF

The above assumes you have 4 sprites - one each for heavy, medium, light and no equipment.  If you want to display the 'light' equipment sprite when the player has no equipment, just leave out that last conditional branch altogether, replacing it with the command to change to the light equipment sprite.


Now go into your armor and add the following to the note tag for each piece, depending on what group it's in:

Code:
<weight:light>
<weight:medium>
<weight:heavy>

don't leave any spaces after the :


See how you go with that.
I'll have to try this tomorrow. Thanks a ton for all your work. I'll definitely include you in the credits 🙂

Original thread: https://forums.rpgmakerweb.com/threads/is-there-a-way-to-attach-variables-to-a-piece-of-equipment-based-on-if-it-is-equipped.57027/