How to change an enemy attack pattern based on player health

I'll explain.

Enemy has an attack that deals damage equal to the target's health - 1, essentially leaving them with 1HP. Then, I want the enemy, for their next attack, to check and see if any of the actors have 1 hp remaining. If they do, do a regular attack. If none of them do, once again use the attack that leaves a target with 1hp. And, when using this mercy attack, it should just be random on all actors with HP greater than 1.

I know very little about how enemy behavior works in this engine. From what I've tried, I can't get it to work. Any advice?
It's one of the free yanfly plugins.
This plugin allows you to entirely program the AIs of each of your enemies. What you are looking for is pretty easy to do with this plugin 👋 check it out !
You rock! Thank you!
You rock! Thank you!
No problem ! Don't hesitate to ask if you are having trouble using it, though the documentation makes it pretty easy to understand/to learn its usage 😤
So I am struggling just a bit and was hoping to get some guidance! I see that there is AI Priority.

<AI Priority>
condition: SKILL x, target
condition: SKILL x, target
</AI Priority>

So the priority for this would first want to check if any actors have 1 HP exactly. If any of them do, it would just use the regular attack command on one of them, at random.

However, if none have exactly 1 HP, we move on. If any actors do have greater than 1 HP, it would randomly pick one of them and use skill 126 on them.

So the first thing to realize is that there would be two conditions in the AI Priority tag. I don't want to check for an actor with the lowest HP, but exactly 1. I don't see a way to check for that in the plugin guide. Any advice?

As for the next part, well I'll worry about that once I figure out the first part.
So I am struggling just a bit and was hoping to get some guidance! I see that there is AI Priority.

<AI Priority>
condition: SKILL x, target
condition: SKILL x, target
</AI Priority>

So the priority for this would first want to check if any actors have 1 HP exactly. If any of them do, it would just use the regular attack command on one of them, at random.

However, if none have exactly 1 HP, we move on. If any actors do have greater than 1 HP, it would randomly pick one of them and use skill 126 on them.

So the first thing to realize is that there would be two conditions in the AI Priority tag. I don't want to check for an actor with the lowest HP, but exactly 1. I don't see a way to check for that in the plugin guide. Any advice?

As for the next part, well I'll worry about that once I figure out the first part.
There is multiple ways I can recommend of doing it. But I'll need to know how you want to use this plugin. In the parameters, this plugin allows you to customize it in multiples ways.

For instance, you could customize the plugin in order for it to use the classic AI if none of the conditions inside <AI Priority> are met. You can also change the intelligence of the AI (putting it at 100 means the AI will always follow the condition tree, putting it anything below 100 will have a chance for the AI to not follow the condition tree and do something random).

Please customize the plugin the way you want it to be used, then let me know how you're going with this, then I'll be able to give you something useful 👋

By the meantime, the condition you're looking for is this :
<AI Priority>
HP param > 1: SKILL x
</AI Priority>
If you do not wish to entirely build the AI of the enemy, makes it so that if none of the conditions required are met, it use the default enemy AI (from the engine one). Though I would recommend you to do the opposite and actually write the entire AIs of each enemy with <AI Priority>, and also put the AIs intelligence to 100, because it allows you for more complexity and to make your enemies actually way way smarter. But that's just my own opinion.

EDIT : To target a foe that have exactly 1 HP, just do HP param == 1
Thank you for taking the time to help me!

How does this look?

<AI Priority>
HP param = 1: Skill 1, random
Always: Skill 126, Highest HP
</AI Priority>

To break it down...the skill targets enemies, so when I say "HP", it's checking actor health. (Skill 1 in the regular attack skill) So according to this, the AI will check if any actors have 1 HP, and if they do, attack them. However, if none of the actors have 1 HP, it moves on to the next priority. This one is just set to Always because I don't want any other conditions on it. If no actors have 1 HP, this SHOULD happen. So it right away uses skill 126 on the actor with the most HP. Skill 126 has a damage formula of b.hp-1 which should be it calculates damage by taking the target (whoever has the most HP in this case) and doing damage equal to their HP minus 1, leaving them with exactly 1 HP regardless of all other stats. Hypothetically, if this was done on an actor with 1 HP left, it would do nothing. Skill 126 also costs 0MP, is an element that is never resisted or weak, has no critical chance, and no variance.

Also here is what I currently have...

1642194546426.png

This would mean that if a actor had 1 HP and healed, the enemy would still attempt to use a regular attack on them. That is what I want.

Does this appear it will work? Thanks again for your help!!!

Edit: Also if there is no AI priority at all set, does it just use the default AI?
Thank you for taking the time to help me!

How does this look?

<AI Priority>
HP param = 1: Skill 1, random
Always: Skill 126, Highest HP
</AI Priority>

To break it down...the skill targets enemies, so when I say "HP", it's checking actor health. (Skill 1 in the regular attack skill) So according to this, the AI will check if any actors have 1 HP, and if they do, attack them. However, if none of the actors have 1 HP, it moves on to the next priority. This one is just set to Always because I don't want any other conditions on it. If no actors have 1 HP, this SHOULD happen. So it right away uses skill 126 on the actor with the most HP. Skill 126 has a damage formula of b.hp-1 which should be it calculates damage by taking the target (whoever has the most HP in this case) and doing damage equal to their HP minus 1, leaving them with exactly 1 HP regardless of all other stats. Hypothetically, if this was done on an actor with 1 HP left, it would do nothing. Skill 126 also costs 0MP, is an element that is never resisted or weak, has no critical chance, and no variance.

Also here is what I currently have...

View attachment 212890
This would mean that if a actor had 1 HP and healed, the enemy would still attempt to use a regular attack on them. That is what I want.

Does this appear it will work? Thanks again for your help!!!

Edit: Also if there is no AI priority at all set, does it just use the default AI?
Change the Default AI Level to 100 so that your enemies will always follow the condition tree inside <AI Priority>.

Here's a correction :
<AI Priority>
HP param == 1: Skill 1
Always: Skill 126, Highest HP
</AI Priority>

You don't need to define the "target" after the Skill, so no need to put "Skill 1, random", the script will check by itself every possible foe.
You have to put "==" and not "=", a single equal will not work. In JavaScript, you use "=" to set a value to another one.
Well I think I will just set this specific enemy to have an AI of 100 and then use this plugin elsewhere in the game. Thanks for the clarification with the random part, I had no idea how that would work lol, I'm trying it out and will let you know if it doesn't work!
Well I think I will just set this specific enemy to have an AI of 100 and then use this plugin elsewhere in the game. Thanks for the clarification with the random part, I had no idea how that would work lol, I'm trying it out and will let you know if it doesn't work!
Works too. Just keep in mind that if your global Enemy AI level is 80%, then 20% of the time the enemy will do something random.

In your specific case, at least this particular enemy of yours, needs an AI level of 100, unless you want it to be inconsistent.

And no problem, just let me know ! 👋
It worked exactly as expected! Thanks a ton for helping me out with this!
It worked exactly as expected! Thanks a ton for helping me out with this!
No problem ! Glad your issue is solved 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-to-change-an-enemy-attack-pattern-based-on-player-health.143965/