MZ Changing the targets of a multi-hit attack when one of them dies?

For context, I just bought RPG Maker MZ a few days ago and I'm using VisuStella Core Engine and the Battle Core so I apologise if I'm asking something really obvious!!!

I'm trying to make a skill that hits enemies multiple times, damaging a random enemy each time
I've tried using the <Target: x Random Enemies> notetag and while it works there's just one problem: the attack will still target enemies that are already dead. Toggling the "Immortal: On" option doesn't fix the issue and the plugin's Random Target command seems to do nothing. Is there any way to change the target in the middle of the action so the skill only hits enemies it haven't killed yet? I've attached my attempts below if that's of any help
Your script call seems incorrect.
  1. Your newTarget variable ranges from 0 to the alive enemy count, because of the +1 in the previous line. So if there's 1 enemy alive, randomNum could be 0 or 1.

  2. You get the target's index based on aliveMembers, but then you set the target based on members.
Try this instead?
JavaScript:
const living = $gameTroop.aliveMembers();
$target = living[Math.randomInt(living.length)];
Your script call seems incorrect.
  1. Your newTarget variable ranges from 0 to the alive enemy count, because of the +1 in the previous line. So if there's 1 enemy alive, randomNum could be 0 or 1.

  2. You get the target's index based on aliveMembers, but then you set the target based on members.
Try this instead?
JavaScript:
const living = $gameTroop.aliveMembers();
$target = living[Math.randomInt(living.length)];
Nope, that didn't do the trick, I have a feeling setting the $target variable might not actually be doing anything
The +1 is because JS's Math.random() is between 0 and the number you want so if you want to include 10 in your RNG for example you have to multiply it by 11, randomInt looks much more convenient so thank you for that though!
Nope, that didn't do the trick, I have a feeling setting the $target variable might not actually be doing anything
OK, I'm not really familiar with VisuStella's plugins so maybe someone else can offer advice there.

However...
The +1 is because JS's Math.random() is between 0 and the number you want so if you want to include 10 in your RNG for example you have to multiply it by 11
As an example: if an array has length 3 then its indices are 0, 1, 2. So Math.randomInt(3) gives the correct range: 0~2.
Bump
What does your corrected sequence look like?
What does your corrected sequence look like?
1711983324805.png

Right now it looks like this.
Ummmm, I don't think that's right-nyan?? 😅

You're saying if $gameTroop.aliveMembers().length == 0 choose a target...but that means when there are no alive members because you dun killed all the bad guys!

Maybe you meant to say != 0? Maybe you meant for the conditional to use AND so you're saying if I haven't done 10 hits and there are still living enemies! 😂
Code:
$gameVariables.value(3) < 10 && $gameTroop.aliveMembers().length > 0

Good luck-nyan!

Original thread: https://forums.rpgmakerweb.com/threads/changing-the-targets-of-a-multi-hit-attack-when-one-of-them-dies.167213/