Yanfly's EquipReqirements Check if Item ID is equip, NOT slot id.

thebootknifer

Villager
Member
Joined
Nov 18, 2018
Messages
13
Reaction score
1
First Language
English
Primarily Uses
RMMV
Hello again. I'm here with another JS question. This time using Yanfly's EquipRequirements Plugin.

I have armors 2-15 that equip to armor slot 2.
I have armors 77-91 that equip to armor slot 7.

I am trying to set a requirement on armors 77-91 that is dependent on 2-15.
E.g. Armor 77 requires the actor has armor 2 equip in slot 2.
Armor 78 requires the actor has armor 3 equip in slot 2.
etc. It follow this pattern.

This is what I have right now. It does not work because my JS/coding knowledge is next to nothing, but key, I'm trying! This is what I have come up with so far.

<Custom Equip Requirement Condition>

var actor = $gameActors.actor(1); // Is there a way for this to grab the ID of actors 1 through 3, depending on who I'm trying to equip? All 3 of my actors can equip these armors.

var equipment = actor.equips()[2]; // Does this check slot or armor ID? I need it to check the armor ID.
if ($gameActors.actor(1).equips()[2] == 2) {

condition = true;

} else {

condition = false;

}
</Custom Equip Requirement Condition>

Once the above code is complete, I can put it into item slots 77-91 and adjust the necessary numbers.

Thank you in advance!
 

Fornoreason1000

Black Sheep
Veteran
Joined
Mar 1, 2014
Messages
206
Reaction score
95
First Language
English
Primarily Uses
RMMV
to Answer your first Question, Yanfly states this poorly BUT in those tags theres a predefined 'user' property that automatically gets the currently selected actor, here is Yanfly's example using it.

Code:
<Custom Equip Requirement Condition>
     if (user.name() === 'Harold') {
       condition = true;
     } else {
       condition = false;
     }
    </Custom Equip Requirement Condition>
this means user is equal to the currently selected character so there's no need to use $gameActors at all!!


to Answer your second question

Code:
 user.equips()
returns an array of all equipment as their data objects , or their empty slots(null)
so if i had no weapons or Armour but a 1 shield it would look like this

[null, {Weapon Data Object},null,null,null,null]

so calling
Code:
user.equips()[1] ;
>> {id: 3, animationId: 0, description: "", etypeId: 1, traits: Array(2), …}
will return an object which contains all the information about that weapon/Armour. to find more about it check the help the go to JS library and loop for weapons.
this Object has the property id you are looking for which you can get by doing this

Code:
user.equips()[1].id ;
>> 3
HOWEVER!!!
you don't want to be calling .id on NULL , notice when we dont have something equipped that slot is NULL which means 'no Value'. if you call id on it you will get an error.

Code:
user.equips()[1].id ;
>> 3
user.equips()[0].id ; //we have no weapon equipped
>> ERROR!
To avoid this, we want to check if we have a weapon there, Null is a falsey value, which means it will evaluate to false when pased as a condition. Object, Numbers, Strings are "truthy' which means if treated as a condition they will always evalulate to true. Anything thats placed with a == or something similar will get type casted to a Boolean you know true/false the true name of Switches.

Code:
1 == true //true
{} == true //true
(function () {}) == true //true
null == true // false
false == true //false
undefined  == true //false
true == true //true
'a' == true //true
'' == true //false
armed with this knowledge we can do this.

Code:
var otherEquip = user.equips()[2]; //this gets your Head Armour BTW
if (otherEquip) { //checks if other equip is null
     condition = otherEquip.id == 2;
  }
else { //since otherequip is null or something,
    condition = false;
  }
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,081
Members
137,582
Latest member
Spartacraft
Top