MZ Enemies smart enough to ATB Interrupt? How do.

I would love a clean way to get enemy AI smart enough to use an ATB interrupting skill on an a player actor that is mid-cast.

I have been wracking my brain trying to crack this, and all I can come up with is to rewrite each skill with a cast time as an action sequence, and put a state? on the actor? And use vizu Battle AI plugin to focus on actors with that state? idk sounds janky.

Any help would be appreciated.
I have moved this thread from RPG Maker MZ Tutorials to RPG Maker MZ Support.
I'm guessing you're using VisuStella's ATB system plugin. Am I right?

I had a quick look at VisuStella's Battle AI plugin and it looks like it accepts JS for conditions. Assuming the ATB plugin simply extends the existing TPB system, "is target casting right now" would be:
JavaScript:
target._tpbState === "casting"
I don't know if target is the correct variable to refer to the target in the AI condition, I haven't tested.
I'm guessing you're using VisuStella's ATB system plugin. Am I right?

I had a quick look at VisuStella's Battle AI plugin and it looks like it accepts JS for conditions. Assuming the ATB plugin simply extends the existing TPB system, "is target casting right now" would be:
JavaScript:
target._tpbState === "casting"
I don't know if target is the correct variable to refer to the target in the AI condition, I haven't tested.
Yes, i am, and as far as I can tell, the plugin does just expand on the base TPB system.

I think my next mistake was not giving the ATB Interrupt skill higher priority than the normal attack.

EDIT: thank you for your response (☆-v-)

So here is the log for a combat encounter, whenever that enemy's turn starts, it throws all these errors:
Untitled.png


I was at my limit for JS scripting when i started this nonsense, now I'm completely out of my depth. I hope this is enough to troubleshoot?
(target._tpbState here means "read the value of _tpbState defined on target". But the error says it can't read _tpbState of undefined, i.e. target is not defined.)

Basically, as I suspected, target is not the correct variable to use here. I assume there is such a variable, but I don't know what it might be named.

Maybe someone familiar with the plugin will have a suggestion. Alternatively you could try contacting VisuStella via the "Need Help?" links on their itch page. 👋

I've moved this thread to Plugin Support (from MZ Support). Thank you.

yeah, i tried "actor" as well, with no luck. i also looked at rmmz_managers.js, to see what kind of variables it might use, and it looks like it uses something called _ActionState, so i tried that in place of _tpbState and that wasnt it either.

thanks a bunch for your help
[EDIT:
Hmmm, seems like it's just programmed in a "confusing" way. Like it only accepts some kind of expressions or something. I think I got it to work by using:
($gameActors.actor(1)._tpbState === "casting") === true
I'll check if it accepts it somehow like this using the "target" thing...]


I'll bump this, since it's only a month old and I have the exact same question.

Even if we ignore the target or whatever would be the correct variable, what does it mean when it also says that "Reference error: casting is not defined"?
I tested it with:
$gameActors.actor(1)._tpbState === "casting"
but even that gives the same error (or when the actor is in the charging phase, it starts saying "charging is not defined".

However, when I put a script "$gameActors.actor(1)._tpbState" into a variable and make a text box with it, it does say either "casting" or "charging", so clearly it has a value? So what's the problem?
what does it mean when it also says that "Reference error: casting is not defined"?
I tested it with:
$gameActors.actor(1)._tpbState === "casting"
Are you certain you wrote "casting" (string) rather than casting (variable)? Because the latter would cause exactly that error message.

If so, then like the OP has done, I suggest you open the dev tools window (F8 or F12 during playtest) and share a screenshot of the full error message seen in the Console tab. Perhaps the error itself is happening on a different line.

Otherwise, as earlier, I can only suggest following the VisuStella support guidelines. (It doesn't look like anyone who has seen this thread knows the answer.)
@caethyril Yes, I tested it again and copied it from that box you quoted. Gives an error.

But did you see my edit above?

I think it has something to do with it searching those keywords or that it only wants code on one side of the equation of something, I don't know, I'm not a coder.

Anyway, it seems I got it to work by using the expression in my edit?

However, the "target" word still doesn't work in conjunction with that...do you know how I get the current target the program is evaluating as a potential target? (I mean even in the base game, if we forget Visustella). Maybe that would work?
Ah, I didn't see the edit earlier, no. I guess it's some quirk of how VisuStella's plugin parses that condition. 😴

The core engine has BattleManager._targets, which is an array containing the remaining targets for the current action (does not include the current target). I don't imagine that'll help much.

Maybe try $target instead of target? I think I saw someone use something like that in a VisuStella action sequence once.
Hmm, can't get it to work. But thanks for the help. Hope someone knows how the target can be referenced...

Original thread: https://forums.rpgmakerweb.com/threads/enemies-smart-enough-to-atb-interrupt-how-do.161317/