Alive enemies count / Hit enemies' count

How do I count enemies currently participating in battle?

For example: there is a full AoE skill which gains certain effect depending on how many enemies it hit. How can I make effect(s) depending on number of enemies hit by the skill?
It shouldn't count hidden enemies if possible.

I'm maybe just blind but couldn't find solution anywhere here. 😅

Also, hi RPG Maker Forum!
Depending of what exactly you want to do you might want a plugin, but you could make a common event for it. In either case, you can use the script call
Code:
$gameTroop.aliveMembers().length
to get the number of alive, appeared enemies and then do stuff based on the number. If you use a common event then youd put it in a conditional branch as a script condition and compare it to some number (or save it to a variable with a control variables event command and make comparisons to that variable) to do your additional effects
Depending of what exactly you want to do you might want a plugin, but you could make a common event for it. In either case, you can use the script call
Code:
$gameTroop.aliveMembers().length
to get the number of alive, appeared enemies and then do stuff based on the number. If you use a common event then youd put it in a conditional branch as a script condition and compare it to some number (or save it to a variable with a control variables event command and make comparisons to that variable) to do your additional effects
I saved the variable of currently existing enemies and used it for effect. It works. Big thanks!

Just in case: How can I count enemies directly hit by the skill? (it should exclude those who evaded and immortal/invulnerable ones)

Edit: Crap. AoE skill should activate effect if it hits 2 enemies or less. If it hits 3 enemies and kills 1, the effect still happens because Common Event is being used after attack (and so, sees 2 enemies even though skill hit 3). I guess I should somehow deal damage after calculating number of enemies.
you could place the script call for increasing a variable within the damage formula for the skill, add a condition for the target not resisting death, and have the common event do stuff and clear the variable at the end.
the formula being ran makes it necessary that the skill hit the target in the first place, but that will have drawbacks if you have actors that use autobattle. it'd work if you didn't though.

In my opinion, it would be better to use yanfly's action sequences plugin to make the skill gain whatever bonus effect you want after it hits however many targets.
First time using Action Sequences and yeah, that works very well. Thanks!


1742139935459.png

1742139989626.png


Now, AoE skills adds effect only there is 2 or less enemies at the moment of dealing damage. Killed ones also count cus they were hit obviously.
Will find out about evades and other stuff later.
so since you started an AS, ill continue from there then.
cant test it at the moment, but the basic form of what you'd want would look like this
Code:
<whole action>
action animation
action effect
change variable 5 = $gameTroop.aliveMembers().filter(member => member.result().isHit()).length
</whole action>

<target action>
</target action>
so once your common event does run, the value of the variable is going to be the number of targets the skill hit. by the time the game looks at the alive enemies, they shouldnt have been killed yet by the damage, so anyone who is to be killed by the skill should still count

That being said, if all you are doing is restoring the user's mp based on the number of targets hit, you dont need the variable or the common event and can do it directly through the action sequence and a direct comparison

Code:
<whole action>
action animation
action effect
if $gameTroop.aliveMembers().filter(member=>member.result().isHit()).length < 3
  mp +2: user
end
</whole action>
<target action>
</target action>
so since you started an AS, ill continue from there then.
cant test it at the moment, but the basic form of what you'd want would look like this
Code:
<whole action>
action animation
action effect
change variable 5 = $gameTroop.aliveMembers().filter(member => member.result().isHit()).length
</whole action>

<target action>
</target action>
so once your common event does run, the value of the variable is going to be the number of targets the skill hit. by the time the game looks at the alive enemies, they shouldnt have been killed yet by the damage, so anyone who is to be killed by the skill should still count

That being said, if all you are doing is restoring the user's mp based on the number of targets hit, you dont need the variable or the common event and can do it directly through the action sequence and a direct comparison

Code:
<whole action>
action animation
action effect
if $gameTroop.aliveMembers().filter(member=>member.result().isHit()).length < 3
  mp +2: user
end
</whole action>
<target action>
</target action>
Yeah, it works perfectly, just as I wanted, I had to be more straightforward.

Anyway, it's good to have 2 different problems solved in one thread with almost different ways.
I'm very little known with JS and coding stuff overall so seeing anything similar to script makes me scared LMAO

BIG THANKS!

Original thread: https://forums.rpgmakerweb.com/threads/alive-enemies-count-hit-enemies-count.176271/