Yanfly Battle AI Core - Questions

I've been using the titular plugin for my battle AI. For the most part it accomplishes what I want it to do, but there's a few things I'm not quite sure how to do with it.

The first thing that seems to be lacking is checking for buffs and debuffs. Checking the user's own buffs is relatively simple (Eval user._buffs[insertParamIDhere]), but there doesn't seem to be a way to check for the target's buffs and debuffs. I did try using this extension, but it didn't seem to work for me (the AI didn't seem to recognize the conditions as a valid and just passed over it, no matter how strict I made it) and furthermore I'm not sure if it'd work with the base plugin's multiple conditions. So I'm wondering if there's something I can plug into Eval that does the job, or failing that if there's another plugin that's better at handling it.

The second question is doing loops (e.g. on turn 1 do this, on turn 2 do another thing, on turn 3 do something else, and then go back to the first action; repeat until otherwise stated). The best idea I've come up with on my own is making a variable, increasing it by one, and then resetting it to restart the loop, but that seems rather clunky.
I find it weird my extension didn't work for you. I checked again, and it seemed to work perfectly.
Mind showing me what you tried that didn't work so I can try replicating it or tell you what you did wrong?

As for your second question, using battle AI and the modulus operator you should achieve what you want.

Also: I sneakily updated my plugin, because I added a target eval notetag a while ago, and didn't make it public. It's undocumented, but it works.
Ex:
Code:
<AI Priority>
Targeteval (target._actorId === 2): Skill 1
</AI Priority>
Here's the enemy I tested it out on:
Spoiler: Enemy
qm5rjMc.png

For whatever reason, the first condition is always ignored. The enemy just uses Skill 1 (the normal attack) no matter how many attack buffs the player has. Omniboost is Skill 103, for the record.

Could you elaborate on what you mean by "modulus operator?" My mind went to doing something like this:

If turn % 3 = 0: Skill 3
If turn % 2 = 0: Skill 2
If turn % 1 = 0: Skill 1

In that case, it seems like it'd go Skill 1, 2, 3 for the first three turns. Then on turn 4 it'd use Skill 2; on turn 5, Skill 1; on turn 6, Skill 3.... I'm trying to accomplish something along the lines of Skill 1, 2, 3, repeat.


Managed to figure it out on my own. For anyone who might be having the same issue and is reading this topic, what I did was this:

Eval $gameTroop._turnCount % 3 === 0: Skill 1
Eval $gameTroop._turnCount % 3 === 1: Skill 2
Eval $gameTroop._turnCount % 3 === 2: Skill 3

Essentially, 1 divided by anything will give a remainder of 1 (except for itself, obviously). Same goes for 2, 3, etc. So a remainder of 1 would be the first turn, a remainder of 2 would be the second turn, and so on, while a remainder of 0 would be the last skill in the loop. After that, it'd repeat until the end of the battle or until otherwise stated. I don't know if the plugin's default Turn condition would work with modulation, so that's why I did an eval.

However, I still have one last question as far as loops go. Most bosses in my game change attack patterns upon hitting certain HP values. How do I make it so that the new loop begins on the turn the pattern changes, since that's not probably going to happen on the same turn in every battle?
Why the "condition:" in your notetag?
It shouldn't be there. Or has there be an update on Battle AI core I didn't catch?

Anyway, your notetag should be:
Code:
Buff >0 Buff 2: Skill 103
Always: Skill 1

And then it should work as advertised.

As for your second question, I'd use a compound condition: modulus operator and hp% parameter.
The "condition" was there because I misread the help file and thought that had to be there in order for the notetags to work properly (and it seemed to work fine with it for the default conditions). With that misconception cleared up, I've tried it again and it now works just fine. That's one issue down.

As for the second problem: What I ultimately wound up doing was setting up a couple of troop events. The first event, set to trigger at whatever HP value I wanted, sets a switch and initializes another variable. Then the second troop event adds one to the variable each turn (the condition is set to Switch on only and is set to be checked every turn; as far as I can tell, this makes the variable increment at the start of the turn). In the notetags, I put something along these lines:

Eval $gameVariables.value(variableID) % 3 === 1: Skill 1
Eval $gameVariables.value(variableID) % 3 === 2: Skill 2
Eval $gameVariables.value(variableID) % 3 === 0: Skill 3

Since the variable appears to increment at the start of the turn (and thus starts off at 1 rather than 0), a remainder of 1 marks the first turn in the pattern while a remainder of 0 is the last turn in the pattern. If I want to change the pattern at another point in the fight, I'd make another troop event setting a new switch and resetting the variable before making another set of notetags. I again used an Eval as I doubt the default Variable condition works with modulation.

I've noticed some issues with skills that cost TP both with this method and the purely turn-based one before. For the first enemy I tried, it seemed to forget it had the TP skill when it seemingly ran out of TP and never used it again regardless of future TP gain. Beyond that, I'm not sure how efficient this method is, but it seems to work all right.

The final question I can think of for the time being involves randomness. For certain enemies, I'd like there to be a chance for it to use a different move for any given turn in a loop (like, for turn 1 there's a 50% chance it'll use Skill 1 and a 50% chance it'll use Skill 2; sort of like this).

I think I could accomplish this with a simple Random in the case of two skills, like so:

Random 50%: Skill 1
Always: Skill 2

Where if the first skill didn't get the random roll it'd be guaranteed to use the second skill. But if I'd like there to be three or more skills, I don't think making two Random commands like this:

Random 50%: Skill 1
Random 50%: Skill 2
Always: Skill 3

Would give me an equal probability for all three skills, if my (admittedly rather scant) knowledge of probability is correct. So I'm wondering if there's a more efficient way of going about this than just the Random command.

Thanks for your help so far!
That wouldn't work. Just go through it one line at a time.
There's a 50% chance for skill 1. -Out of 1 roll, 1 must succeed -> 50% (1/2)
25% For skill 2. 1/4 chance. Out of two rolls, result must be Fail - Succeed. (2 x 50% roll) (1/2 * 1/2)
25% For skill 3. 1/4 chance. Out of two rolls, result must be Fail - Fail. (2 x 50% Roll) (1/2 * 1/2)

It should be 33%, then 50%.
Let's run through it, probability goal is 33% for each option:
33% Skill 1. Out of 1 roll, result must be success (33%). (1/3)
50% Skill 2. Out of 2 rolls, result must be success, success (33%, 50%) (2/3 * 1/2)
Always skill 3. Out of 2 rolls, results must be success, fail (33%, 50%). (2/3 * 1/2)
You can see there's an equal probability of outcomes 2 and 3 which means that they'll be executed 33% of the time each because the first roll has a 66% chance to fail.

If this doesn't convince you, roll a variable between 1 and 3 each turn and use the result as a condition instead.
By the looks of things, it's fraction multiplication. Just to make sure I'm understanding things correctly:

Say I wanted a 50% chance of Skill 1, a 30% chance of Skill 2, and a 20% chance of Skill 3.

If Skill 1 is set to Random 50%, that would mean it has 1/2 chance of succeeding.
A 30% chance is 3/10 in terms of fractions (I think). So to get the percentage I need for Random, I'd find some fraction that, multiplied by 1/2, would give me 3/10.
1/2x = 3/10.
x = 3/10 * 2/1
x = 6/10 = 60/100 = 60%

So if this line of thinking is correct, I'd need to put:
Random 50%: Skill 1
Random 60%: Skill 2
Always: Skill 3

Is this correct, or am I still not getting it?
Yep, again go trough it one line at a time, just like the computer would.

Roll 1 50%, result must be success. (1/2)
Skill 2: goal is 30% of total times, out of two rolls result must be sucess sucess.
(1/2) * x = 3/10
<=> 3x = 1/5
<=> x = 3/5
So:
Random 60% Skill 2.

Skill 3:
1/2 * 2/5 = 2/10
20% chance.

That should indeed get you the desired result.
Alrighty. After doing a few more problems, I think I understand perfectly.

That's all the major questions I have for the time being. Thank you very much for your help!

That being said, I do have one last question: How does the plugin detect "Appear Halfway" enemies? Does that need an Eval, or is that something "Troop Alive/Dead Members" can read?

I've been using an alternative method (have the "Appear Halfway" enemies get summoned once via a switch, then just have the boss revive the enemies afterwards as needed. I think it works better from a story perspective as well, given the circumstances of the fight), so I'm more curious about this one than anything.
Hi I am using Yanfly's sample project and I try to have a fairy cast First Aid, so I copy the code found in yanfly's medic which is this
<AI Priority>
HP% Param <= 75%: First Aid, Lowest HP%
Always: Attack, Lowest HP%
</AI Priority>

and it only works with his medic ennemy, not with a new ennemy of my own, any ideas on what simple mistake I might be doing?

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-battle-ai-core-questions.82359/