MV "Synchronize" Ability

Hi everyone,
I was trying to make a passive ability, also using Yanfly's Plugins, that would work like "Synchronize" in pokemon: whenever the user has a negative status, they transmit it to their enemies; in my case, I want them to transfer it to a random target.
However I don't really understand how it works, since I think a coding knowledge is required for this.
Thanks in advance for helping 🙂
Do you have the Buffs & States Core and Auto Passive States plugins?
Moved to: Plugin Support
Do you have the Buffs & States Core and Auto Passive States plugins?
Yes, I have those plugins
Okay, give me a bit and I'll come up with a notetag that'll do this.
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>
The only trick with that is that it isn't limited solely to negative statuses, it will also distribute any buffs that the user gets during the battle.

The easiest way around that is probably to utilize a notetag: on every state that you want to be considered "negative" by this skill, give it the notetag <negative>

Then, modify the code by @CHKNRAVE to the following:

Code:
if(!target.pastStates.includes(newStates[i]) && $dataStates[newStates[i].id].meta.negative) {

I believe that should do what you want.
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>
Thank you for your help, but it doesn't seem to work because the enemy is not affected by the new states; Also, the animation of the state doesn't play on the actor who is affected by that state.
Okay, give me a bit and I'll come up with a notetag that'll do this.
Hi there! Sorry to bother you, but I wanted to ask you if you had come up with the notetag yet. Thanks in advance!

Original thread: https://forums.rpgmakerweb.com/threads/synchronize-ability.134792/