Help with Turn Count Based Attack Patterns

I'm trying to figure out how to give a boss a set attack pattern, where they always use a certain skill based on the turn count. For example, let's say turn 1 and 2 they use "Skill A" then on turn 3, "Skill B", then turn 4 and 5 "Skill A" again, then turn 6 "Skill B" and so on. I feel like this should be really simple, but I'm clueless. The best I can do is get an enemy to alternate back and forth each turn. The example I gave is only two skills, but ideally, I would like to be able to coordinate like.. 7 different skills on a set pattern.

I have Yanfly's "Battle AI Core", but I can't figure out turn count with that plugin either. It would be nice to know how to handle this with Yanfly's Battle AI Core as well for the sake of the flexibility that plugin offers.

EDIT: Well, I learned that the skill "rating" is not always random like I initially assumed. Apparently, if a skill's rating is more than 3 points lower than another one, it will never be selected when they both have their conditions met. This was useful to know, and can accomplish what I wanted in the first example:

ex1.png

But, that said, I also discovered that setting a pattern really is very simple, and I'm just stupid.

ex2.png

That's it. That's all you gotta do, and somehow I struggled to figure this out for the past 2 hours. It's just... The turn you want them to use it, + the number of total moves in the pattern. (*X) Done.
good!

btw, the way battle ai core works with turns would be like this:

Code:
Turn > 2: Skill 34, User

so, making priorities, youd go in the reverse order, like this
Code:
Turn > 10: Skill 12, User 
Turn > 5: Skill 21, User 
Turn > 2: Skill 34, User

and/or mixing other conditions, like this:
Code:
Eval user.isStateAffected(36) +++ Turn > 10: Skill 12, User 
Eval user.isStateAffected(37) +++ Turn > 10: Skill 12, User
Eval user.isStateAffected(12) +++ Turn > 5: Skill 21, User
Eval user.isStateAffected(32) +++ Turn > 5: Skill 21, User
good!

btw, the way battle ai core works with turns would be like this:

Code:
Turn > 2: Skill 34, User

so, making priorities, youd go in the reverse order, like this
Code:
Turn > 10: Skill 12, User
Turn > 5: Skill 21, User
Turn > 2: Skill 34, User
This works. Just to add to it, if you're trying to do a cycling pattern and you don't want to type out, like, 50 rounds of stuff just in case the fight takes that long, the modulo operator % can be your friend. Modulo says "what is the remainder of this number divided by this number?"

This works very easily for an alternating pattern, you'd do
Code:
Turn %2==0: skill on even turns
Always: skill on odd turns

Because of you having a weird number of turns in your cycle, I'd actually suggest just putting a variable onto your enemy. Make a Turn 0 troop event, enter a Script command that says:
Code:
$gameTroop.members()[0].skillCounter=1;

That's good if that's the only enemy in your troop, or if it's the first one you put into the troop; otherwise, you'll have to count up from [0] to reference the correct enemy.

Then, in its AI conditions, you'd do:
Code:
Eval user.skillCount==3: skill on turn three, etc.
Eval user.skillCount == 2: skill on turn two, etc.
Always: skill on turn 1, etc.
filling it up to turn 7.

Finally, make a Turn End troop event that has the Script command:
Code:
$gameTroop.members()[0].skillCounter+=($gameTroop.members()[0].skillCounter==7 ? -6 : 1)

So it's a little more setup with the two troop events, but then you don't need to type any duplicate material in your A.I. conditions.
Thank you both! I really appreciate the info! This will definitely help me out in the long run.
This works. Just to add to it, if you're trying to do a cycling pattern and you don't want to type out, like, 50 rounds of stuff just in case the fight takes that long, the modulo operator % can be your friend. Modulo says "what is the remainder of this number divided by this number?"

This works very easily for an alternating pattern, you'd do
Code:
Turn %2==0: skill on even turns
Always: skill on odd turns

Because of you having a weird number of turns in your cycle, I'd actually suggest just putting a variable onto your enemy. Make a Turn 0 troop event, enter a Script command that says:
Code:
$gameTroop.members()[0].skillCounter=1;

That's good if that's the only enemy in your troop, or if it's the first one you put into the troop; otherwise, you'll have to count up from [0] to reference the correct enemy.

Then, in its AI conditions, you'd do:
Code:
Eval user.skillCount==3: skill on turn three, etc.
Eval user.skillCount == 2: skill on turn two, etc.
Always: skill on turn 1, etc.
filling it up to turn 7.

Finally, make a Turn End troop event that has the Script command:
Code:
$gameTroop.members()[0].skillCounter+=($gameTroop.members()[0].skillCounter==7 ? -6 : 1)

So it's a little more setup with the two troop events, but then you don't need to type any duplicate material in your A.I. conditions.
I would really like to use this code for a specific case. One where I intend to have an enemy appear part way into the fight. I assume that using a variable would allow the script to begin counting when the enemy appears (if I insert it at that time.) rather than counting from the start of the fight.

For the purpose of time saving, I'm just testing from turn one right now, but I can't seem to get this to work. The enemy will use the "always" skill, but not the other two. I've tried typing it out in a few different ways. Of course, I am very new to this.

ex1.pngex2.pngex3.png

What am I doing wrong here?
What am I doing wrong here?
Are you sure the enemy is member 0 of the troop? That's the first enemy you added to the troop. If not, you'll need to change the number inside the brackets accordingly.

You can check during battle by pressing F8, going to the Console tab, and pasting in:
Code:
$gameTroop.members()[0].name
and making sure it shows the name of the enemy you're looking for.

You can also check that the variable is getting initialized and incrementing by checking it directly:
Code:
$gameTroop.members()[0].skillCounter

Lastly, you don't want the span to be Battle on your Turn End event, because running only once per battle will bring the counter to 2 and never touch it again; you want a span of Turn. But it should still take it to 2 so that your skill on turn 2 should trigger.
Also note that in your event you set a variable called skillCounter, while in the AI Priority you eval a variable called skillCount. This is not the same.
Also note that in your event you set a variable called skillCounter, while in the AI Priority you eval a variable called skillCount. This is not the same.
This is it! This was the problem. I had just copy and pasted what ATT_Turan had wrote.

Lastly, you don't want the span to be Battle on your Turn End event, because running only once per battle will bring the counter to 2 and never touch it again; you want a span of Turn. But it should still take it to 2 so that your skill on turn 2 should trigger.
This was also very helpful. Thank you both, this thread has helped me a ton.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-turn-count-based-attack-patterns.150697/