All targets affected by a state applied to one (Shouldn't be)

I've got a skil that uses YEP_BuffsStatesCore plugin to move the target when a state is applied. However, it's moving the whole troop instead.

In this example the player is meant to knock just the one enemy up in the air for the rest of the turn. It applies the state to the one, but they rest of the troop are lifted as well.

https://gyazo.com/48ccea34d458eb3d994ba0f4ea173120


Code:
<State animation: 200>
<Custom Apply Effect>
SceneManager._scene._spriteset._enemySprites.forEach((sprite) =>
{
  if(!sprite.isAlreadyFloating) {
  sprite.isAlreadyFloating = true;
  sprite._homeY -= 200;
}
});

</Custom Apply Effect>

<Custom Remove Effect>
SceneManager._scene._spriteset._enemySprites.forEach((sprite) =>
{
      sprite._homeY += 200;
      sprite.isAlreadyFloating = false;
      
});
</Custom Remove Effect>
Try:
JavaScript:
<Custom Apply Effect>
const s = SceneManager._scene._spriteset._enemySprites.find(x=>x._battler._states.includes(4));
if (!s.isAlreadyFloating) {
    s.isAlreadyFloating = true;
    s._homeY -= 200;
}
</Custom Apply Effect>
Replace the number 4 with the state ID that you put on the enemy and it will find it.
Using .forEach() means it will do it for every enemy so use .find() instead. Do the same for the remove effect or as needed.

Edit: you might want to try removing the .isAlreadyFloating condition too since you also have a custom remove effect to take care of the possibility.

I am not sure since I don't know what else you are using for your project so you'll have to make changes as needed. Maybe for the Custom remove effect, use the .isAlreadyFloating to bring them back down.
It seems to work perfectly, thank you.

As for the .isAlreadyFloating was added because you can potentially use the skill multiple times, and that was sending them higher and higher and higher...
Try:
JavaScript:
<Custom Apply Effect>
const s = SceneManager._scene._spriteset._enemySprites.find(x=>x._battler._states.includes(4));
if (!s.isAlreadyFloating) {
    s.isAlreadyFloating = true;
    s._homeY -= 200;
}
</Custom Apply Effect>
Replace the number 4 with the state ID that you put on the enemy and it will find it.
Using .forEach() means it will do it for every enemy so use .find() instead. Do the same for the remove effect or as needed.

Edit: you might want to try removing the .isAlreadyFloating condition too since you also have a custom remove effect to take care of the possibility.

I am not sure since I don't know what else you are using for your project so you'll have to make changes as needed. Maybe for the Custom remove effect, use the .isAlreadyFloating to bring them back down.
As bass2yang mentioned, that's what forEach() does - it executes the code for each element of the array you're referencing.

Not knowing the context of how you apply this state, you might consider moving this into an action sequence for the skill, instead. That provides more user-friendly, non-coding commands to simply do things like move and lift specific battlers (you wouldn't have to access the sprite, you just say the target of the attack).
Try:
JavaScript:
<Custom Apply Effect>
const s = SceneManager._scene._spriteset._enemySprites.find(x=>x._battler._states.includes(4));
if (!s.isAlreadyFloating) {
    s.isAlreadyFloating = true;
    s._homeY -= 200;
}
</Custom Apply Effect>
Replace the number 4 with the state ID that you put on the enemy and it will find it.
Using .forEach() means it will do it for every enemy so use .find() instead. Do the same for the remove effect or as needed.

Edit: you might want to try removing the .isAlreadyFloating condition too since you also have a custom remove effect to take care of the possibility.

I am not sure since I don't know what else you are using for your project so you'll have to make changes as needed. Maybe for the Custom remove effect, use the .isAlreadyFloating to bring them back down.
So I rushed onto my next step without testing everything... Now, when the state is removed, All of the enemy go down even those that didn't go up... I tried just replacing the for each Sprite again.... and that didn't work. :/
Edited: I got it, I just used an if statement to check if they were floating

Original thread: https://forums.rpgmakerweb.com/threads/all-targets-affected-by-a-state-applied-to-one-shouldnt-be.174094/