MZ What would be the best approach to hook code into animation system? [MV/MZ]

What would be the best way to hook code into the battle animation system?
Some of the easiest approaches I can think of are just:
  • On damage (No need to hook into animation system, just use Game_Action)
  • On animation start (Window_BattleLog shenanigans)
  • On animation end (Also can use Window_BattleLog shenanigans)
But what if we want to have more precision regarding the timing? Like running code at a specific animation frame? I'm aware we can just count the frames from onAnimationStart, but any better ideas? :hswt:
This is somewhat difficult conceptually because traditionally we've used the note field for many of the user-driven plugin inputs, and obviously animations don't have one. This means that setup-wise you'd have to either hardcode your functionality into a plugin with specific animation references, or provide a JSON file for the data and have a plugin that reads it. Doable, but not without its downsides.

However, in terms of said precision, Sprite_Animation has a _frameIndex property already, so you could use that to determine it. This is already how the sound/flash timings work, so you could expand that.
Yeah this is not as simple as I thought :hswt: The problem would be moving the data from user (either notetags or JSON) into animation data.

I guess the simplest thing that I can think of is to use skill/item/weapon note field, then during database load we parse animation related notetag then add it to $dataAnimations. Probably works for battle-related animation only, though.
Maybe Sprite_Battler?
So in its update function you can check animation state as well as the battler.
I have hooked into Sprite_Animation's updateMain method in one of my projects to trigger screen shakes of specific intensities at specific frames. I configure the frames and shake properties in a simple object keyed by the animation id.
@utunnels I'll check into it, might be handy too for more precise control. Thanks! :hwink:

@Kenen Hahah that is exactly what I'm trying to do, Sprite_Animation it is. Thanks Kenen! 🤣 does the frame based approach works well?

Original thread: https://forums.rpgmakerweb.com/threads/what-would-be-the-best-approach-to-hook-code-into-animation-system-mv-mz.176002/