Elemental States Combination in battle

I want to do some elemental combinations in battle.
It can be state-to-state or state-to-element combinations.
Ex: Wet + Cold -> Freeze (state+state) or Wet + Ice attribute Skill -> Freeze (state+element).

Explanation:
First, a battler attacks and applies an elemental state (e.g. Wet) to an enemy, then if an ally attacks that enemy with a different elemental skill (e.g. ice attribute) or applies an another elemental state (e.g. Cold) --> the enemy will be applied another state that combines the above (e.g. Freeze), and also replaces the previous states.
Pictures:
A attacks the crab with Water attribute skill and appiles "wet" state to the crab.
1688746371386.png

The crab got wet.
1688746256369.png

B attacks the crab with Ice attribute skill (and appiles "cold" state to the crab (if needed/ state-to-state combination)).
1688746285658.png

--> The crab froze and lost "wet" (and "cold") states.
1688746464359.png

(Note:
The order in which the state is applied first can be changed.
Any types of combinations are OK and can be used flexibly.
I use some Visustella's plugins.)

Do you guys have any idea about any plugins or commands that can be used?
Just use the apply effects from VisuStella Skills and States.

e.g. your water state can have
Code:
<JS On Add State>
if (target.isStateAffected(id_of_cold_state))
{
    target.removeState(id_of_cold_state);
    target.addState(id_of_frozen_state);
    target.removeState(state.id);
}
</JS On Add State>
replacing the IDs of cold and frozen as appropriate, no leading zeros.
Just use the apply effects from VisuStella Skills and States.

e.g. your water state can have
Code:
<JS On Add State>
if (target.isStateAffected(id_of_cold_state))
{
    target.removeState(id_of_cold_state);
    target.addState(id_of_frozen_state);
    target.removeState(state.id);
}
</JS On Add State>
replacing the IDs of cold and frozen as appropriate, no leading zeros.
Thank you so much!
It's worked and help me a lot.
I'll try to improve my JS code skill lol.

Original thread: https://forums.rpgmakerweb.com/threads/elemental-states-combination-in-battle.159065/