Yanfly's plugin : Battle AI core

Plugin : http://yanfly.moe/plugins/en/YEP_BattleAICore.js


Hi,


I'm trying to code : when party level is superior to level 5, the enemy cast : Sleep.


I know there is already a default feature for that but it never worked for me so I'm trying to do it with Yanfly plugin


<AI Priority>


Average Party Level > 5: Sleep,


State !== State 10: Sleep, Random


</AI Priority>


The problem is that the code ignore the first line and read only the second.


@Riff kindly tried to help me (in Yanfly original thread since I didn't know by then if it was a bug or not) but it isn't working, unfortunaly.


First solution :


<AI Priority>


((Average Party Level > 5) && State !== State 10): Sleep, Random


</AI Priority>


01.png.c37eb5e606825cec0468f238a6534d3a.png



Second solution :


<AI Priority>


Eval (($gameParty.averageLevel() > 5) && (!target.isStateAffected(10)): Sleep, Random


</AI Priority>


02.png
For some weird reason, Yanfly don't let people have more than 1 condition in their AI 🙂
I have used multiple conditions using Eval. Like having HP range (two conditions, lower than and higher than a number). Help, anyone?


- Riff
Weird, l read it like a week ago as an official response in the AI plugin comments.


I'll have to find it again I guess.


5c7c3b48a0.png



Since it's been a while since the comment has been written, i've been checking patch notes incase he changed it, seems like it's not the case.


 * Version 1.05:


 * - Updated for RPG Maker MV version 1.1.0.


 *


 * Version 1.04a:


 * - Fixed a bug that would cause a crash with the None scope for skills.


 * - Switched over a function to operate in another for better optimization.


 *


 * Version 1.03:


 * - Fixed a bug that returned the wrong MP% rate.


 *


 * Version 1.02:


 * - Fixed a bug that targeted the highest parameter enemy instead of lowest.


 *


 * Version 1.01:


 * - Added 'MaxTP' and 'TP' to targets.


 * - Compatibility update with Battle Engine Core v1.19+. Turn settings are now


 * based 'AI Self Turns' if the enabled.


 *


 * Version 1.00:


 * - Finished Plugin!
Thanks for finding this, that's too bad then...


Edit :


@Riff


I think you were right because Yanfly replied this in her thread : "You need a () with the  $gameParty.averageLevel"
Thanks for finding this, that's too bad then...

I'm on the point of commissioning this since that alone makes the AI very restricted.
Edit : sorry for double post
Just notice that this code is wrong, it's missing a parenthesys:


Eval (($gameParty.averageLevel() > 5) && (!target.isStateAffected(10)): Sleep, Random
look at the maching colors and you will see that the ( is missing it's closing. and in fact,
Anyway all those parenthesys are unnecessary. you just need the ones for the functions.


This should work  if it wors as a normal eval:


Eval ($gameParty.averageLevel() > 5 && !target.isStateAffected(10)): Sleep, Random
@Victor Sant Woot, thank you Victor!


But I've a little problem, while the first condition is respected the second seems not.


The second condittion is for the enemy to not recast the sleep spell when an actor is affected by it.


I made sure while testing that the enemy only use "Attack", so I removed the Sleep but the result was the same.


Eval ($gameParty.averageLevel() > 5 && !target.isStateAffected(10)): Attack


But thank you again, it doesn't crash anymore 😀


Edit : I spoke too quickly, I got that error after closing Rpg maker Mv and opening it


When I try to test battle in Troops


03.png


04.png


I also tried it in another project...
There is no "target" variable at that time because it's deciding what skill to use, not which target to use it on (yet). "State !== x" is a special condition that restricts the targeting pool to targets that lack that state; using eval means you can't restrict the targeting pool.


What you could do instead (assuming you don't want to rewrite the script to make multiple conditions possible) is do something like this:


<AI Priority>


Average Party Level <= 5: Attack


State !== State 10: Sleep


</AI Priority>


Assuming the AI level is set not to allow any randomness, this would make it only cast sleep if the party's average level is > 5 and there's a party member unaffected by state 10.
@MageKing17


Tried it with a party of lvl 1 and the enemy casted sleep while it should only do it on a party of lvl 5+ 🙁
Was wondering if there was a way to condition the following. I want an enemy to see which targets (the party) is affected by state x. If they are not affected by state x then I can choose another condition to target them. If they are affected by state x then I cannot target them unless I have skill y, which I can then choose to use skill y.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-plugin-battle-ai-core.58813/