State that stops health from dropping below 1

Hi, I was wondering if there was a way to create a state that stops health from going below 1. I tried using yanfly's buffs and states core along with this:
<Custom Respond Effect> if (user.hp == 0) { user.gainHp(1); } </Custom Respond Effect>
But it doesn't trigger at all. Does anyone know what to do?
"User" in this context means whoever is attacking. Use "target" instead.
Is the built-in "Immortal" state not sufficient for whatever you're trying to do?
"User" in this context means whoever is attacking. Use "target" instead.
Thanks, it works.
Is the built-in "Immortal" state not sufficient for whatever you're trying to do?
Immortal lets the hp stay at 0 so when it's removed, the actor instantly gets KO'd. I don't want that.
If you use what you have, the gainHp() will show up during battle with a popup number wherein the target will take the damage and then heal one back. To me, this would look weird - if you agree, use the tweak below:
<Custom React Effect> value=Math.min(value, target.hp-1); </Custom React Effect>
That will change the incoming damage so that it can't kill the target.
If you use what you have, the gainHp() will show up during battle with a popup number wherein the target will take the damage and then heal one back. To me, this would look weird - if you agree, use the tweak below:

That will change the incoming damage so that it can't kill the target.
I saw and swapped it out with _hp = 1 but yours looks like better practice. Thank you!
I saw and swapped it out with _hp = 1 but yours looks like better practice. Thank you!
Yes - directly setting hp is never desirable. It bypasses everything that checks for the battler to die, or revive from death, set their sprite, all that stuff.

Original thread: https://forums.rpgmakerweb.com/threads/state-that-stops-health-from-dropping-below-1.144872/