Play animation if damage is 0

Hello, I am having a difficult time trying to figure out how to play an animation if my attack does 0 damage.


For example: if the actor attacks and does 0 damage to the enemy I'd like a shield animation to play on the enemy to show that he blocked it. I have it set now so that a message says "enemy blocked the attack", but I'd like to show the animation as well.


I don't know if it'll be needed but here's the damage formula I use for my attack skill:


aDice=Math.randomInt(21);
bDice=Math.randomInt(21);
aDice==0 ? aDice=1 : aDice+0;
bDice==0 ? bDice=1 : bDice+0;
aDice==20 ? a.atk*2 : aDice+0;
bDice==20 && aDice<20 ? a.atk=0 : aDice+0;
(a.atk + aDice) - (b.def + bDice)


Also if you notice anything wrong with this formula I'd greatly appreciate you pointing it out, I know very little about Java Script.
Using Yanfly's action sequences, I use something along these lines instead of letting RMMV do its thing at all:


<target action>


motion attack: user


wait: 30


action effect: target


motion damage: target


</target action>


This makes it so the animation and effects happen as I want them to, regardless of whatever else the skill does. I'm admittedly not sure how you'd plug the damage values into it, but the action sequences do allow you force the actors to make the desired motions either way.
Using Yanfly's action sequences, I use something along these lines instead of letting RMMV do its thing at all:


<target action>


motion attack: user


wait: 30


action effect: target


motion damage: target


</target action>


This makes it so the animation and effects happen as I want them to, regardless of whatever else the skill does. I'm admittedly not sure how you'd plug the damage values into it, but the action sequences do allow you force the actors to make the desired motions either way.

Thanks but I'm only looking to play the animation if the attack hits for 0 damage.
aDice=Math.randomInt(21);
bDice=Math.randomInt(21);
aDice==0 ? aDice=1 : aDice+0;
bDice==0 ? bDice=1 : bDice+0;
aDice==20 ? a.atk*2 : aDice+0;
bDice==20 && aDice<20 ? a.atk=0 : aDice+0;
c = (a.atk + aDice) - (b.def + bDice); (c == 0) ? b.startAnimation(x); 0 : c


Hello!


I didnt go through your code, but it looks okay at first glance. As for the animation, you can try the above code.


Hope that works!


- Riff
aDice=Math.randomInt(21);
bDice=Math.randomInt(21);
aDice==0 ? aDice=1 : aDice+0;
bDice==0 ? bDice=1 : bDice+0;
aDice==20 ? a.atk*2 : aDice+0;
bDice==20 && aDice<20 ? a.atk=0 : aDice+0;
c = (a.atk + aDice) - (b.def + bDice); (c == 0) ? b.startAnimation(x); 0 : c


Hello!


I didnt go through your code, but it looks okay at first glance. As for the animation, you can try the above code.


Hope that works!


- Riff

Thank you, this seems to be what I'm looking for, however for some reason even when my attack does 0 the animation doesn't play every time, any idea why?
Thank you, this seems to be what I'm looking for, however for some reason even when my attack does 0 the animation doesn't play every time, any idea why?



Do you mean it only plays the animation sometimes and sometimes it doesnt?
Yes. It seems to be random when it'll play. Sometimes the attack will hit for 0 and it will play and other times the attack will hit for 0 and it won't play.
I honestly dont know. Sorry. Seems a bit odd.
I honestly dont know. Sorry. Seems a bit odd.

Thank you for the help you've given.


I'll keep trying different things to see if I can figure out why it's seems to play randomly. 

Original thread: https://forums.rpgmakerweb.com/threads/play-animation-if-damage-is-0.58575/