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,653
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 Profile Posts

Worst part about doing a plugin based on an existing system: figuring out the best way for developers to set up the data.
Right now, my free time is less when Covid 19 in my country.
Begin to reduce the number of daily infections to 0.
Okay someone really needs to fix that broken railing, its a health hazard...

Forum statistics

Threads
99,210
Messages
963,079
Members
130,798
Latest member
dirty_score
Top