Making an enemy immortal whenever another enemy is alive, how?

I want to make a battle that whenever there's an enemy other than the boss alive the boss will reciece 0 damage from every single attack. The battle consists of 3 phases, the first enemy group appears at 75% HP, the second at 50% and the final at 25%.

Currently it only works for the first group but because it removes the immortal state when any of the enemies are dead it keeps getting removed the turn after the second group appears, how can I change it so that it won't be removed when one of the enemies that appear is defeated but only when there are 0 other enemies alive?

I use MV btw.
it depends a lot on how you handled both the appearing and the immortality.
Usually I would use a single turn 0 troop event to give the immortal state, and then one troop event for each enemy to handle what should happen when that enemy dies, checking which states to remove and which enemies to appear.

if you work differently, we need a screenshot of your events
it depends a lot on how you handled both the appearing and the immortality.
Usually I would use a single turn 0 troop event to give the immortal state, and then one troop event for each enemy to handle what should happen when that enemy dies, checking which states to remove and which enemies to appear.

if you work differently, we need a screenshot of your events

That helped a lot, it works now. Thank you.
That helped a lot, it works now. Thank you.

It doesn't, Now the immortal state keeps disappearing after one turn because I thought if I made it 1 turn and that it always gets reapplied whenever the enemies are alive but it either disappears after one turn or after one of the two enemies dies.
My current layout of events is:

Page 1: The battle intro (Doesn't have anything to do with the rest, it's just an intro)
Page 2: When the boss is at 75% HP or lower the first two enemies appear and the immortal state gets applied.
Page 3 and 4: Same as 2 but at 50% and 25%
Page 5-10 Turn ends, conditional branch: If enemy is alive apply immortal state.
your "layout" is useless because it misses too many details on what you have done.
If you want help we need screenshots of every troop event and the immortal state to see what you have done.

Original thread: https://forums.rpgmakerweb.com/threads/making-an-enemy-immortal-whenever-another-enemy-is-alive-how.125078/