Resisting Death, leaving at 1 HP state

Some games contain ways to avoid death. Pokemon does this with the Ability "Sturdy", the move "Endure", and several held items. These abilities mean that if the pokemon possessing the trait were to be killed in a single hit, they would instead be left at 1 HP (a second hit while at less than full health will kill them as usual).

More relevantly, Fire Emblem contains the skill "Miracle", which gives the user a chance of evading death while their HP is greater than 1: Any character equipped with the Miracle skill has a Luck% chance to be placed at 1 HP instead of 0.

I would like to replicate Miracle as a State within my own game. While the state is active, the user would have a Luck% chance of being left at 1 HP after taking fatal damage, instead of being killed. The state would only be active while the user has more than 1 HP. This second part I have achieved using Yanfly's Auto Passive States plugin (which allows me to add an auto state to a skill learned by the actor, and this state has the condition of "<Passive Condition: HP Above 1>":
Plugin in question: http://yanfly.moe/2015/10/17/yep-13-auto-passive-states/

The first part is the problematic part though. Does anyone know of any plugins or RMMV functions capable of creating this resist death effect? I'm currently substituting by having the state apply the RMMV function "resist state: Knockout", but this leaves the user at 0 HP instead of 1, meaning that as soon as the state is removed by the condition no longer being met, the user dies anyway. The Luck% chance is optional, I'm fine with it being a 100% chance, because 100% chance of needing 1 extra attack to kill a character instead of a 50 or 60% chance isn't a particularly big game changer, especially considering how fragile the units capable of learning Miracle are.
To get something like this, you'd want to modify the incoming damage of an attack such that it never exceeds the target's current HP (so long as this passive state is on).

So we'd use a <Custom React Effect> to do just that. React effects have the ability to know the incoming damage amount before it hits the target, and also modify it.

So we'd do something like this on your passive state:
Code:
<Custom React Effect>
if (value > target._hp) {
 value = target.hp - 1
}
</Custom React Effect>
If you want to add in some randomness, we can also do that in the same if condition:
Code:
<Custom React Effect>
if (value > target._hp && (Math.random()* 100) > 40 ) {
 value = target.hp - 1
}
</Custom React Effect>
If you want the luk stat of the defender to be involved, well, add that to the random check:

Code:
<Custom React Effect>
if (value > target._hp && ((Math.random()* 100) + Math.round(target.luk/64) > 40 ) {
 value = target.hp - 1
}
</Custom React Effect>
Every 64 luk the target has, starting at 32, causes a 1% increased chance for the effect to trigger. Neat eh?
That looks perfect! Which plugin is it using, though? I don't recall seeing any Custom React Effect plugins.
Yanfly's Buffs States Core

Original thread: https://forums.rpgmakerweb.com/threads/resisting-death-leaving-at-1-hp-state.79567/