Alive Troop Members and Conditional Branches

I am trying to make a skill that inflicts a random status ailment on every enemy. I tried using doing so using the damage formula and succeeded, but, for some unexplained reason, it also stopped all the enemies from taking any damage at all afterwards.

To fix this, I decided to create a common event that uses a randomized variable to inflict a different state on enemies 1-8. While this did not have the immortal enemies problem, it inflicted multiple states on the same enemy if there fewer than eight enemies left in the troop. this makes the skill ridiculously overpowered when used on smaller troops and bosses.

Does anyone know how to make a conditional branch that only runs if there are a more than a certain number of enemies left in a troop? To my mind, I imagine it being something along the lines of:


If: Script: $gameTroop.aliveMembers() >== n
Instead of checking there are more than a certain number, just loop through the ones that there are:

JavaScript:
for (const member of $gameTroop.aliveMembers()) {
    const randomState = $dataStates[Math.randomInt($dataStates.length)];
    member.addState(randomState);
}
but, for some unexplained reason, it also stopped all the enemies from taking any damage at all afterwards.
the damage is always the last number processed in the damage formula.
that is why the order of the code inside is important.
if the last code has no number, the damage will be zero

it inflicted multiple states on the same enemy if there fewer than eight enemies left in the troop.
that basically means you have a mistake in your logic - if you show us a screenshot of that event we might be able to help you repair it
Instead of checking there are more than a certain number, just loop through the ones that there are:

JavaScript:
for (const member of $gameTroop.aliveMembers()) {
    const randomState = $dataStates[Math.randomInt($dataStates.length)];
    member.addState(randomState);
}
Unfortunately, there are some states that I don't want the enemies to have, as a lot of them are buffs or were made for very specific circumstances.
Unfortunately, there are some states that I don't want the enemies to have, as a lot of them are buffs or were made for very specific circumstances.
That's fine, the random state wasn't the important part.
the damage is always the last number processed in the damage formula.
that is why the order of the code inside is important.
if the last code has no number, the damage will be zero


that basically means you have a mistake in your logic - if you show us a screenshot of that event we might be able to help you repair it
This is what I originally put in the damage formula:

x = Math.floor(Math.randomInt(14) + 1); if (x === 1) {b.addState(4);} if (x === 2) {b.addState(5);} if (x === 3) {b.addState(6);} if (x === 4) {b.addState(12);} if (x === 5) {b.addState(13);} if (x === 6) {b.addState(17);} if (x === 7) {b.addState(22);} if (x === 8) {b.addState(24);} if (x === 9) {b.addState(8);} if (x === 10) {b.addState(9);} if (x === 11) {b.addState(20);} if (x === 12) {b.addState(47);} if (x === 13) {b.addState(53);} if (x === 14) {b.addState(54);}

Does this mean that I should add "; 0" to the end so that the final damage calculation is 0?

The screenshots are down below. The rest of the event is just the same code only for Enemies #2-#8.
This is what I originally put in the damage formula:

x = Math.floor(Math.randomInt(14) + 1); if (x === 1) {b.addState(4);} if (x === 2) {b.addState(5);} if (x === 3) {b.addState(6);} if (x === 4) {b.addState(12);} if (x === 5) {b.addState(13);} if (x === 6) {b.addState(17);} if (x === 7) {b.addState(22);} if (x === 8) {b.addState(24);} if (x === 9) {b.addState(8);} if (x === 10) {b.addState(9);} if (x === 11) {b.addState(20);} if (x === 12) {b.addState(47);} if (x === 13) {b.addState(53);} if (x === 14) {b.addState(54);}

Does this mean that I should add "; 0" to the end so that the final damage calculation is 0?

The screenshots are down below. The rest of the event is just the same code only for Enemies #2-#8.
Do you have Buffs & States Core?
Do you have Buffs & States Core?
Yep.
Don't bother with the damage formula, just set the damage type to none, and put this in the notebox (you'll need Skill Core for this, not Buffs & States Core, sorry):

JavaScript:
<Custom Execution>
  const possibleStates = [4, 5, 6, 8, 9, 12, 13, 17, 20, 22, 24, 47, 53, 54];
  for (const member of $gameTroop.members()) {
    const randomState = possibleStates[Math.randomInt(possibleStates.length)];
    member.addState(randomState);
  }
</Custom Execution>
as for the event - I would reorganize that for better readability.
with different values of the random number there is no need for else-branches at all if done correctly.
you would have to reorganise the logic, but I would make all conditional branches checking for equal and having no else branch or indent at all.
you would get the same result, but without that large structure of indents.

then for each of those much smaller random states per enemy, you nest them once inside a conditional branch that checks if that specific enemy is there and alive.

basically
if enemy #1 there
>>random conditional list #1
if enemy #2 there
>>random conditional list #2


And you can check that either with conditional branch enemy #n appeared
or using control variable : enemy #? HP (it's in the game data section) and then conditional branch variable >0
Don't bother with the damage formula, just set the damage type to none, and put this in the notebox (you'll need Skill Core for this, not Buffs & States Core, sorry):

JavaScript:
<Custom Execution>
  const possibleStates = [4, 5, 6, 8, 9, 12, 13, 17, 20, 22, 24, 47, 53, 54];
  for (const member of $gameTroop.members()) {
    const randomState = possibleStates[Math.randomInt(possibleStates.length)];
    member.addState(randomState);
  }
</Custom Execution>
That did the trick. Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/alive-troop-members-and-conditional-branches.145803/