MV Yanfly Ai/Row Formation-Enemy use skill against other enemy in same row

Hello, I want to make an enemy tank that can protect their allies on the same row as them. I want the enemy tank to specifically target 1 enemy (not itself) on the same row as them that has the least amount of health.


--------------Concept for better understanding (I know this doesn't work but this is what I mean)--------------

Condition: If alive in troop row 1 is greater than 1 AND If SkillUser row = 1, then use skill "Protect" on a Troop Member on the same row as SkillUser with the lowest HP excluding the SkillUser

Then I would repeat that for each of the 4 rows, but I don't know how to do it. I run into the issue of the conditions I set in the AI battler notes of an enemy checking the target when I want it to check if the user of the skill and the target are in the same row.
-----------------------------------------------------------------------------------------------------------------


Action order of tank enemy (example of what I want to happen)
Turn 1
-Starts in row 4, decides to use a skill to move forward to row 3 because it's melee only (note: I set melee attacks to only be used when in row 1 and 2 'aka the front rows')
Turn 2
-Realizes it's in a row where there is another enemy, so instead of moving forward again to row 2, there is a chance that it instead uses a skill to protect the weakest enemy on it's row by applying a buffing state to it, named "protected" or something similar
Turn 3
-Instead of protecting the enemy again, it instead via chance uses the skill to move forward to row 2 which has another enemy already in that row.
Turn 4
-Realizes it's in a row where there is another enemy, but instead of moving forward to row 1 or protecting the enemy on the same row 2, via a slim chance, it decides to attack using it's melee ability
Turn 5
-Realizes it's in a row where there is another enemy, so it decides to use the protect skill instead of moving forward or attacking, but there are two other enemies other than itself, so it picks the enemy with the lowest amount of health to keep it alive

Extra
Every time I say by chance, I mean the Random % condition in Yanfly's AI Battler which I like

Example of random condition from another enemy I have, So even though it can meet the conditions, that enemy might just not wanna do that skill:
Troop Alive Members > 2 +++ State !== State 53 +++ Random 20%: Skill 111
I believe you'd need to use Selection Control in addition to the Battle A.I. to do this.

The eval condition for the skill is pretty simple, pulling from the Row Formation instructions:
Code:
eval $gameTroop.rowSize(1)>1
then you just do the skill on Lowest HP%.

In order to make the actual targeting group be allies in the front row that aren't the user, you'd need to use Selection Control.

Give the skill the notetag:
Code:
<Select Conditions>
Front Row Only
Not User
</Select Conditions>
Oh ok, I don't have much experience with selection control yet,

Where would I put the "eval $gameTroop.rowSize(1)>1"?

Would the note tags of the skill look like this?:

<Custom Select Condition>
if $gameTroop.rowSize(1)>1 {
condition = true;
} else {
condition = false;
}
</Custom Select Condition>

<Select Conditions>
Front Row Only
Not User
</Select Conditions>

Or would it be something else?

Also, I'm trying to make the tank enemy only target it's allies in the same row as it
I believe you'd need to use Selection Control in addition to the Battle A.I. to do this.

The eval condition for the skill is pretty simple, pulling from the Row Formation instructions:
Code:
eval $gameTroop.rowSize(1)>1
then you just do the skill on Lowest HP%.

In order to make the actual targeting group be allies in the front row that aren't the user, you'd need to use Selection Control.

Give the skill the notetag:
Code:
<Select Conditions>
Front Row Only
Not User
</Select Conditions>
Where would I put the "eval $gameTroop.rowSize(1)>1"?
The eval condition for the skill

Would the note tags of the skill look like this?:
Give the skill the notetag:

I'm not sure why you would try to give a skill both regular select conditions and a custom selection condition. Not only won't it work, but it seems pointless - don't the two conditions I already gave you do exactly what you want? Target an ally in the front row that isn't the user.

That can only logically happen if there is more than one enemy in the front row, so I don't know why you'd need to check for that separately.
I'm not sure why you would try to give a skill both regular select conditions and a custom selection condition. Not only won't it work, but it seems pointless - don't the two conditions I already gave you do exactly what you want? Target an ally in the front row that isn't the user.

That can only logically happen if there is more than one enemy in the front row, so I don't know why you'd need to check for that separately.

Ok, I see what you mean, so I'll go with Front Row Only and Not User select conditions only. The only issue I have is I want the Tank enemy to only protect enemies on the same row as it. There are 4 rows total. So if the tank enemy is on row 3, I want that protect skill it uses to only target it's allies on row 3. Or if it moves forward to row 2, it can only use that protect skill on the enemies also on row 2.

I was thinking 4 instances of the protect spell where I have the select conditions like this:

Version of protect spell for row 1
<Select Conditions>
Row 1 Only
Not User
</Select Conditions>

Version of protect spell for row 2
<Select Conditions>
Row 2 Only
Not User
</Select Conditions>

And so on for row 3 and 4, but I don't know how to limit the tank enemies targets to only enemies in the same row as the row that tank enemy is currently in.

For the eval, i have no clue where the 'eval condition for the skill' is. It might be that I'm just unfamiliar with the terms and layout, but is it the note section, or effects section of a skill?
I didn't understand your "tank" could be not in the front row. You did say "in the same row as them," but then your example condition explicitly said row 1 so I thought that was what you wanted.

In that case, change the selection notetag to the following:
Code:
<Custom Select Condition>
return target.row() == user.row() && target!=user;
</Custom Select Condition>

For the eval, i have no clue where the 'eval condition for the skill' is. It might be that I'm just unfamiliar with the terms and layout, but is it the note section, or effects section of a skill?
Sorry - you gave an example in your first post of a condition from Yanfly's Battle A.I. Core, so I assumed you knew how to add conditions to an enemy.

Please read the instructions for that plugin to see how it works.
I didn't understand your "tank" could be not in the front row. You did say "in the same row as them," but then your example condition explicitly said row 1 so I thought that was what you wanted.

In that case, change the selection notetag to the following:
Code:
<Custom Select Condition>
return target.row() == user.row() && target!=user;
</Custom Select Condition>


Sorry - you gave an example in your first post of a condition from Yanfly's Battle A.I. Core, so I assumed you knew how to add conditions to an enemy.

Please read the instructions for that plugin to see how it works.
Oh I see what you mean, like the conditions for a move to be used in the <AI Priority> notetag?
like this eval?: Troop Alive Members === $gameVariables.value(3): Skill 12, Random

In image one, I put the new custom select notetag in the skill's notes. In image 2, I set the tank enemy to always use it when it can. And in image 3, it's using the skill on an enemy in row 2 when it's in row 1 which is an issue. Did I set it up wrong?

Even when I give the protect skill to my characters, they can target enemies and allies with it like it had no select conditions or any conditions.
Do you have the Target Core and Selection Control plugins installed and in the correct order?

And you're saving your project and starting a new game to test, not loading a save?
I'm pretty sure I have them in the correct order, image 4 is the first half, and image 5 is the other half.
I was initially doing the testing in the Battle Test in the Troops tab. I just tried saving and loading a new game but it still targets its allies on different rows. Something to note is that it does prioritize the enemies with the least health so at least the scope works for <AI Priority>
I used the wrong syntax - there's no return, it should set the condition variable.

Code:
<Custom Select Condition>
condition = target.row() == user.row() && target!=user;
</Custom Select Condition>
-Ignore this-
I used the wrong syntax - there's no return, it should set the condition variable.

Code:
<Custom Select Condition>
condition = target.row() == user.row() && target!=user;
</Custom Select Condition>
Ok that works, one last thing for this tank enemy that I can't figure out.

<AI Priority>

//While in row 4 (state 39), move forward (skill 91)

State === State 39: Skill 91


//While in row 3 (state 38), move forward

State === State 38: Skill 91


//While in row 2 (state 37), move forward if nobody else in row 2

State === State 37 +++ $gameTroop.rowSize(2)==1: Skill 91


//High chance to protect (Skill 114) weakest enemy on same row who isn't already protected (State 58)

State !== State 58 +++ Random 65%: Skill 114, Lowest HP

</AI Priority>

Biggest issue is "$gameTroop.rowSize(2)==1", I don't know the proper way to use this, but I know it doesn't work. Does this need to go in a skill's notetags and what does that look like?
You can't just type code, you need to use the eval condition.
You can't just type code, you need to use the eval condition.
Oh ok I fixed it. I never used eval in my ai priority notetags before so I wasn't sure what it would look like. I was able to fix it, thank you for the help!
You can't just type code, you need to use the eval condition.
Okay I thought everything was working, but something isn't right. The tank enemy I keep referring to is called "Rook Goblin" and it doesn't act according to the conditions I set in the AI Priority notetags.

Information:

Rook Goblin notetags:


<Breathing>
<Show HP Gauge>
<Scale Sprite: 50%>
<AI Level: 100>
<Default Row: 1, 2, 3, 4>

<AI Priority>

//While in row 4 (state 39), move forward (skill 91)
State === State 39: Skill 91

//While in row 3 (state 38), move forward
State === State 38: Skill 91

//While in row 2 (state 37), move forward if nobody else in row 2
State === State 37 +++ eval $gameTroop.rowSize(2)<2: Skill 91

//High chance to protect (Skill 114) weakest enemy on same row who isn't already protected (State 58)
State !== State 58 +++ Random 65%: Skill 114, Lowest HP

//Shield Bash in front row (state 36) to do some dmg
State === State 36: Skill 115, Random

</AI Priority>

Grunt Goblin notetags:
<Breathing>
<Show HP Gauge>
<Scale Sprite: 45%>
<AI Level: 80>
<Default Row: 1, 2, 3, 4>

<AI Priority>

State === State 37 +++ Random 50%: Skill 91
State === State 38: Skill 91
State === State 39: Skill 91
Always: Scratch, Random
State === State 38: Skill 91
State === State 39: Skill 91

</AI Priority>

Deadshot Goblin notetags:
<Breathing>
<Show HP Gauge>
<Scale Sprite: 50%>
<AI Level: 90>
<Default Row: 1, 2, 3, 4>

<AI Priority>

State === State 36: Skill 93
State === State 37: Skill 93
Troop Alive Members > 2 +++ State !== State 47 +++ Random 50%: Skill 94
Troop Alive Members > 1 +++ State !== State 47 +++ Random 30%: Skill 94
Always: Arrow Shot, Random
State === State 36: Skill 93
State === State 37: Skill 93

</AI Priority>



Turn by turn examples:

Fighting the "Rook Goblin" alone:

Turn 1
-It starts in Row 3
-I used physical melee (my normal) successfully
-It moves up to Row 2

Turn 2
-I used physical melee (my normal) successfully
-It moves up to Row 1

Turn 3
-I used physical melee (my normal) successfully
-It procceeds to take no actions for the rest of the battle while in row 1


Fighting the "Rook Goblin" with a "Grunt Goblin" (The grunt just moves up and attacks pretty much)
Turn 1
-Both start in row 2
-Grunt basic attacks me and Rook Goblin did nothing which is fine because the protection is 65% chance
-I used physical melee (my normal) successfully against the grunt

Turn 2
-Grunt basic attacks me and Rook Goblin protects the grunt goblin
-I used physical melee (my normal) successfully against the grunt

Turn 3
-I used physical melee (my normal) successfully against the grunt and killed it
-Rook Goblin did nothing after the grunt goblin died, I think it should have moved up with the eval condition I have

Turn 4
-The "Rook Goblin" procceeds to take no actions for the rest of the battle while in row "2" this time
-I keep basic attacking until it's dead


Fighting the "Rook Goblin" with 2 "Grunt Goblins"
Turn 1
- "Rook Goblin" starts in row 3, grunt goblin 1 started in row 4 and grunt goblin 2 started in row 2
-I used physical melee (my normal) successfully against the grunt goblin 2
-Grunt goblin 1 moved up to row 3 and the "Rook Goblin" moved up to row 2

Turn 2
-I used physical melee (my normal) successfully against the grunt goblin 2
-Grunt goblin 1 moved up to row 2 and Grunt goblin 2 moved up to row 1, Rook goblin protects one of the grunts

Turn 3
I kill grunt goblin 2, grunt goblin 1 moves up to row 1, and rook goblin stays in row 2 taking no action

Turn 4
-I used physical melee (my normal) successfully against the grunt goblin 1
-Grunt goblin 1 attacks and "Rook goblin" moves up to row 1

Turn 5
-Rook Goblin protects grunt goblin 1, but it's not enough because I still killed it (it was really low anyways)

Turn 6
-While alone, "Rook Goblin" procceeds to take no actions for the rest of the battle while in row 1


Fighting the "Rook Goblin" with 1 "Grunt Goblin" and 1 "Deadshot Goblin" (Deadshot is just an archer goblin that moves to the back rows):
Turn 1
- "Rook Goblin starts in row 2, grunt starts in row 3, and deadshot starts in row 3
-I used physical melee (my normal) successfully against the Rook Goblin
-Rook Doesn't do anything, the grunt moves to row 2, the deadshot shoots me with an arrow

-Turn 2-4
-I switch my targeting to the grunt goblin in row 2, and kept attacking it while the Rook goblin kept protecting it which is good, i eventually killed the grunt goblin
-Rook Goblin took no action during the turn I killed the grunt goblin and the archer goblin kept shooting me like normal

Turn 5-10
-The "Rook Goblin" procceeds to take no actions for the rest of the battle while in row "2" and the archer goblin in row 3 is still alive
-I kept attacking the Rook Goblin until I killed it, then killed the archer

--------------------------------------------------------------------------------------

It's like it gets stuck or bugged, the rook goblin never uses it's shield bash and when not fighting alone, doesn't seem to want to move to row 1

I'll put images of the skills the Rook Goblin uses

Sometimes, the rook goblin becomes untargetable, like I can't select to attack it with my normal attack but I wasn't able to recreate it reliably. And sometimes when I could target it, it would skip my turn, but again, I wasn't able to recreate that during the above tests

Let me know if more information is required to figure out what's happening and I'll provide as much as I can!
I dunno. I've seen seen one other person report issues with Battle A.I. using skills with Selection Control and it bugged the next player skill's selection.

In that thread, the poster was using out of date versions of the Yanfly plugins and never finished the discussion about buying the final versions to try those.

Assuming your plugins and MV are all the most recent versions, I don't know.

I do see from the logic of your A.I. that there are turns the Rook Goblin may be unable to do anything.

I don't see why it would be completely unable to use Shield Bash. If you press F8 and go to the Console, are there any errors? If you take the targeting notetags out of Shield Bash, is there any difference? You're already telling the enemy via Battle A.I. conditions that it can only use it from the front row.
I dunno. I've seen seen one other person report issues with Battle A.I. using skills with Selection Control and it bugged the next player skill's selection.

In that thread, the poster was using out of date versions of the Yanfly plugins and never finished the discussion about buying the final versions to try those.

Assuming your plugins and MV are all the most recent versions, I don't know.

I do see from the logic of your A.I. that there are turns the Rook Goblin may be unable to do anything.

I don't see why it would be completely unable to use Shield Bash. If you press F8 and go to the Console, are there any errors? If you take the targeting notetags out of Shield Bash, is there any difference? You're already telling the enemy via Battle A.I. conditions that it can only use it from the front row.
I'm checking my Yanfly plugins and it seems that they are up to date (Most of the battle core and other core plugins' most recent versions where in 2020). I ran through an entire battle with the F8 developer tools open and the console tab only showed me the user message "PixiJS 4.5.4 - ✰ WebGL ✰ http://www.pixijs.com/", but no actual errors.

Something I noticed is that the Rook Goblin only gets stuck on Row 2 and doesn't move to Row 1 when another enemy dies on Row 2. When I kill enemies that are on other rows that aren't 2, the Rook Goblin has no issue moving to Row 1. Maybe the condition has to be Alive Row Members on Row 2 instead of eval $gameTroop.rowSize(2)<2. Maybe the enemies I kill on row 2 count for the row size even when they're dead and that's why the Rook Goblin gets stuck on Row 2 when I kill enemies in Row 2 but moves freely when I kill enemies not on row 2.

I removed <Row Only: 1, 2> from Shield Bash, but it doesn't change anything when I test it. If I replace the Shield Bash condition in AI Priority notetag with this "Always: Skill 115, Random", It does attack when in both Row 1 and 2 (I added the Row Only notetag back to the skill). But it still doesn't move up to Row 1 which should take priority over Shield bash.
Yes, use rowAliveSize()
Yes, use rowAliveSize()
That worked, thank you!

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-ai-row-formation-enemy-use-skill-against-other-enemy-in-same-row.162182/