RMMV Yanfly Battle AI Core - Help with a Few Checks

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Hello!

Would someone be able to help me out with setting up a few conditions using Yanfly's Battle AI Core plugin?

The conditions that I am looking to check are:

1. If variable A is equal or greater to variable B
2. Check if target has a certain buff/debuff
3. Check is the target has a skill of a specific element
4. Check if the result of a battle formula is greater of equal to the user's current HP.
5. Check is a certain Enemy ID (or name, either works) is currently alive in the troop
6. Check to see if 2 or more troop members or party members has a certain state

I hope I explained this all well enough. If you're not sure what I mean by something, definitely feel free to ask.

Thank you!
 

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
187
Reaction score
85
First Language
English
Primarily Uses
RMMV
Some of this can be done with just the default plugin. Some, though, you'll need a second plugin for.

To check just game information, use the handy dandy Eval checker. So, if you want the enemy to use Skill 50 only when Variable 1 is greater than Variable 2, this would be the notetag:

Code:
<AI Priority>

Eval $gameVariables.value(1) > $gameVariables.value(2): Skill 50

</AI Priority>
The Eval function can be great if you want to check a lot of weird things, or if you want to check complex functions.

However, you also want to check information on specific targets. The Yanfly Ai plugin has trouble with that by default. I use this addon plugin:


This plugin lets you check information on targets, and only have the enemy use a skill if the target is valid.

So, to only use skill 50 on a target that has State 5, you would use this:


Code:
<AI Priority>

 Eval AIManager.targetCondition("target.isStateAffected(5)"): Skill 50

</AI Priority>
This will have the enemy AI only use the skill on a target with that state on it.

As this is just Javascript now, you can get crazier from here. You could check if a target has a certain name. You can have and/or checks, to only use skills on targets that have multiple conditions.

So, to go through each of your points:

1) Eval $gameVariables.value(VAR_ID) > $gameVariables.value(VAR_ID): Skill SKILL_ID

2) Eval AIManager.targetCondition("target.isBuffAffected(BUFF_ID)"): Skill SKILL_ID

3) This one is complicated. If there's only one skill you're looking for, use

Eval AIManager.targetCondition("target.hasSkill(SKILL_CHECK_ID)"): Skill SKILL_ID

If you want to check for a ton of skills, you'd be best using a outside function, say called hasAnyOfTheseSkills(), with the inside of the function being checking for a lot of skills, then run this AI notetag:

Eval AIManager.targetCondition("target.hasAnyOfTheseSkills()"): Skill SKILL_ID

4) I'm not sure. Sorry.

5) Eval AIManager.targetCondition("(target.enemyId() == ENEMY_ID && target.isStateAffected(DEATH_STATE))"): Skill SKILL_ID

6) I guess you could write an outside function to go into the Eval, the function being a loop that checks every member of $gameTroop, seeing if at least two of the members return true on isStateAffected(STATE_ID). There may be a better way of doing that.
 

Vis_Mage

Novice Magician
Veteran
Joined
Jul 28, 2013
Messages
567
Reaction score
196
First Language
English
Primarily Uses
RMMV
Thank you for all your help! :kaothx:

I do have a couple of questions regarding the solutions, if you don't mind.

Regarding number 5, will this eval work for skills that don't actually target the enemyID that is being checked (and instead, whether that enemyID is still alive just acts as a condition on whether or not the enemy can use that skill)? Also, is there a way to check if multiple of that enemyID is alive?

In the same vein as above, for number 2, is it possible to check for a buff or state, while not necessarily targeting the person with the buff/state?

Also, for number 6, could you go into a little more detail on what you mean by an outside function?
 

TheTitan99

Veteran
Veteran
Joined
Nov 2, 2015
Messages
187
Reaction score
85
First Language
English
Primarily Uses
RMMV
No worries!

As written, #5 will check only that target, and it'll use the skill on that target. So, the way it's written right now, I guess it's really more of use for revive spells. If you want to use the skill when a specific enemy is dead, but have it not target the dead battler, then use this:

Code:
Eval $gameTroop.members()[ENEMY_PLACEMENT_IN_TROOP].isStateAffected(DEATH_STATE): Skill SKILL_ID
That'll check if, say, Enemy 1 in the troop is dead, or Enemy 2, or whatever spot you select. This isn't a dynamic system, it's always checking if that one enemy is dead.

If you want to check if there is any dead enemy, use this:

Code:
Eval $gameTroop.deadMembers().length > 0: Skill SKILL_ID
That'll run when there's at least 1 dead enemy, though it doesn't matter what enemy is dead.

What I mean by outside function is... say, see this enemy AI command:

Code:
Eval twoOrMoreInTroop(STATE_ID): Skill SKILL_ID
The function twoOrMoreInTroop() doesn't exist by default. However, you could write the function in a plugin! I do this all the time for more complex checks, especially in damage formulas.

This is an example of the function, though you can write whatever you want here:

Code:
twoOrMoreInTroop = function(nState) {

    var n = 0;

    for (var i = 0; i < $gameTroop.aliveMembers().length; ++i) {
       if ($gameTroop.aliveMembers()[i].isStateAffected(nState))
         n = n + 1;
    }

    if(n >= 2)
        return true;
    else
        return false;
};
Keep in mind, there are MUCH better ways of writing the above code. I want to make it easier to read, so I'm using some sloppier coding to make it easy to read.

What this function will do is go through all living enemies in the battle, and check if that are under the state nState. You decide what the variable nState is, based on whatever number you put in the enemy AI command.

If at least 2 enemies are under the state, then the function is true, and the AI command will run. Otherwise, the function is false, and the AI command will not run.

By using functions like this, you can make AI evaluations as complex as you want. As long as the function returns either true or false in the end, it can be as convoluted as you want. You could have a function that checks if the combined number of letters in the bio of all living actors is more than 400 words. I... don't know WHY you would want to check that, but by writing a function, you could!
 

Users Who Are Viewing This Thread (Users: 1, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

GOBBLE GOBBLE! Happy thanksgiving.
Oh no. That moment when you try to fix something you modified in your game, like, a year ago but didn't want to fix then, and you now have no idea what you even did. Me right now, trying to figure out why my gold window is over stretched?
LittlePIGGY wrote on atreyoray's profile.
Where are you TT^TT
We need ARP_InGameManual for MZ
Oh my gosh. Thank you, Macy's! Thank you so much! You have made me very happy!

Forum statistics

Threads
105,552
Messages
1,014,573
Members
137,225
Latest member
Eryndor
Top