Dice Roll for damage?

So, what I was thinking for my game was for a more DnD-esque mode of combat.


What I mean by that is everything is controlled by die rolls. I.e., the Warlock's Darkspiral Aura ability deals 1d6. How would I go about making this?
To simulate a d6 roll, make the damage formula Math.floor(Math.random(6)) + 1 which will produce a random number 1 through 6 inclusive.
okay, so, just trying to make sure I have this right before I mess it up.


Math.floor(math.random(12)) + Math.floor(math.random(12)) + 2 would make a 2d12?
@feliaria,


To shorten the code, you can also use


Math.randomInt(max)


So, yup, Math.randomInt(12) + Math.randomInt(12) + 2 would be 2d12.
Thanks, guys! 🙂
Actually.


Math.randomInt(max) is not accurate. That generates a number from 0 to MAX.


So for 1d12 you want Math.randomInt(11)+1


or you could just do: math.randomInt(1, 12) (or MIN , MAX)
@Baerthe,


From RPG Maker:


/**
* Generates a random integer in the range (0, max-1).
*
* @static
* @method Math.randomInt
* @param {Number} max The upper boundary (excluded)
* @return {Number} A random integer
*/


It doesn't take 2 parameters, only a single one. And it generates a number between n to n-1. So Math.randomInt(12)+1 is correct.
@Mr. Trivel


Huh, Alright. Not how I learned it, lol.
Hmm... So, it's always dealing no damage? I tried setting my Attack for a 1d6 damage plus half of the character's ATK but it always returns 0 damage? The enemies have 1 defense. I originally had it as the math.randomInt(6) and it was returning 0, so I switched to the long-hand but it still didn't fix anything. :/


Attack Dice formula.PNG
@feliaria,


It's Math not math
Mrgrgr... Still doing 0 :/
@feliaria,


And also it's not atk but either a.atk or b.atk. a being skill user, b being skill receiver.


Example:


[IMG]http://puu.sh/oD9zA/2cf294545d.png[/IMG]
I should have noticed that, lol XD


Thanks, Mr. Trivel! Sorry you had to walk me through that so slowly. Shoulda been obvious. :/

Original thread: https://forums.rpgmakerweb.com/threads/dice-roll-for-damage.61232/