MV How to give an actor a chance to attack in another ally's turn randomly?

Hey 😍

I'm creating a rogue-like class, and I'd like to give it the ability to randomly, based on it's luck, perform an attack action during or right after another ally's turn. I have all of Yanfly's plugins. I googled but didn't find anything that seemed even close to what I want to do. Is that even possible? I was thinking maybe something with passive states, but I don't really know where to start.
Which YEP battle system are you using? ATB? CTB? DTB?
I imagine you could set some (if not all) the attacks in your game to randomly add on extra damage/effects giving the illusion of an ally helping them attack. But I'm sure that process would be rather tedious compared to a plugin that does it automatically.
Moved to: Plugin Support
Which YEP battle system are you using? ATB? CTB? DTB?
Oh sorry, forgot to mention. I'm using ATB


I imagine you could set some (if not all) the attacks in your game to randomly add on extra damage/effects giving the illusion of an ally helping them attack. But I'm sure that process would be rather tedious compared to a plugin that does it automatically.
Yes, this was the only solution I could think of. Of course, I wanted something more automatic, but if no soluion comes up, I guess that's what I'll have to do 😐
Here's how I did it in MZ using the VisuStella plugins: you should be able to get the same effect by changing JS Post-End Action to the YEP equivalent. This notetag should go on a global actor passive state.

JavaScript:
<JS Post-End Action>
  if (this.isForOpponent()) {
    const rogues = user.friendsUnit().aliveMembers().filter(member => member !== user && member._classId === 5);
    rogues.forEach(rogue => {
      const bonusChance = rogue.luk / 100;
      const random = Math.random();
      if (random < bonusChance) {
        rogue.forceAction(12, -2);
        BattleManager.forceAction(rogue);
      }
    });
  }
</JS Post-End Action>

(very quick-and-dirty implementation that causes a character with class ID 5 to have a luk / 100 chance of performing Double Attack after a friendly actor takes action against an enemy)
Here's how I did it in MZ using the VisuStella plugins: you should be able to get the same effect by changing JS Post-End Action to the YEP equivalent. This notetag should go on a global actor passive state.

JavaScript:
<JS Post-End Action>
  if (this.isForOpponent()) {
    const rogues = user.friendsUnit().aliveMembers().filter(member => member !== user && member._classId === 5);
    rogues.forEach(rogue => {
      const bonusChance = rogue.luk / 100;
      const random = Math.random();
      if (random < bonusChance) {
        rogue.forceAction(12, -2);
        BattleManager.forceAction(rogue);
      }
    });
  }
</JS Post-End Action>

(very quick-and-dirty implementation that causes a character with class ID 5 to have a luk / 100 chance of performing Double Attack after a friendly actor takes action against an enemy)

It worked perfectly!! Thank you very much!!!

edit: Actually, I just realized that my rogue attacks now even when dead/paralyzed/stunned etc. Would you know if there's any way to check if rogue is restricted by any "cannot move" states? Or would I have to check for every state that has this restriction?
It worked perfectly!! Thank you very much!!!

edit: Actually, I just realized that my rogue attacks now even when dead/paralyzed/stunned etc. Would you know if there's any way to check if rogue is restricted by any "cannot move" states? Or would I have to check for every state that has this restriction?
JavaScript:
<JS Post-End Action>
  if (this.isForOpponent()) {
    const rogues = user.friendsUnit().aliveMembers().filter(member => member !== user && member._classId === 5);
    rogues.forEach(rogue => {
      if (rogue.canMove()) {
        const bonusChance = rogue.luk / 100;
        const random = Math.random();
        if (random < bonusChance) {
          rogue.forceAction(12, -2);
          BattleManager.forceAction(rogue);
        }
      }
    });
  }
</JS Post-End Action>
JavaScript:
<JS Post-End Action>
  if (this.isForOpponent()) {
    const rogues = user.friendsUnit().aliveMembers().filter(member => member !== user && member._classId === 5);
    rogues.forEach(rogue => {
      if (rogue.canMove()) {
        const bonusChance = rogue.luk / 100;
        const random = Math.random();
        if (random < bonusChance) {
          rogue.forceAction(12, -2);
          BattleManager.forceAction(rogue);
        }
      }
    });
  }
</JS Post-End Action>
Okay, now I believe it's REALLY working perfectly! Thank you soooooo much!!!

Original thread: https://forums.rpgmakerweb.com/threads/how-to-give-an-actor-a-chance-to-attack-in-another-allys-turn-randomly.137242/