Want to remove a state only when taking an attack

I have a very specific state that I haven't been able to find any help with just searching, so figured I'd ask on the forum. Here's what the state does:

- Gives the user an extra action as long as it remains
- Reduces the next instance of damage taken to 0
- When damaged, removes the state

How it functions right now, I just have the state give another action, and raised the defenses of the user to 1000%, while also having the "remove by damage" box checked in the state. Then there's another plugin that makes it so "remove by damage" occurs even when there's 0 damage taken, otherwise the state would just reduce all damage to 0 and remain up forever.

However, for some reason when the user takes "anything" while the state is up, it will disappear. Meaning you can target them with a buff, or a healing item, or even an AoE heal and the state will vanish. I'd like for it to only vanish on damage, if possible. Anyone know how to make this work?
Make every attack remove that state.
you can use yanfly's buffs and states plugin to make a state with a custom react effect where if the battler is hit with a damaging skill, itll set the damage to 0 and remove itself
you can use yanfly's buffs and states plugin to make a state with a custom react effect where if the battler is hit with a damaging skill, itll set the damage to 0 and remove itself
I have Yanfly's "BuffsStatesCore", is that it? If so, I would have no idea what I'd need to put on the state's notetags in order for that to work.
Code:
<Custom React Effect>
if (value>0)
{
    value = 0;
    target.removeState(stateId);
}
</Custom React Effect>
Code:
<Custom React Effect>
if (value>0)
{
    value = 0;
    target.removeState(stateId);
}
</Custom React Effect>
Thank you very much for this, does seem like exactly what I'm looking for, but it didn't seem to work. I changed it to this since the defenses are high enough "all" damage should be 0, but it still doesn't work.

<Custom React Effect>
if (value = 0)
{
value = 0;
target.removeState(53);
}
</Custom React Effect>
That's not correct JavaScript syntax.

If you're using a notetag to make the damage be 0, you shouldn't also be artificially inflating defense. Take that Trait off.
That's not correct JavaScript syntax.

If you're using a notetag to make the damage be 0, you shouldn't also be artificially inflating defense. Take that Trait off.
Alright, removed the defense increases and did it exactly as you posted. It works pretty much perfectly with only one minor quirk, but that doesn't matter too too much with this state in particular. Thank you very much for the help.

Original thread: https://forums.rpgmakerweb.com/threads/want-to-remove-a-state-only-when-taking-an-attack.164720/