MZ Skill that copies states and spreads among the party

Hi,

I need some help creating a skill that copies specific states, and adds these states to the the rest of the troop.

I was able to create a skill that copies all states and spreads it to the user by using the following code:

JavaScript:
target._states.forEach(state => $gameTroop.members().forEach(member => member.addState(state)));

When using this attack, it collects al the states on the target, and spreads them among the enemy troop.

What I'm having trouble doing is getting only specific states to transfer. I figure I would have to put specific states in an array, and then have them transferred, but not sure how to approach.

Anyone have an tips? or done anything similar?
Yeah.
I think adding an array would probably do the trick

I didn't test it, but how about:
JavaScript:
const checkStates = [a, b, c...];
checkStates.forEach(check => if (target._states.contains(check)) $gameTroop.members().forEach(member => member.addState(check)));

Where a, b, c... are the state IDs you want to have added.
Yeah.
I think adding an array would probably do the trick

I didn't test it, but how about:
JavaScript:
const checkStates = [a, b, c...];
checkStates.forEach(check => if (target._states.contains(check)) $gameTroop.members().forEach(member => member.addState(check)));

Where a, b, c... are the state IDs you want to have added.

I get this error regarding "if"

1713375640457.png


I also should have mentioned, I'm running the Visusetlla core.
Sorry

Try this:
JavaScript:
const checkStates = [a, b, c...];
checkStates.forEach(check => {if(target._states.contains(check)) $gameTroop.members().forEach(member => member.addState(check))});

Again with a,b c being the IDs of your states.
Sorry

Try this:
JavaScript:
const checkStates = [a, b, c...];
checkStates.forEach(check => {if(target._states.contains(check)) $gameTroop.members().forEach(member => member.addState(check))});

Again with a,b c being the IDs of your states.
works like a charm.

Thank you.
This thread is being closed due to being reported as solved. If you need it reopened, let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-copies-states-and-spreads-among-the-party.167828/