HELP with a Yanfly skill requirement function

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
232
Reaction score
39
First Language
English Spanish
Primarily Uses
There is a skill custom requirement plug in, if the eval comes true, the skill is usable, otherwise will not.
Someone helped me with this in the past:

Code:
if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(22) })) {
    value = false;
  } else {
    value = true;
  }
This checks if someone in the enemy troop has the state 22.

Now, what I need is a code that checks if all alive game Party members have state X, lets say 172.

So if all party members have the state 172, the skill is unusable, otherwise, is usable.

Thanks!
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,652
Reaction score
1,105
First Language
EN
Primarily Uses
RMMV
Short answer: swap $gameTroop for $gameParty, replace some with every, and change the state ID as appropriate~
JavaScript:
if ($gameParty.aliveMembers().every(function(member) { return member.isStateAffected(172); })) {
  value = false;
} else {
  value = true;
}
:kaothx:

Explanation: your example uses Array.some to check if at least one element of the array meets the given criteria. For your question, you want Array.every, which checks if all elements of the array meet the given criteria. In case you're interested, you can find a whole list of functions usable with arrays here (scroll down a bit or check the sidebar on the left):
 

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
232
Reaction score
39
First Language
English Spanish
Primarily Uses
Damn, I swear I tried that and didnt worked...so thats why I asked for help...let me double check that and see where I coded that wrong.

Thakyou!!!

EDIT: Yup, that works...don´t know what was wrong when I tried it.
Thanks again.
 
Last edited:

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

Latest Threads

Latest Posts

Latest Profile Posts


:3c here's a thing i made a while while while back
Tried mochi for the first time. It's quite nice. Has a pleasant smell and taste, and is nice and chewy.
made a bio for the protag in my project!
Beggar : "I haven't eat for days..."
Kid : "Just do crime! You will get daily necessity for free in prison~"

Forum statistics

Threads
99,158
Messages
962,449
Members
130,725
Latest member
teendinsaikha
Top