JAVASCREEPS are melting my brain.

Hello, I am working on a small formula to provide one random character in the party a chance to assist the attack with whoever started the assault and should only work on a basic attack. It appears working sorta but everyone in the party is getting a roll where I need it to stop with the first character that clears the successRate.
Ideally it should..

Pick a random member that's not the initial attacker.
Run them vs the success chance.
If clears move to the next phase and perform X action.
Clean up and don't check any more characters.
If doesn't clear move to check another character until success or out of characters.

Also, is there a guide that has all the terms to talk to MV?


So far...

if (this.isAttack()) {
var successRate = 0.50;
var whoAttacks = Math.randInt (1, $gameParty.members().length - 1);
if (Math.random() < successRate) {
$gameParty.members()[whoAttacks].forceAction(51, -1);
BattleManager.forceAction($gameParty.members()[whoAttacks]);
}
}

This is a roadblock thats had me stuck for the last 4 days.
Any thoughts on this madness? I know I am missing things but what are they. ><
I don't know Javascript sorry.

Edit: I found these plugins from Victor Engine that might help. Please take a look.
The way you're trying to approach it could work, but I think there's a simpler strategy. Assuming each ally should have an equal chance of being the one to assist, the user can't assist themselves, and dead allies can't help anyone, you could do something like this:

JavaScript:
if (this.isAttack()) {
  var assistRate = 0.50; // the total chance of any assist happening
  if ($gameParty.aliveMembers().length > 1 && Math.random() < assistRate) { // at least one other living ally, and you pass the random check
    var whoAttacksId = Math.randInt (1, $gameParty.aliveMembers().length - 1); // use aliveMembers() so dead allies don't try to assist
    if (whoAttacksId <= $gameParty.aliveMembers().indexOf(user)) { // see explanation below*
      whoAttacksId -= 1;
    }
    var whoAttacks = $gameParty.aliveMembers()[whoAttacksId]; // easier to read this way
    whoAttacks.forceAction(51, -1);
    BattleManager.forceAction(whoAttacks);
  }
}

Spoiler: *Explanation
Let's say we have 3 living party members. Their indices in the aliveMembers array would be 0, 1, and 2. Math.randInt(1, array length - 1) will give you either "1" or "2", which is fine if index 0 is the character who attacked.

But what if index 1 attacked? Index 0 wouldn't be able to assist, and there's a chance index 1 would try to assist their own attack, which is weird. So, we say that if the random number is the same as the user's ID, or lower, we subtract one from it. A quick illustration of how that ends up working:
Index 0 attacks: 1 and 2 are valid, nothing changes. Result can be 1 or 2.

Index 1 attacks: 1 will change to 0, 2 remains the same. Result can be 0 or 2.

Index 2 attacks: 1 changes to 0, 2 changes to 1. Result can be 0 or 1.

While you can devise an approach that iterates over the party in a random order, I think it's more complicated and processor-intensive than you actually need.

Original thread: https://forums.rpgmakerweb.com/threads/javascreeps-are-melting-my-brain.126311/