MZ Splash damage if targeted enemy is defeated

Hello guys, thanks for the usual help.
So, i'm using visustella battle core to apply splash damage after an enemy is hit and is still alive with this code provided by @ATT_Turan in another thread:

<JS Post-Damage> for (let i=0; i<target.friendsUnit().aliveMembers().length; i++) { if (target.friendsUnit().aliveMembers()[i]!=target) { target.friendsUnit().aliveMembers()[i].gainHp(0-Math.round(value/2)); target.friendsUnit().aliveMembers()[i].startDamagePopup(); } } </JS Post-Damage>

It works perfectly if the target is still alive, but the problem is: if the targeted enemy dies, the splash damage doesn't happen and the battle is over (victory) even with other enemies alive! lol
I wanted to fix this but have been struggling a lot.

Appreciate the help, guys.
the problem is: if the targeted enemy dies, the splash damage doesn't happen and the battle is over (victory) even with other enemies alive! lol
are you sure the other enemies are actually alive? my guess would that the splash damage is going through and is killing the other enemies as well, but because theres no call to make the other enemies collapse if they died that way, they may be visually lingering. there might also be some shenanigans happening for iterating through aliveMembers(), then calling aliveMembers() again while also dealing damage that may have killed the current iteration's battler

try this?
Code:
target.friendsUnit().aliveMembers().forEach(enemy => {
    if (enemy!=target){
        enemy.gainHp(0-Math.round(value/2));
        enemy.startDamagePopup();
        if (enemy.hp === 0) enemy.performCollapse();
    }
})
are you sure the other enemies are actually alive? my guess would that the splash damage is going through and is killing the other enemies as well, but because theres no call to make the other enemies collapse if they died that way, they may be visually lingering. there might also be some shenanigans happening for iterating through aliveMembers(), then calling aliveMembers() again while also dealing damage that may have killed the current iteration's battler

try this?
Code:
target.friendsUnit().aliveMembers().forEach(enemy => {
    if (enemy!=target){
        enemy.gainHp(0-Math.round(value/2));
        enemy.startDamagePopup();
        if (enemy.hp === 0) enemy.performCollapse();
    }
})

You're absolutely right, the enemies were indeed being killed, but the collapse wasn't happening, thank you!

I don't know if i need to open another thread, but i also wanted a skill that does splash damage ONLY if the targeted enemy dies. Is it possible
if you dont use resist death on your enemies, you can change
Code:
if (enemy!=target){
to
Code:
if (enemy!=target && target.hp===0){
and it should only do the splash damage if the target's hp was dropped to 0 by the end of the skill.
otherwise you might have to do something like flag whether or not the enemy had more than 0 hp before the skill started and check if they ended at 0 afterwards
if you dont use resist death on your enemies, you can change
Code:
if (enemy!=target){
to
Code:
if (enemy!=target && target.hp===0){
and it should only do the splash damage if the target's hp was dropped to 0 by the end of the skill.
otherwise you might have to do something like flag whether or not the enemy had more than 0 hp before the skill started and check if they ended at 0 afterwards
It worked like a charm.
Thank you so much @Robro33 , you're awesome!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/splash-damage-if-targeted-enemy-is-defeated.166036/