[SOLVED] Skill effect conditioned to target's HP

Hey 😍

How could I make a skill that, if target HP is lower than, let's say, 500, makes target escape, and if it's higher, apply stun state to user?

I have all yanfly plugins but I got lost in all the possibilities and I don't know how to program, so those eval texts are alien language to me 😢
try the common event. select abort battle (i think?) then set it into your effect. if not then use Common Event: x
I don't think "abort battle" is what I'm looking for, because it's supposed to be single target. And also the part I'm having trouble with is exactly setting up the conditions in a way that works 😢

I mean, I know it's "if targets hp > 25% add "escape" effect ; else add stun state on user", but I don't know how to translate that into a working code to a skill, I guess?
You can use what you have in that note tag but it needs to be inside an action sequence. Take this:

Code:
<setup action>

</setup action>

<whole action>
</whole action>

<target action>

</target action>

<follow action>
clear battle log
</follow action>

<finish action>
    perform finish
</finish action>

Insert what you have between the <target action> and the </target action>
Insert what you have between the <target action> and the </target action>

it didn't work 😐 nothing happens

edit: I changed and now the stun part works, but not the escaping part
Code:
<Target Action>
perform action
motion wait: user
action animation
wait for animation
if $gameTroop.members()[-2].hp() < 150
        action effect
    else
        ADD STATE 12: user, (show)
death break
</Target Action>
Who exactly are you trying to target? Is it specifically the target in index 2?
You could always give that target a passive state that banishment can check.

So:
if target.hp < 150 && target.isStateAffected(419)
action effect

You would replace 419 with whatever passive state you gave that enemy.
Who exactly are you trying to target? Is it specifically the target in index 2?
You could always give that target a passive state that banishment can check.

So:
if target.hp < 150 && target.isStateAffected(419)
action effect

You would replace 419 with whatever passive state you gave that enemy.

I'm using "-2" as in "last targeted". I'm not sure adding a state would solve this, I'm having trouble making the first part work (if hp<150, banish target), I think there's something wrong with the coding but I don't know what it is

Edit: I did it!
Skill has "escape" effect. If target hp is <= 20%, it flees from battle; else, user is affected with state 12 (stun).
Code:
<Target Action>
perform action
motion wait: user
action animation
wait for animation
if (target.hp / target.mhp <= 0.20)
        action effect
    else
        ADD STATE 12: user, (show)
death break
</Target Action>

Original thread: https://forums.rpgmakerweb.com/threads/solved-skill-effect-conditioned-to-targets-hp.128707/