Apply a State to all Enemies

I'm trying to make a skill that applies a certain state to one enemy then apply another state to all enemies. The first part is easy and obvious but for the second part I'm trying to use Yanfly's Skill Core and do an <After Eval> to apply the state to all enemies. I've tried:

$gameTroop.members().each {|a| a.add_state(24)}

$gameTroop.aliveMembers().every(function(member.add_state(24)))

$gameTroop.members().add_state(24)

$gameTroop.alive_members.all.add_state(24)

$gameTroop.battle_members().all.add_state(24)

None of these have worked. Simply put, what is the script call to apply a state to all enemies?
I think this will take more than one line to pull off. Try something like this:

<After Eval>
var members= target.friendsUnit().aliveMembers();
for (var i = 0; i < members.length; i++) {
var member = members;
if (member) {
member.addState(24);
}
}
</After Eval>

You need to somehow divide the group up and apply the state individually. I think this is how, but I'm not certain.
If that doesn't work, you can grab *someone's* "Infectious State's Plug In. That's REALLY flexible and can very easily accomplish what you're seeking. I'd post the links etc., but I am faaaar too sleepy. 🙁

Best luck!! If you can't find it or want more direction, feel free to PM me. 🙂
-Mia
I think this will take more than one line to pull off. Try something like this:

<After Eval>
var members= target.friendsUnit().aliveMembers();
for (var i = 0; i < members.length; i++) {
var member = members;
if (member) {
member.addState(24);
}
}
</After Eval>

You need to somehow divide the group up and apply the state individually. I think this is how, but I'm not certain.

I was wondering if I had to do a loop... thanks man. When I first used your code it gave me the "TypeError: undefined is not a function" error. I noticed it just needed to have members[i ]; (but the "i" really doesn't have a space after it, that makes this site do italics) so I fixed that one thing and it worked! Thanks!

<After Eval>
var members = target.friendsUnit().aliveMembers();
for (var i = 0; i < members.length; i++) {
var member = members[i ];
if (member) {
member.addState(24);
}
}
</After Eval>
Oh! I didn't intend to put a space there; that was a typo. But I'm glad it worked.

Original thread: https://forums.rpgmakerweb.com/threads/apply-a-state-to-all-enemies.76653/