Survive Lethal Blows.

In my game, each party member has a special ability. One of the ones I came up with is that, if this character suffers a killing blow, there's a 25% chance that he will survive the hit with 1 HP. I was wondering how it was possible (if at all) to implement this in RPG Maker.
I'm sure there are cleaner ways to do this (with plugins anyway) but the simplest solution that I can think of would be to have that ability both turn on a switch and give the character a state that makes them immune to state 1 (the knockout/death state). Then throw in a battle event (yanfly has a plugin that allows you to make a certain troops battle event universal to all troops so you won't have to copy/paste it into every encounter) with the conditions: actor with the survival ability HP <=0% & switch that the special ability activates is On. Then for the meat of that battle event you set a variable to random 1-4, have a conditional branch follow where if that variable is equal to 1 you restore 1 hp to the character, turn off the switch and remove the state (for some reason you can't have battle events proc by state or the switch would be unnecessary. It's purpose is so that the event won't keep procing if the character keeps getting hit consecutively without reactivating the special ability. If it is passive I'd just have a common event reactivate said switch and state after the battle ends) and have the else branch merely remove the state and the switch without restoring any health (which will make that character die as intended.)
Quick snippet, not sure if this would break anything though
Code:
class Game_Actor
  def on_damage(value)
    if value > self.hp && rand <= 0.25 && @actor_id == 1 # <-- Actor ID
      @result.hp_damage = value = self.hp - 1
    end
    super(value)
  end
end
For debugging purpose, if you want the lethal hit dodge proc rate is 100%, try to change "rand <= 0.25" into "rand <= 1"

Original thread: https://forums.rpgmakerweb.com/threads/survive-lethal-blows.87052/