MZ VisuStella Battle Core Plugin Command Random Targetting

Hi, I'm in the middle of making a skill that triggers a common event where I've created a sequence of plugin commands from VisuStella Battle Core, it's meant to be a multi hit skill (1 hit to all enemies, then 7 consecutive hits to random targets, then 1 final hit to all enemies again).

The problem I'm running into is that if an enemy dies before or during the 7 hits, the targeting can change to an enemy that's already dead instead of only random alive enemies.

1775774186348.png

This is the looping event sequence for the 7 hits, hopefully it's just something I'm missing in the sequence, thank you!
You can roll your own random chance from alive members with something like:

const aliveTroop = $gameTroop.aliveMembers();
const index = aliveTroop[Math.randomInt(aliveTroop.length)].index();
$gameVariables.setValue(10, index);

Then get a plugin extension that lets you use variable id:

Hi, thanks for getting back to me! I'm a little confused on some details.

const aliveTroop = $gameTroop.aliveMembers();
const index = aliveTroop[Math.randomInt(aliveTroop.length)].index();
$gameVariables.setValue(10, index);
Am I pasting this in as a script function at the end of each single target skill loop? I'm still quite new to using action sequences, would it be okay if you gave an example event sequence please?
Yeah use the script event command. And replace what variable you want to use in the last line (currently 10).

Then that plugin extension lets you write enemy index var 10 in the action sequence targets (I assume it works also with emulate too, but haven't tested, anyway you can write conditional branches too).

You can make a loop that runs that stuff 7 times, at the end add +1 to some variable, then if that variables is 7, set it to 0 and break the loop.

LOOP
->script stuff
->motion
->animation
->action effect
->variable +1
IF variable >= 7
->variable = 0
->break loop

EDIT: Oh yeah, might wanna add a conditional check that alive members are still available there.
Perfect, that's worked great! Thank you so much! I've looped it in a primitive way by just copy and pasting the loop with a small wait delay between them but it's still worked haha
Cool.

But like I said, you should put a conditional there or else it can crash if there are no alive battlers.
Like put the stuff under a conditional branch before the hits:
$gameTroop.aliveMembers().length > 0
That's odd, I don't get a crash after testing it with a single enemy that dies during the skill. All that happens after it dies is that the skill continues with the single target looping skill showing but not resulting in a damage pop up, and then the last aoe hit doesn't show but the audio still plays.

I'll include what you've mentioned anyways just for safety anyways!

Original thread: https://forums.rpgmakerweb.com/threads/visustella-battle-core-plugin-command-random-targetting.183194/