Check to see if any enemy has state applied for allowing skill to appear

Hi!


I'm trying to add a skill that needs to check if an enemy is afflicted with a state before the skill appears and can be used. I'm using Yanfly skillcore ect and have come up with this, but i get 'gametroop is undefined' errors. It's true that I haven't defined an enemy note tag, because I want it to check for one with the state applied..


<Custom Show Eval>


if ($game_troop.members().isStateAffected(X)) {


visible = true;


} else {


visible = false;


}


</Custom Show Eval>


any help i appreciated!
1. "$game_troop" is from VX Ace, not from MV. The correct code for MV is "$gameTroop".


2. "$gameTroop.members()" is an array, a list with all enemies. you need to specify the index of the enemy if you want to use the function "isStateAffected()". For example "$gameTroop.members()[0].isStateAffected(X)" (this will check the first enemy.)
I've moved this thread to JS/Plugin Support. Please be sure to post your threads in the correct forum next time. Thank you.
Fantastic! Made changes as above and it works on a fight with one enemy. do i replicate the line or is there a way to check to see if all the enemies in the fight have the state?
to check if all enemies have the state.


$gameTroop.aliveMembers().every(function(member) { return member.isStateAffected(X) })


To check if at last one have the state.


$gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) })
You might also need to use aliveMembers() rather than members() if you only want to check the enemies still remaining.
You might also need to use aliveMembers() rather than members() if you only want to check the enemies still remaining.

In fact, for the 'every' you must use it, otherwise if a single enemy is dead it will not have the state and the condition will be never met.


I will even edit the other post.
Thanks so much for your help! I've entered in this:


<Custom Show Eval>


if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) }) { 


visible = true;


} else {


visible = false;


}


</Custom Show Eval>


however, I'm getting an 'unexpected token {' error


I'm very new at this and I appreciate your help and patience, but I can't figure out what is wrong here.
You need an extra )


Here's what you have, vs what you need:

Code:
if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) }) { 

if ($gameTroop.aliveMembers().some(function(member) { return member.isStateAffected(X) })) {
That's got it! Thanks so much!

Original thread: https://forums.rpgmakerweb.com/threads/check-to-see-if-any-enemy-has-state-applied-for-allowing-skill-to-appear.57894/