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
205
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

Woke up on an awful nightmare of being banned here because some mod didn't liked me in a super-heroes freeform round robin RP where I used throwing normal hammer as power and it was qualified being too OP. XD Nice to read you all guys. Will not wait next nightmares.
Staring at all the RPG Maker versions I have and realizing that my project has been a long time coming. But, I finally feel like I have the knowledge and experience to make it into something good.
We're almost done with the jam game! :D

Forum statistics

Threads
104,324
Messages
1,005,563
Members
135,844
Latest member
andrewshetty123
Top