Battle AI Core: priority issues

Hello,

I'm having an issue with Battle AI Core not doing what I need it to do. The default AI level is at its maximum, so they have to be following it strictly.

In one of the enemies' notes, I wrote this:

Code:
<AI Priority>
   User MP param = 0: Skill 2, User
   State === State 16: Skill 129, Lowest HP%
   HP% param <= 99%: Skill 129, Lowest HP%
   User MP param > 1: Skill 90, User
</AI Priority>

Skill 2 is a skill that ends the user's turn once they're out of MP, it's on all enemies and it works.
Skill 129 is a heal that removes the Burning state (state 16), I want that heal to prioritize the enemies' allies that are on fire.
Then, I want the heal to be cast on allies with the lowest amount of HP, even if they're not on fire.
If these situations are not present, I want the enemy to use Wait, skill 90, to wait unless they only have 1 MP left.

In practice, the enemy keeps healing enemies that have 100% HP and aren't on fire.
What do I need to write so that everything works as planned?
firstly, I guess the first line contain a mistake. See below how I would write it.
JavaScript:
<AI Priority>
   User MP param === 0: Skill 2, User
   State === State 16: Skill 129, Lowest HP%
   HP% param <= 99%: Skill 129, Lowest HP%
   User MP param > 1: Skill 90, User
</AI Priority>

Can you tell us if you have well ordered the plugins according to the yanfly published list ?
firstly, I guess the first line contain a mistake. See below how I would write it.
[...]
Can you tell us if you have well ordered the plugins according to the yanfly published list ?

The first line is now fixed on all enemies. I just moved every plugin to their recommended order, and the first thing that enemy did in battle (Skill 129 having increased cast speed) was to heal an unharmed enemy that wasn't on fire. Something else isn't working.
I have a lot of experience with this plugin, and with the correction that @Lay recommended, it looks like a well-made notetag to me. (I notice that I used title-case "Param" rather than "param" in my own notetags, but I don't think that will matter since Yanfly's plugin seems to uppercase everything to avoid case mismatches.)

If you are doing anything wacky that could put restrictions on enemies' skills (or change their MP values), such as using Yanfly's Enemy Levels plugin, you may want to turn those off, save, and see if you can get better behavior from the enemies.

One of the things I did a lot while testing behavior, if I felt like the enemy should be using a certain skill and they didn't use it, was to put a line in the top of the AI Priority list with the condition "Always" - for example, Always: Skill 24, Random If the enemy still doesn't use this skill, it means that there's either something wrong with the Skill itself, or something larger (like a plugin incompatibility) at play. In this case, you could put do this with Skill 90 since that's the skill you're expecting to be used on turn 1.

If the enemy DOES use the skill properly under the Always condition, it means there is indeed something wrong with your AI logic, or that you have made mistaken assumptions. For example, check to make sure that State 16 is actually Burning, and check to make sure that you are not using events to start some enemies out at less-than-full HP (which you might have done earlier to test other behavior).

One final improvement you could make, and I don't think this is what is causing your error, is to make the final line > 0 instead of > 1. Because if the user's MP is exactly 1, then it won't match the first line or the last, and I can't imagine a scenario where that's what you intended.
Thank you so much for your time.

One of the things I did a lot while testing behavior, if I felt like the enemy should be using a certain skill and they didn't use it, was to put a line in the top of the AI Priority list with the condition "Always" - for example, Always: Skill 24, Random If the enemy still doesn't use this skill, it means that there's either something wrong with the Skill itself, or something larger (like a plugin incompatibility) at play. In this case, you could put do this with Skill 90 since that's the skill you're expecting to be used on turn 1.
I just added the Wait command at the top of the priority list and put it on Always, the enemy waited at every turn. I know it didn't skip the AI notes because the heal has a weight of 9 and Wait has a weight of 1 in the list.
Before putting it back, I gave it its MP >= 1 condition again while it's still at the top. This time, it didn't pass the check and the enemy started healing on turn 1 again. Could my conditions be the issue?

If the enemy DOES use the skill properly under the Always condition, it means there is indeed something wrong with your AI logic, or that you have made mistaken assumptions. For example, check to make sure that State 16 is actually Burning, and check to make sure that you are not using events to start some enemies out at less-than-full HP (which you might have done earlier to test other behavior).
State 16 is indeed Burning, and I have no base troop event or specific troop event that reduces the enemies' HP. To test if it works, I spend the first turn making my characters either buff themselves or heal each other. Then at the following turns, I make them hit different enemies, either of which don't always end up being the targets of the heals.

One final improvement you could make, and I don't think this is what is causing your error, is to make the final line > 0 instead of > 1. Because if the user's MP is exactly 1, then it won't match the first line or the last, and I can't imagine a scenario where that's what you intended.
This line is intentional. I make all my enemies' stats match those of the player character at the level they should be fought. For this one, the player should have 3 base MP. Because the healing spell costs 2 MP and the enemy has no other way to spend those points, the AI for the wait command checks if the user has at least enough MP to cast the healing skill otherwise it's pointless. So what I should actually do is move the Skill 2 line all the way down the list and put its condition to MP <= 1. The reason why I don't set that enemy's MP at just 2 to rig things a little is that my player characters have easy access to skills and basic attacks that can remove 1 MP.

The note is now (without the parts after //)
Code:
<AI Priority>
   State === State 16: Skill 129, Lowest HP%   //Heal enemies that are on fire to put it out
   HP% param < 100%: Skill 129, Lowest HP%  //Heal enemies that are hurt
   User MP param <= 1: Skill 2, User                 //End your turn if you don't have enough MP to heal
   User MP param > 1: Skill 90, User                 //If you do have enough just wait
</AI Priority>
and the enemy still heals at the start of turn 1.

One thing I've noticed in Yanfly's video is that the Heal spell that is programmed in the notes isn't part of the enemy's skill list. In my game, if a skill in the AI priority list isn't in the enemy's skill list, it's never used.
You are getting some very strange behavior!!

I just added the Wait command at the top of the priority list and put it on Always, the enemy waited at every turn. I know it didn't skip the AI notes because the heal has a weight of 9 and Wait has a weight of 1 in the list.
Before putting it back, I gave it its MP >= 1 condition again while it's still at the top. This time, it didn't pass the check and the enemy started healing on turn 1 again. Could my conditions be the issue?
It's certainly possible that your Conditions are the issue. But looking back on the conditions that I wrote (example below), and I tested each of them thoroughly and they all worked, I feel like the Conditions are well-formed.
User Level Param >= 20 +++ User MP Param >= 120 +++ Random 25%: Skill 54, Lowest HP%

The fact that it works as intended when you use Always, but not with MP >= 1, and the fact that the enemy seems to have enough MP to use the Heal skill, is what is so confounding about this.

I believe the intended behavior for falling through to the Weighted Skill List is that it only uses the Weighted Skill List if none of your Conditions at all have been met. For the rest of your debugging process, I'd recommend creating a new skill with an obvious name/animation and no MP cost - and an Always line for this skill as the last line of your AI tag, and also make this the only skill that the enemy can use in the Weighted Skill List. That will rule out fall-throughs as the reason your enemy is using the Heal skill (or using Wait if their MP is not being read correctly for some reason).

It would be very weird if you ever do see this new dummy skill being used, since with your new notetags User MP param <= 1 and User MP param > 1 should together make a catch-all that it never falls past. If you do see the dummy skill get used, let me know!

State 16 is indeed Burning, and I have no base troop event or specific troop event that reduces the enemies' HP. To test if it works, I spend the first turn making my characters either buff themselves or heal each other. Then at the following turns, I make them hit different enemies, either of which don't always end up being the targets of the heals.
Right, it sounds like you're doing everything right here.

The note is now (without the parts after //)
Code:
<AI Priority>
   State === State 16: Skill 129, Lowest HP%   //Heal enemies that are on fire to put it out
   HP% param < 100%: Skill 129, Lowest HP%  //Heal enemies that are hurt
   User MP param <= 1: Skill 2, User                 //End your turn if you don't have enough MP to heal
   User MP param > 1: Skill 90, User                 //If you do have enough just wait
</AI Priority>
and the enemy still heals at the start of turn 1.

I'm flying a bit blind and making assumptions because I haven't seen your game, but seeing a line that suggests using some kind of "Wait" skill (which, in MV's default behavior, means passing your turn) only if you have enough MP to act, and having that be different than Skill 2 (traditionally Guard) which the battler could use to pass their turn, together that makes me think that you have some kind of unique battle system plugin being used (or at least something very complex that you have done yourself). Is this the case?

If so, I would definitely recommend disabling (turning OFF) this battle system, if possible, and any other non-AI plugins that directly tie into the skill system (even turn off stuff like Instant Cast for this test, even though I can confirm it can coexist fine with AI Core). Save your project, and try testing again. If it works properly now, there is almost certainly an incompatibility in your plugins.

One additional thing I could think of is a problem in the skills' Scopes. Since you specify a target (here, you are specifying "User" for the End/Wait skills), I think only the User will be checked to see whether the skill can be used on him. If your skill's Scope is something like "1 Enemy" or "None", this might prevent the AI Core from ever selecting it, whereas targets are not specified in the standard Weighted Skill List box. Make sure that the Scope for skills 2 and 90 makes sense ("The User" or "1 Ally" should be good).

A couple other things you could try:
  • Try changing "MP param" to "HP param" on both MP param lines. If that fixes it, there may be some problem with the way your battle engine understands MP.
  • Try changing HP% param < 100% to something like HP% param < 70%. There's no reason that < 100% shouldn't work, but I could envision a scenario where rounding errors are causing this Condition to evaluate as true on a full health enemy.
  • Check your Note box and make sure there aren't any unmatched <notetags> </notetags> anywhere. Also be sure to hit F12 (sometimes F8) when you start a playtest and see if any suspicious error messages are in the console log.
  • Try changing "param" to "Param". Like I said last time, case shouldn't matter in these notetags, but if you've already tried all those other things... worth a try, right?
One additional thing I could think of is a problem in the skills' Scopes. Since you specify a target (here, you are specifying "User" for the End/Wait skills), I think only the User will be checked to see whether the skill can be used on him. If your skill's Scope is something like "1 Enemy" or "None", this might prevent the AI Core from ever selecting it, whereas targets are not specified in the standard Weighted Skill List box. Make sure that the Scope for skills 2 and 90 makes sense ("The User" or "1 Ally" should be good).
The plugin's Wiki does indicate that the scope line isn't mandatory, so I can definitely remove it for Wait (90) and End Turn (2).

I believe the intended behavior for falling through to the Weighted Skill List is that it only uses the Weighted Skill List if none of your Conditions at all have been met. For the rest of your debugging process, I'd recommend creating a new skill with an obvious name/animation and no MP cost - and an Always line for this skill as the last line of your AI tag, and also make this the only skill that the enemy can use in the Weighted Skill List. That will rule out fall-throughs as the reason your enemy is using the Heal skill (or using Wait if their MP is not being read correctly for some reason).

It would be very weird if you ever do see this new dummy skill being used, since with your new notetags User MP param <= 1 and User MP param > 1 should together make a catch-all that it never falls past. If you do see the dummy skill get used, let me know!
Alright, so I've set up a troop with an enemy who does nothing but end its turn, and the healer who's being a pain in the booty. The latter has a skill called "AI fall-through" at the bottom of the AI list, set on always; it also has only one skill in its skill list called "Complete fall-through".
The enemy first used AI fall-through. Then my character hit the dummy enemy.
In the second turn the enemy used its heal on the dummy.
In the third turn the enemy ended its turn.

What we can conclude is that the skill list is indeed only useful for the skills I want an enemy to use after the AI priority list. The heal worked as intented, when someone on the troop was hurt, but Wait wasn't set up correctly otherwise it would've been cast instead of AI fall-through on turn 1.

So the changes I've applied is to simply put Wait instead of AI fall-through, with the same conditions.
The enemy started using Wait as intended, when it has nobody to heal.
But now I've come across an issue: because the only character in my playtest save doesn't have a buff skill, I made him end his turn on turn 1. That caused the healer to Wait on loop. More on the reason why after the next quote.

I'm flying a bit blind and making assumptions because I haven't seen your game, but seeing a line that suggests using some kind of "Wait" skill (which, in MV's default behavior, means passing your turn) only if you have enough MP to act, and having that be different than Skill 2 (traditionally Guard) which the battler could use to pass their turn, together that makes me think that you have some kind of unique battle system plugin being used (or at least something very complex that you have done yourself). Is this the case?
In my game Skill 2 is End Turn, which makes the user unable to act, virtually until the battle ends. Once everybody still alive in the fight is under this state, everybody's MP is recharged and the state is removed. As a result, everything besides passive/triggered skills and End Turn cost at least 1 MP (actually called Action Points in my game).
My battle system is all eventing and no plugin besides Common Troop Events.
The Burning state, instead of dealing damage every RPG Maker turn, will only hurt with a triggered skill once I'm processing the end of the battle system turn.
Back to the softlock, it's caused by the fact that the enemy never has a reason to end its turn. It keeps having more than 1 MP, so it just keeps on waiting while nothing else happens.

If so, I would definitely recommend disabling (turning OFF) this battle system, if possible, and any other non-AI plugins that directly tie into the skill system (even turn off stuff like Instant Cast for this test, even though I can confirm it can coexist fine with AI Core). Save your project, and try testing again. If it works properly now, there is almost certainly an incompatibility in your plugins.
The only plugin linked to this battle system is Yanfly's Common Troop Events, which only saves me from the headache of copy-pasting the same troop event pages over and over again to make my battle system work. Which would be hell every time I add a new passive or a triggered skill.
What we can conclude is that the skill list is indeed only useful for the skills I want an enemy to use after the AI priority list. The heal worked as intented, when someone on the troop was hurt, but Wait wasn't set up correctly otherwise it would've been cast instead of AI fall-through on turn 1.
I'm still a little surprised that the Wait Skill wasn't being evaluated properly - which makes me think it had something to do with the Scope in the condition, or something in the skill itself (anyone reading this know? please shout it out!), but in either case it sounds like you have a solid work-around in placing it at the end as a fall-through. 🙂

So the changes I've applied is to simply put Wait instead of AI fall-through, with the same conditions.
The enemy started using Wait as intended, when it has nobody to heal.
But now I've come across an issue: because the only character in my playtest save doesn't have a buff skill, I made him end his turn on turn 1. That caused the healer to Wait on loop. More on the reason why after the next quote.
Right. Based on the system you've described, this would be the (unfortunate) behavior we'd expect to follow from your AI setup.

I might go about trying to "fix" this by modifying whatever troop event you're using each turn to check the battlers' End Turn states. You might modify it to check to see whether all (non-dead) battlers have either a Wait state OR and End Turn state on them (you seem to have a good grasp of eventing, so I assume you can set this up, but if you need help, just ask!). That would break deadlocks where every battler is waiting on another change in the situation before acting, and would also add a slight strategic wrinkle where it can risky to Wait for too long while ahead on MP.

A simpler, but less solid, solution, would be to make sure that every battler has something fairly practical they can do that only costs 1 MP (damage, ally buffs, etc.), and have that practical action as a second catch-all right above your final catch-all (Wait).

In my game Skill 2 is End Turn, which makes the user unable to act, virtually until the battle ends. Once everybody still alive in the fight is under this state, everybody's MP is recharged and the state is removed. As a result, everything besides passive/triggered skills and End Turn cost at least 1 MP (actually called Action Points in my game).
Just want to say that this sounds like a very clever and intriguing way around the default turn system! I could see it being a lot of fun to play, as long as you make a concerted effort to ensure the turns don't drag for too long, and if you want to post more about it in Game Ideas and Prototypes, or show off a demo, I'd love to see it! 😀
Will do! I'll set up how it works in a new project and make a topic about it.

Original thread: https://forums.rpgmakerweb.com/threads/battle-ai-core-priority-issues.121591/