MV Kill all Troops with HP less than X

Trying to get this to work, its fine on editor.

var HP = 2000
for (i=0;typeof $gameTroop.members() !== 'undefined';i++) {for (i = i; HP > $gameTroop.members().hp; i++) {if($gameTroop.members() === 'undefined') {break} else {$gameTroop.members().forEach(member => member.addState(Game_Interpreter.prototype.changeHp.call(this, $gameTroop.members(), Math.round(-$gameTroop.members().mhp), true)))}}}

1667082236146.png


Also this is my plugin list (sorry for the long list, trying to build Overlord's Yggdrasill system with RPG Maker):

1667082317471.png

1667082355252.png

1667082399525.png

1667082435108.png

1667082464604.png

1667082492766.png

1667082521845.png

1667082610764.png
Please re-paste your code using the CODE tags (the </> on the edit bar). Without using that,
1 - none of your spacing/indents are preserved, and
2 - all of your [i] and other array commands are turned into BBCode.

Some of the existing code looks a bit odd to me, but it's overall not legible because of that stuff missing.

It would also help if you explained where you're using this code - are you calling it from an event? In the damage formula of a skill?
another part as HP is not defined anywhere + your YEP plugin are out of place.
run the ALOE_YEP_PluginOrderChecker in my spoiler to correct them in your list.

if they are out of place, you get bad behavior and they work incorrectly.
There are a lot of errors in that code, even without further context. Try this instead:
JavaScript:
for (var enemy of $gameTroop.members()) {
  if (enemy.hp < 2000) {
    enemy.addState(1);
    enemy.performCollapse();
  }
}

I'm guessing the var HP = 2000 line was in its own Script command. That would explain the error: script calls are sandboxed so a local variable in one cannot be seen in another.

[Edit: added missing { on the first line of my code. 😴]
I have several executing skills. This is my regular damage formula:

b.hpRate() < 0.3 ? 4.5 * (a.atk * 6.1 - b.def * 5) : 1.5 * (a.atk * 6.1 - b.def * 5) ;

the skill basically deals three times more damage, if the enemy has less than 30% hp.

Original thread: https://forums.rpgmakerweb.com/threads/kill-all-troops-with-hp-less-than-x.152323/