First, we'll get a custom battle effect that records the state ID of every state the actor already has when entering a battle:
JavaScript:
<Custom Battle Effect>
user.pastStates = [];
for(i = 0; i < user.states().length; i++) {
user.pastStates.push(user.states[i].id);
}
</Custom Battle Effect>
What we're going to do to make Synchronize work is that we'll record the states the wearer already has, and see in the wearer's current states which ones they didn't have before.
JavaScript:
<Custom React Effect>
newStates = [];
for(i = 0; i < user.states().length; i++) {
newStates.push(user.states[i].id);
}
sync = [];
for(i = 0; i < newStates.length, i++) {
if(!target.pastStates.includes(newStates[i])) {
sync.push(target.newStates[i]);
}
}
</Custom React Effect>
The
sync variable contains every state ID of the states that weren't in the wearer's
pastStates variable but were in
newStates, which means they weren't there before the action that was just received.
Next, we'll throw these states at random opponents.
JavaScript:
if(target.isActor()) {
opponents = $gameTroop;
} else {
opponents = $gameParty;
}
for(i = 0; i < sync.length; i++) {
syncTarget = opponents.randomTarget();
syncTarget.addState(sync[i]);
}
Finally, we replace the past states array by the current one.
JavaScript:
user.pastStates= newStates;
Now all together:
JavaScript:
<Custom Battle Effect>
user.pastStates = [];
for(i = 0; i < user.states().length; i++) {
user.pastStates.push(user.states[i].id);
}
</Custom Battle Effect>
<Custom React Effect>
newStates = [];
for(i = 0; i < user.states().length; i++) {
newStates.push(user.states[i].id);
}
sync = [];
for(i = 0; i < newStates.length, i++) {
if(!target.pastStates.includes(newStates[i])) {
sync.push(target.newStates[i]);
}
}
if(target.isActor()) {
opponents = $gameTroop;
} else {
opponents = $gameParty;
}
for(i = 0; i < sync.length; i++) {
syncTarget = opponents.randomTarget();
syncTarget.addState(sync[i]);
}
user.pastStates = newStates;
</Custom React Effect>