HELP with a Yanfly skill requirement function

Magusalfador

Veteran
Veteran
Joined
Jun 15, 2014
Messages
239
Reaction score
40
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,708
Reaction score
1,152
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
239
Reaction score
40
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

I spoke with hudell and many programmer about the Window_BattleLog class and we all just agreed to pretend this class just doesn't exists lol
I haven't been able to solidify a cohesive plot so dropped out of a game jam but, on a fun note, I pre-ordered MZ today! :LZSwink:
So I just spent the weekend...playing my own game. The one I released last year. Yep you heard that right.
Goal for MZ? None... I'm still curious how to finish my VXA project and how it looks like when it actually finished. Which will take at least another two years. Coming late again to the party.

Forum statistics

Threads
100,657
Messages
978,136
Members
132,268
Latest member
janetjoradan
Top