Passive: Cheating death system

Hello everyone,
I've been thinking of adding a cheating death system in my game which features a skill tree. I wanted to make it quite similar to the one in The Evil Within 2, where the player can survive a lethal hit if the hit does only slightly more damage than the remaining hp of the player. The skill is upgradable which improves the threshold at which the skill is triggered. Yanfly's work on "Second chance" (Link here: http://yanfly.moe/2016/03/23/tips-tricks-second-chance-kingdom-hearts/ ) helps me a lot but the passive can trigger even if a massive blow hits the player with 2hp, which breaks the realistic vibe of my game.

So here's my question: Is it possible to trigger the passive on the following conditions? Here's an example: Player has 20/100 hp left. His "cheat death" threshold is at 5% which means if an enemy hits him for 25 damage, he will survive with 1hp, If it inflicts 26 damage or more, the player will die. Additionally, to prevent surviving small blows, he has to have more than only 1 hp for the passive to trigger. This skill can be upgraded in the skill tree after unlocking, improving the threshold from 5% to 10% for example.

I think the biggest issue here is to calculate whether the player will survive the hit depending on his current HP and maxHP.

Hope I made my problem understandable!
Thank you in advance for your help 🙂

PS: I don't know if this post is in the right location, considering whether it is a Maker issue or Plugin related. Excuse me in advance if it's not!
Haven't tested, but based on the linked example, I think you could add a condition in the <Custom React Effect> notetag:
Code:
<Custom React Effect>
// Calculate overkill damage, if any
var overkillDmg = Math.max(0, value - target.hp);
// Calculate max damage "cheat death" can withstand
var overkillLimit = Math.floor(target.mhp * 0.05);
// Check to see if the party is in battle and target was not squashed flat
if ($gameParty.inBattle() && overkillDmg <= overkillLimit) {
  // Sets the flag if the target has more than 1 HP at the time of death.
  target._secondChance = target.hp > 1;
}
</Custom React Effect>
The value variable is the damage value, negative for healing. So now _secondChance can only activate if the "overkill damage" (i.e. damage exceeding target's current HP) is at most overkillLimit, which here I've defined as 5% of the target's max HP (rounded down). 🙂
Wow that's perfect! I'll try to apply it now. Thank you very much!
Like I said, I didn't test it, but hopefully it works! 🙏

Original thread: https://forums.rpgmakerweb.com/threads/passive-cheating-death-system.105377/