Lunatic Mode Help: Repeat skill if target dies

Hello everyone, i need help to make a skill that will repeat itself to another target if the current target dies.

For example, i use the skill to kill enemy A, if the enemy A dies, i will perform the skill again to random alive enemies.

I came up with the following code:

<Post-Damage Eval>

if(target.hp <= 0){

target._immortalState = false;

target.performCollapse();

BattleManager.queueForceAction(user, 32,

$gameTroop.aliveMembers()[Math.randomInt($gameTroop.aliveMembers().length)]);

}

</Post-Damage Eval>

But the problem is, while the skill succeed to repeat itself, the dead enemy battler wont dissappear/collapse.
I tried to change target.hp <= 0 with target.isDead(), the dead enemy dissappear but the skill wont repeat.
I cant think of another way to achieve this lol, perhaps someone who is more familiar with MV can help me.

Thank you for reading.
Hello! I ran a few tests with this code and it seems to do as you required:
Code:
<Post-Damage Eval>
   if (target.hp <= 0 && $gameTroop.aliveMembers().length - 1 > 0) {
     target._immortalState = false;
     target.performCollapse();
     target.refresh()
     user.forceAction(X, -1)
     BattleManager.forceAction(user);
   }
</Post-Damage Eval>
*X is to be replaced by the repeated skill Id.

I suggest you test it thoroughly to see if it does behave as you want, though...
Good luck! 😉
Been testing it, and wow it works flawlessly so far! Thank you soooooo much! @TSR :hhappy:

I have a quick question if you dont mind, do i need to put target.refresh() after i change immortalState and do target.performCollapse()?
Hello again!
I think it's better to put the refresh() so that the Battler sprite update before proceeding to the next step. When I tested it without refreshing it, the first enemy only collapse after the repeated skill was done on second enemy (looks less cool...).

Original thread: https://forums.rpgmakerweb.com/threads/lunatic-mode-help-repeat-skill-if-target-dies.118508/