MV [YEP Buff & States Core] Passive state that adds state to ally with highest parameter

Hello everyone, I have a passive state that's supposed to check the battle party's ATK when the condition is fulfilled, then automatically apply to the battle ally with the highest ATK.
I see there's the whole 'i' loop stuff, but that's not really in my expertise - combined with getting the highest atk ally's id, etc.

The state in question does something akin to:
"When attacked, 20% chance to grant the ally with the highest ATK parameter Energized, increasing TP Regen+10% and ATK+10% for 3 turns."

So I'd imagine it'd be something like:
JavaScript:
<Custom React Effect>
if (Math.random() <= 0.2){
[thing to check current party's atk, then get id of ally with highest parameter]{
target.startAnimation(x); //show buff anim
target.addState(y); //add energized state
}
}
</Custom React Effect>

Bonus question, how can I check if anyone is inflicted with the state so the passive doesn't trigger again until it wears off?


Thank you ahead of time!
Hello everyone, I have a passive state that's supposed to check the battle party's ATK when the condition is fulfilled, then automatically apply to the battle ally with the highest ATK.
I see there's the whole 'i' loop stuff, but that's not really in my expertise - combined with getting the highest atk ally's id, etc.

The state in question does something akin to:
"When attacked, 20% chance to grant the ally with the highest ATK parameter Energized, increasing TP Regen+10% and ATK+10% for 3 turns."

So I'd imagine it'd be something like:
JavaScript:
<Custom React Effect>
if (Math.random() <= 0.2){
[thing to check current party's atk, then get id of ally with highest parameter]{
target.startAnimation(x); //show buff anim
target.addState(y); //add energized state
}
}
</Custom React Effect>

Bonus question, how can I check if anyone is inflicted with the state so the passive doesn't trigger again until it wears off?


Thank you ahead of time!
Math.random() returns a value from 0-0.9, so <= 0.2 is actually a 30% chance.

Code:
<Custom React Effect>
// 20% chance and no one in the party has state id X
if (Math.random()<0.2 && !$gameParty.aliveMembers().some(member => member.isStateAffected(X)))
{
    var memberOld=$gameParty.aliveMembers()[0];

   for (var i=0; i<$gameParty.aliveMembers().length; i++)
    {
        if ($gameParty.aliveMembers()[i].param(2)>memberOld.param(2))
            memberOld=$gameParty.aliveMembers()[i];
    }
    memberOld.startAnimation(Y);
    memberOld.addState(X);
}
</Custom React Effect>
Make sure to replace all instances of X and Y with the appropriate IDs.
Excellent, thank you very much!

Thread is solved.

Original thread: https://forums.rpgmakerweb.com/threads/yep-buff-states-core-passive-state-that-adds-state-to-ally-with-highest-parameter.140924/