MZ How to implement a state that gives the player a chance to survive a fatal attack with 1 HP?

As the title says, I'm trying to implement a state that when the player takes a fatal attack, will have x chance to survive the hit instead and have 1 HP. I know how to make things immortal using a resist death state, but that's not quite what I'm aiming for, as that's a guaranteed survive. I don't know if its something that can be done without the use of a plug-in or not, but if it needs a plug-in to work and one exists, where could I find it?
VS BattleCore state notetag

<JS Pre-Damage as Target>
if (value >= target.hp && Math.random() < X) {
value = target.hp - 1;
}
</JS Pre-Damage as Target>

EDIT: Put X like 20% is 0.2
Thank you! Works perfectly.
Oh yeah, you might want to add in the if conditional (I always forget these):

&& this.isDamage() && this.isHpEffect()
Is there a way to do this without VisuStella Battle Core?
Is there a way to do this without VisuStella Battle Core?

You're probably going to have to make a common event and have it run in the battle.

Its really basic, but something like this could be a good start!

1748024535505.png
Is there a way to do this without VisuStella Battle Core?
ATT_Turan's Eval Tags plugin should be able to do the same as the VS JS notetags if you want the functionality without all of the baggage that comes with VS battle core
ATT_Turan's Eval Tags plugin should be able to do the same as the VS JS notetags if you want the functionality without all of the baggage that comes with VS battle core
Oh great! So the same notetag and the same if conditional that rpgLord69 used would work with ATT_Turan's Eval Tags? :0
Oh great! So the same notetag and the same if conditional that rpgLord69 used would work with ATT_Turan's Eval Tags? :0
youd have to use his equivalent for the notetags, so you'd use <Action Respond Eval> instead of <JS Pre-Damage as Target>.
the code should be the same, but you might have to change uses of "this" to "skill"
youd have to use his equivalent for the notetags, so you'd use <Action Respond Eval> instead of <JS Pre-Damage as Target>.
the code should be the same, but you might have to change uses of "this" to "skill"
Thank you so much! I will try it ^-^
VS BattleCore state notetag

<JS Pre-Damage as Target>
if (value >= target.hp && Math.random() < X) {
value = target.hp - 1;
}
</JS Pre-Damage as Target>

EDIT: Put X like 20% is 0.2
Another question regarding this, how would I modify it to check if the target has a certain percent of TP available, we'll say 70%, and if so, then this activates but then sets their TP to 0?

Original thread: https://forums.rpgmakerweb.com/threads/how-to-implement-a-state-that-gives-the-player-a-chance-to-survive-a-fatal-attack-with-1-hp.177857/