MZ A state lasting until all actors have had X actions

I need a state which will last the equivalent of 2 turns but because I am using the VS CTB system, all 'turns' are converted into 'actions'.

There is one state I was planning to use which is utterly dependent on turns. It has been suggested to me that what might be a way round my problem is to program a state to stay until each different actor has taken X actions.

This is completely beyond my competence, so I was wondering if it would be possible for someone to tell me what the coding is.

I need the state to last until all actors have had 2 actions.
When this state is first available, the party has 3 members which later goes up to 5, so the coding would need to take that into account.

If you could help I would be very grateful.
Thank you for taking the time to read this.
Okay, so you're going to set aside one of your game variables for this. I'll refer to its ID as varId.

You'll also need two states. One is the actual state you want to last 2 turns and it does something (I'll call it state1, and its ID state1Id). The other is going to go on all the party members, and it doesn't need an icon or name the player will see, it's just a counter (I'll call it state2, and its ID state2Id).

I'm using notetags from VisuStella Skills and States Core, and the Battle Core.

In state1's notetags, put:
Code:
<JS On Add State>
$gameVariables._data[varId]=[0, 0, 0, 0, 0];

$gameParty.aliveMembers().forEach(member => member.addState(state2Id));
</JS On Add State>

Then, in state2's notetags, put:
Code:
<JS Post-End Action>
var index=$gameParty.members().indexOf(user);

$gameVariables._data[index]=Math.min(2, $gameVariables._data[index]+1);
if ($gameVariables._data.every(turn => turn==2)
{
    $gameParty.aliveMembers.forEach(member => member.removeState(state1Id);
    $gameParty.aliveMembers.forEach(member => member.removeState(state2Id);
}
</JS Post-End Action>

That should make the states get stripped when all 5 party members have taken 2 actions.

Potential concerns:
- Death. Getting KOed strips all states, so you might need to make any resurrection items or skills check for the user to have state2, and if so also apply state2 to the target. I think this would be easier than converting them to passive states just for this one skill.

- In whatever method you get the extra two party members, you'll also need to apply state2 to them. If there are circumstances where you could get those 2 actors but this skill/state is not in play, then you'll need to do like above and give it to them only if the other party members already have it.

I/people can help with those two if you're not sure how to go about it, but test this first and see if it does what it's supposed to.
@ATT_Turan Thank you for this.
I copy/pasted the code, but as soon as either the test battle in the editor starts, or as soon as the game loads for an on-map test, I get the error message
1656005200621.png


The console shows this:
1656005259459.png
I missed a close parentheses in
Code:
if ($gameVariables._data.every(turn => turn==2))
@ATT_Turan Having put in that correction, I then got an error message saying that ) was missing after argument list.
I identified 2 instances, put them in and I can now say, with a light heart, that everything works exactly as it should. I tested it out on battles lasting 1, 2 and 3 turns and in each case the correct exp came up.

Words cannot express how grateful I am to you for this. This state was a critical element for an aspect of the game and I am so relieved that it can now be incorporated.

Thank you very much indeed.
You're welcome, sorry for the typos of distraction.

Original thread: https://forums.rpgmakerweb.com/threads/a-state-lasting-until-all-actors-have-had-x-actions.148794/