Seeking script for one state negating another upon infliction

I would like certain states in my game to oppose other states, so that if you are inflicted with one state and then receive an "opposite" state, the original state is removed but the new state is not added.


For example, Character A is afflicted with Deprotect (lowered defense). If Character B casts Protect on Character A, then Deprotect is removed, but Character A is not granted the Protect state. Ideally, this would display the "state removed" for the cancelled state.


I'm fairly proficient with VX Ace coding, so if there is a solution that requires that, I can manage. But the simplest solution would be greatly preferred. :3
Don't have access to Ace on this computer, so can't check, but try something like this in the damage formula box:


if b.state?(x); b.remove_state(x) : b.add_state(y)


This checks if state x (Deprotect) is present, if it is, then it removes it.  If it is not (the other side of the colon), then it will add state y (Protect)
That wouldn't work out well. I imagine it'll cause a "[character] took no damage!" message if there isn't a damage aspect to the attack, but no actual message regarding the removal or addition of the state. It also would mean that the nullifying state would automatically hit, thus there'd be no chance for the debuffs to miss.


(Also, my damage formula is fairly complicated and that addition won't fit in the formula box. :3)
Bump!
I have an add/remove state commands script that might be useful.  Search for it in the RGSS3 Scripts section.
As an alternative, though this might end up being a bit more work: you could also create such an effect using database settings:



- Make the "Protect" and "Deprotect" states resist each other


- Make your Protection skill to first add "Protect" to the target (fails if the target is deprotected) and then remove "Deprotect" from it
As an alternative, though this might end up being a bit more work: you could also create such an effect using database settings:



- Make the "Protect" and "Deprotect" states resist each other


- Make your Protection skill to first add "Protect" to the target (fails if the target is deprotected) and then remove "Deprotect" from it

That works perfectly! And I think I could do quite a bit handling it like this, without having to script. Thanks! :3

Original thread: https://forums.rpgmakerweb.com/threads/seeking-script-for-one-state-negating-another-upon-infliction.68344/