Making enemy attempt to flee at low HP, but not 0 HP

I'm currently putting some finishing touches on fleeing monsters, but am still dealing with a particularly irritating little error. I have a script set up in a troop that makes an enemy attempt to flee at low HP, but it also triggers when the enemy is brought straight to 0, and I haven't found a way to fix that.

My script currently looks like this in the Troop page:

QrEgP5o.png


Even with that script, when an attack brings an enemy down to 0, it triggers the flee attempt. I can't figure out what exactly I did wrong.

PS: Before I make a whole separate thread about it... When you allow the enemy to flee, it forces the enemy to use the Escape action. Is there a script call to check if an enemy has fled? I realize it's a special effect rather than a state, so I don't know how exactly you would check this.
why use a script to check HP? why not use the official method with control variable?
Why don't you make a skill with common events?
Why don't you make a skill with common events?
can't work for such cases, it needs to be a troop event to trigger correctly.
but it also triggers when the enemy is brought straight to 0

if you're checking for enemy 1 < 25% HP, and then checking for troops()[0] > 0, and it's still triggering, then that means that troops[0] is still > 0, which means that troops[0] != enemy 1
Just tried the setup cited in the opening post and it worked as expected for me without any plugins active. I then added Yanfly's Battle Engine Core plugin and tested again: same result.

A couple of ideas:
  1. Multiple troop events can trigger at a time. Double-check your troop event pages 2, 3, and 4.
  2. What plugins are you using?
I'm not sure what I was doing wrong, but I booted it back up today and it was working properly without having made any changes... Thanks for the help anyway??? I guess???

In regards to the second question, does anyone know what script call checks if an enemy has escaped? I'm using SumRndmDde's HUD maker and have added HP bars. The condition for their appearance is, for example:

$gameTroop.members()[3]

Meaning the bar will only appear if there is an enemy with index 3. However, I want the bar to disappear if the enemy uses the Escape action, and so far an enemy that has escaped still counts as existing in the battle. So ideally the condition will be something like:

$gameTroop.members()[3] "and not" (whatever the script call is for an enemy having the Escape special effect)
@Damascus7
programming doesn't work that way.

the HUD remains because the plugin writer did not include a command to remove it when the enemy escapes. That is the part that you would have to change, and that requires rewriting the plugin code.
There is no simple way to call a function to remove that - if there were, it would have automatically happen.
@Damascus7 Try this~
Code:
$gameTroop.members()[3] && $gameTroop.members()[3].isAppeared()
Technically the "escape" effect just flips the battler's _hidden flag; isAppeared() checks that flag and returns true iff they're not hidden.

If that doesn't work, I'd guess that SRD's HUD does not update every frame, in which case what @Andar said applies. 😅
@Damascus7 Try this~
Code:
$gameTroop.members()[3] && $gameTroop.members()[3].isAppeared()
Technically the "escape" effect just flips the battler's _hidden flag; isAppeared() checks that flag and returns true iff they're not hidden.

If that doesn't work, I'd guess that SRD's HUD does not update every frame, in which case what @Andar said applies. 😅

This is excellent! I'm already using a condition checking for hidden enemies in other troops, so this is easy to copypaste over. The result works perfectly; the HP bars disappear as soon as the enemy escapes.

Thanks for your help! You've helped me on so many of my problems and I'm so grateful lol
You're welcome, happy RPG Making! 😂

Original thread: https://forums.rpgmakerweb.com/threads/making-enemy-attempt-to-flee-at-low-hp-but-not-0-hp.114584/