How to make critical hits inflict a state and play an animation?

For my current project, I wanna have critical hits inflicted on both party members and enemies have a 100% chance to inflict a state called "Stun"

On top of this I wanna have it play a cool animation when it crits

Anyone know how to make this a reality? Kinda a noob when it comes to scripting
You'll get more answers if you change your 'primarily uses' to match the engine you're asking support questions for.

There's a plugin Victor Critical Hit Effects. You can also use Yanfly plugins to put passive states to everything with:

<Custom Establish Effect>
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
target.startAnimation(X);
target.addState(Y);
}
</Custom Establish Effect>
You'll get more answers if you change your 'primarily uses' to match the engine you're asking support questions for.

There's a plugin Victor Critical Hit Effects. You can also use Yanfly plugins to put passive states to everything with:

<Custom Establish Effect>
if (this.isPhysical() && target.result().hpDamage > 0 && target.result().critical) {
target.startAnimation(X);
target.addState(Y);
}
</Custom Establish Effect>
This actually worked... thanks a TRILLION dude. I'll credit you if this project ever sees the light of day

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-critical-hits-inflict-a-state-and-play-an-animation.174153/