MV lunatic mode selecting state affected enemies

i want to create a state that when the affected actor dies damages only enemies who are affected by a certain state.
i used this so far
Code:
if (target.hp <= 0) {

  var enemies = origin.opponentsUnit().aliveMembers();

  for (var i = 0; i < enemies.length; ++i) {

    var enemy = enemies[i];

    enemy.startAnimation(107);

  }

}
but it showes the animation on every enemy and i dont know how i can specify it to the certain state affected enemies.
you can use enemy.isStateAffected(ID) (ID being the state ID) as a condition inside the for loop. In it, put the animation command and any additional effect you need.
you can use enemy.isStateAffected(ID) (ID being the state ID) as a condition inside the for loop. In it, put the animation command and any additional effect you need.
so i have to do it like this?
Code:
<Custom Respond Effect>
if (target.hp <= 0) {
  var enemies = origin.opponentsUnit().aliveMembers();
  for (if (enemy.isStateAffected(25) { var i = 0; i < enemies.length; ++i } ) {
    var enemy = enemies[i];
    enemy.startAnimation(107);
  }
}
</Custom Respond Effect>
JavaScript:
if (target.hp <= 0) {
  var enemies = origin.opponentsUnit().aliveMembers();
  for (var i = 0; i < enemies.length; ++i) {
       var enemy = enemies[i];
       if (enemy.isStateAffected(StateID)) {
           // add DMG effect here..inside of " if (enemy.isStateAffected(StateID)) { "
           // Example: "enemy.gainHp(-100);"
           enemy.startAnimation(107);
       } // closes the " if (enemy.isStateAffected(StateID)) { "
  } // closes the " for (var i = 0; i < enemies.length; ++i) { "
};
its what CHKNRAVE mentioned and i added an Example that can be added to dmg the enemy with -100 HP...
JavaScript:
//to be added in the Example above if needed
enemy.gainHp(-100);
JavaScript:
if (target.hp <= 0) {
  var enemies = origin.opponentsUnit().aliveMembers();
  for (var i = 0; i < enemies.length; ++i) {
       var enemy = enemies[i];
       if (enemy.isStateAffected(StateID)) {
           // add DMG effect here..inside of " if (enemy.isStateAffected(StateID)) { "
           // Example: "enemy.gainHp(-100);"
           enemy.startAnimation(107);
       } // closes the " if (enemy.isStateAffected(StateID)) { "
  } // closes the " for (var i = 0; i < enemies.length; ++i) { "
};
its what CHKNRAVE mentioned and i added an Example that can be added to dmg the enemy with -100 HP...
JavaScript:
//to be added in the Example above if needed
enemy.gainHp(-100);
it is working ty!

Original thread: https://forums.rpgmakerweb.com/threads/lunatic-mode-selecting-state-affected-enemies.129318/