Multiple "If-else" in damage formula question.

I'm looking to make attacks work something like D&D attacks, following this procedure:

1) A random number is given, it is added the actor or enemy's attack stat, and if it surpasses the target's defense stat, it deals normal damage.

2) If the random number + the attacker's attack stat does not equal or surpass the target's defense score, the attack misses, dealing no damage.

3) Also, if the given number is between the 5% highest possible (191 to 200 in this case), the attack is a critical, hitting regardless of attack and defense stats and dealing additional damage.

While researching about damage formulas I managed to achieve the first 2 goals by the following formula:


Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage formula" : 0

I'm now trying to add the critical hit mechanic, and tried the following:

Math.floor(Math.random()*200)+0 >= 191 ? "Critical damage formula" : Math.floor(Math.random()*200)+0 >= 100 + b.def - a.atk ? "Damage Formula" : 0

This way it works good, but I think what the formula is doing is giving a number to see if it's a critical hit, and if it isn't, it gives another to check if the attack landed in the first place.

Is there a way for the if-else statement to apply to the first Math.floor? Meaning, is there a way to ask two different questions to the same value?
Can you do something like

var dieroll = Math.floor(Math.random()*200);
dieroll >= 191 ? "Critical damage formula" : dieroll >= 100 + b.def - a.atk ? "Damage Formula" : 0
Also, a style comment about this part:
Math.floor(Math.random()*200)+0 >= 191
This gets a random integer from 0 to 199 inclusive, then asks if it's greater than or equal to 191. That has a 9/200 (4.5%) chance of being true. I'm not sure if that's what you intended.

In case it helps: MV's core scripts define a randomInt shorthand, e.g.
JavaScript:
Math.randomInt(200) < 9
I.e. "is a random integer from 0 to 199 inclusive less than 9?" That should be true in 9/200 cases.

I don't see why you need to round it at all, though, if you're only using it as a threshold check. I think you could just rewrite your original check as:
JavaScript:
Math.random() * 200 >= 191
Or, following Showsni's suggestion:
JavaScript:
var dieroll = Math.random() * 200; dieroll >= 191 ? etc
Can you do something like

var dieroll = Math.floor(Math.random()*200);
dieroll >= 191 ? "Critical damage formula" : dieroll >= 100 + b.def - a.atk ? "Damage Formula" : 0
Yup, this got the job done. Didn't know I could use variables in the damage formula. Thanks!
Also, a style comment about this part:

This gets a random integer from 0 to 199 inclusive, then asks if it's greater than or equal to 191. That has a 9/200 (4.5%) chance of being true. I'm not sure if that's what you intended.
Yeah I forgot to add the +1 at the end, the idea is for it to be from 191 to 200, being 10/200 and 5% chance to crit.

I also made it so that It can vary depending on the attacker's crit chance by doing:

Math.floor(Math.random()*200)+1 >= 200 - 200 * a.cri
Math.random() * 200 >= 191
That does look simpler, thanks so much!

Original thread: https://forums.rpgmakerweb.com/threads/multiple-if-else-in-damage-formula-question.169895/