Health Gating/Limit Damage based on parameters?

Hey there! I'm looking for a conversion of a smallscript I had used during a VX Ace project. Small script, can be found below:

Code:
HEALTH_GATING_PERCENT = 60
HEALTH_GATING_SWITCH = 487

class Game_Actor < Game_Battler
  def make_damage_value(user, item)
    super(user, item)
    # If a skill that deals HP damage, check gating
    if item.is_a?(RPG::Skill) && @result.hp_damage > 0
      if !$game_switches[HEALTH_GATING_SWITCH] && hp_rate * 100 > HEALTH_GATING_PERCENT && @result.hp_damage >= hp
        @result.make_damage(hp - 1, item)
      end
    end
  end
end

The goal is to have a variable, in this case HEALTH_GATING_PERCENT, and if the targets health is more than that value as a percentage, then the blow cannot kill them, and will instead deal enough damage to leave them with 1 HP. The HEALTH_GATING_SWITCH is a.. well, switch/boolean, whatever you prefer terminology-wise, that determines whether or not it should be active. A reason for this might be a boss mechanic that one-shots the player, or something akin to that. Additionally, as per the original script, it should only be active for party members-- enemy battlers can be one-shot all day.

If something like this already exists for MV, then I apologize and humbly request to be directed towards it 🙂
Here you go 😉

You can set the hp percentage and switch in the parameters.
Gating will only occur if the switch is on.

Let me know if there's any problems.
Thank you very much! It seems to work flawlessly. 🙂 I hope it wasn't too much of a hassle for you!
Thread closed IgnoreMe
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/health-gating-limit-damage-based-on-parameters.79907/