How to make a skill add a state if it deals enough damage?

Hey there. To provide context, I'm making a skill named 'Tri Jabs', which involves the user punching the target thrice. Each punch has a power of 70%-90% ATK before reductions from DEF, but if the punch is a critical hit, it bypasses DEF completely. This is the current damage formula: a.atk * (0.7 + (Math.random()*20 / 100)) - (b.result().critical ? 0 : b.def).

So here's the thing, I want to make it so that if any of the three jabs deals over 15% of the target's remaining HP, it inflicts a state on the enemy (in this case, a debuff called 'Disoriented'). But I've no idea how to code this effect in the damage formula, or if it can be done without plugins.

Would really appreciate any suggestions.
I'd suggest using Yanfly's Skill Core for that.


<Pre-Damage Eval> if(value > (b.hp * 0.15)) { b.addState(n); //replace n with state number } </Pre-Damage Eval>
I'd suggest using Yanfly's Skill Core for that.


<Pre-Damage Eval> if(value > (b.hp * 0.15)) { b.addState(n); //replace n with state number } </Pre-Damage Eval>
It is worth noting that this will add the state before the damage is executed, which can be problematic if it's a state that can be removed by damage, since the attack might wind up knocking off its own effect.
It is worth noting that this will add the state before the damage is executed, which can be problematic if it's a state that can be removed by damage, since the attack might wind up knocking off its own effect.
If that's an issue, perhaps you could instead turn on a switch in the pre-damage eval, and if the switch is on, apply the state in the after eval and turn off the switch?
If that's an issue, perhaps you could instead turn on a switch in the pre-damage eval, and if the switch is on, apply the state in the after eval and turn off the switch?
I was thinking something along those lines, but the problem is that the OP is using a skill that repeats 3 times. So if the first hit applies the state, then the latter two hits could still knock it off.

You would need to apply the state and turn off the switch at the very end of the action, rather than at the end of each individual invocation of the action. I don't know if such a note tag exists in Yanfly's collection. We have some fitting VisuStella note tags for MZ (the JS Pre/Post-End Action note tags), so there might be a Yanfly equivalent, but I didn't notice anything that fits the bill when I took a quick glance.
What if you used a dummy state that expires in 1 turn to determine if the actual state should be applied? That way, in the event that the first hit procs, the subsequent hits would re-add the state if they removed it.
Pre-damage stage turn on a switch based on the conditional statement.

Post-damage stage conditional branch if switch is on: add state, turn off switch.
I'd suggest using Yanfly's Skill Core for that.


<Pre-Damage Eval> if(value > (b.hp * 0.15)) { b.addState(n); //replace n with state number } </Pre-Damage Eval>

This worked perfectly, thanks a lot Amaranth. Fortunately it's not a state that is removed by damage so that bit is no issue.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-skill-add-a-state-if-it-deals-enough-damage.149549/