Is there code to remove a state from everyone in a battle?

I'm making a Witch class with Hexes. She's supposed to only be able to use one Hex at a time. If she changes the Hex all effects of the previous Hex goes away and the new one starts. I've made each Hex apply States so I could easily remove them. However, the problem I'm coming across is I know how to remove them from the target but not from everyone because one hex may apply to enemies while a different one is buffing a hero.

I know this will be done in scripting but not sure how to target everyone in the battle. I know I'd have to repeat for every Hex except the one being used.

Any ideas? Not sure if anyone has done this I didn't see anything in the forums for it.
depending on how your setup goes, there are different ways - I could even think of one that is complete eventing with common events attached to the skills, although that is a tedious one.

so can you give screenshots of your skills and states, at least examples to see what you stil have?
the eventing way would be to attach a different common event to each skill so that it removes everything not fitting when that skill is used.
If you're using VisuStella's Skills and States Core, put the following notetag in each hex state:

JavaScript:
<JS On Add State>
    const hexes = [id1, id2, id3 etc.]
    target.friendsUnit().forEach(member => {
        hexes.forEach(hex => {
            if (hex !== state.id) member.removeState(hex);
        }) 
      })
</JS On Add State>
Trihan I tried your code it isn't working right.
Code:
<JS On Add State>
    const hexes = [171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183]
    target.friendsUnit().forEach(member => {
        hexes.forEach(hex => {
            if (hex !== state.id) member.removeState(hex);
        }) 
      })
</JS On Add State>

It wasn't doing anything so I also tried this below. Removing the if the state = the id and still it isn't removing the states. I have other state code working and did check I have VisuStella's Skills and States Core on.

Code:
<JS On Add State>
    const hexes = [171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183]
    target.friendsUnit().forEach(member => {
        hexes.forEach(hex => {
            member.removeState(hex);
        })
      })
</JS On Add State>

I also tried this below for heroes or monsters since it needs to work on both. The removeState is never triggering. even on the enemies.

Code:
<JS On Add State>
    const hexes = [171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183]
    target.friendsUnit().forEach(member => {
        hexes.forEach(hex => {
            if (hex !== state.id) member.removeState(hex);
        })
      })
      $gameTroop.members().forEach(member => {
        hexes.forEach(hex => {
            if (hex !== state.id) member.removeState(hex);
        })
      })
</JS On Add State>

Screenshots are attached if you think that could help
1626022260287.png
1626022355050.png
I also tried this below for heroes or monsters since it needs to work on both.
That's the point of using friendsUnit, it will return whatever group the target is a part of, the party or the troop.

And you're sure you're testing it with one of those states being inflicted, then you cast a second one and it doesn't wipe the first one?

And you've saved your game and started a new one since adding the notetag code?
I second ATT_Turan's questions, as I can't see anything in the code I gave you that shouldn't work as written.

Basically it loops through the entire unit the target belongs to (as said above) and then removes each hex from the battler as long as the hex being removed isn't the one currently being added.
Here is a video showing what I've done. I believe they are all right.

Notice the status effects remain on targets after casting a new hex or even the same hex on a different player.

I can't view the video because it's private, unfortunately.

Just checking because it often ends up being related to many an issue: if you're testing this in battle test, did you manually save your project after setting up your plugins and notetag?
I can't view the video because it's private, unfortunately.

Just checking because it often ends up being related to many an issue: if you're testing this in battle test, did you manually save your project after setting up your plugins and notetag?
Video should be fixed now. Yes I saved even closed RPG Maker reopened and tested to make sure. I've done through battle test and through new game.

Also the hexes can target hero or enemy and all targets need to wipe. So if you put a hex buff on an ally the debuff on enemies should clear too.
Oh, that's different from how you made it sound to begin with. In that case:

Code:
<JS On Add State>
    const hexes = [171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183]
    BattleManager.allBattleMembers().forEach(member => {
        hexes.forEach(hex => {
            if (hex !== state.id) member.removeState(hex);
        })
      })
</JS On Add State>
Thank you that is working perfectly. Sorry for the confusion at first. Yeah I just wanted her to be able to have 1 hex going at a time since they are free to cast but she can only maintain one at a time.

Original thread: https://forums.rpgmakerweb.com/threads/is-there-code-to-remove-a-state-from-everyone-in-a-battle.138396/