Script to check if a specific animation id is playing on a map event?

Using the script call list, I found I can do for example $gameMap.event(1).isAnimationPlaying() in a script conditional branch to check if an animation is playing on map event id 1. However, I could not find a solution to check if a specific animation id is playing, is there a way?
Using the script call list, I found I can do for example $gameMap.event(1).isAnimationPlaying() in a script conditional branch to check if an animation is playing on map event id 1. However, I could not find a solution to check if a specific animation id is playing, is there a way?
You'll have to double check the code - I think it should be:
JavaScript:
$gameMap.event(1)._animationId

So, conditional branch:
JavaScript:
◇If : Script : $gameMap.event(1).isAnimationPlaying() && $gameMap.event(1)._animationId === 1

Not at a computer at the moment so I'm not completely sure.
@bass2yang's suggestion may work if you're using a plugin that sets _animationId on the target character(s). MZ does not do that by default.

Alternatively, you can try Conditional Branch -> Script:

const target = $gameMap.event(1); const animId = 56; SceneManager._scene._spriteset._animationSprites.some(s => s.isPlaying() && s._animation.id === animId && s.targetObjects.contains(target))
I.e. "is animation ID 56 currently playing on map event ID 1?" Change the numbers as needed~

I would recommend tracking this kind of thing with a variable or something instead, if possible. Much neater all round that way, and it helps to avoid odd situations that might crop up due to predicating a backend mechanic (event branch) on a frontend display element (animation sprite).
@bass2yang's suggestion may work if you're using a plugin that sets _animationId on the target character(s). MZ does not do that by default.

Alternatively, you can try Conditional Branch -> Script:

const target = $gameMap.event(1); const animId = 56; SceneManager._scene._spriteset._animationSprites.some(s => s.isPlaying() && s._animation.id === animId && s.targetObjects.contains(target))

I.e. "is animation ID 56 currently playing on map event ID 1?" Change the numbers as needed~

I would recommend tracking this kind of thing with a variable or something instead, if possible. Much neater all round that way, and it helps to avoid odd situations that might crop up due to predicating a backend mechanic (event branch) on a frontend display element (animation sprite).
I‘ve tried that and it seems to work well so far, thank you!
Great, happy RPG Making~ 👋
Great, happy RPG Making~ 👋
It might be simpler and safer to manage with a plugin, but I don't really know how to code aside from using the script call list, is there a plugin out there that can do this? I haven't found any myself
So, something to automatically "track it with a variable"? I don't know of a plugin like that, but maybe someone else does.
So, something to automatically "track it with a variable"? I don't know of a plugin like that, but maybe someone else does.
The purpose of this is to be used along with the Galv’s map projectiles plugin to always give damage to the correct enemy. With the plugin, you can set a common event when the projectile hits an event with <projeffect>. However, if it hits the wrong event, it will still use the common event mentioned in the projectile parameters.

By improving accuracy by tweaking speed and range and using a script to store which event is closest to a turret and then attacking this enemy it happens less. But it still happens, which is an issue.

So my thoughts were to check if an animation is playing on specified map events, and then call the needed script to deal damage since the animation always plays on the enemy hit.

So I guess it would be more to check if an animation has started on specified events, and if true, call a common event once for each time. Is this possible?

Original thread: https://forums.rpgmakerweb.com/threads/script-to-check-if-a-specific-animation-id-is-playing-on-a-map-event.165699/