Calling Random Numbers - Printable Version +- Save-Point (https://www.save-point.org) +-- Forum: Games Development (https://www.save-point.org/forum-4.html) +--- Forum: Code Support (https://www.save-point.org/forum-20.html) +--- Thread: Calling Random Numbers (/thread-4809.html) |
Calling Random Numbers - Alistor - 09-06-2013 I'm working on building a D&D styled battle system, and i need to know how to call random numbers from a specific range. for example, to hit with an attack, the basic formula goes like this: if d20 + Actor strength mod + BAB > target AC Hit Else Miss I know this isn't proper code, but i'm still working on it. anyways, where it says d20, i need it to call a random number from 1-20. i'll add Critical functionality later, but for now, this is it. RE: Calling Random Numbers - DerVVulfman - 09-07-2013 HOWL!!!!
Heyoo, it's the Resident Werewolf to offer the Resident Wiccan a little dice script. And it has all your classic bag o' dice values from the 4-sider right up to the full 20 sided die. Code: #============================================================================== I hope you like it. Now you have little commands to actually make a thing like... Code: hit_result = false or Code: strength_roll = Dice.d6(3) The Dice.d20 command generates your d20 dice roll, and the Dice.d6(3) is equivalent to rolling 3 six-siders RE: Calling Random Numbers - MechanicalPen - 09-07-2013 If you had read the RPGm XP help manual you would have known that rand(n) function can do exactly what you want. Well almost. And VVulfy, that is a little too much computational overhead for my tastes (and I've never seen a die numbered 0 to sides-1). I'd do it like this: Code: module Roll Then rolls are just: Code: strength_roll = Roll.d(20) RE: Calling Random Numbers - DerVVulfman - 09-08-2013 Given that he requested one for a Dungeons and Dragons styled system, he would be more familiar with 4sided dice, 6 siders, 8siders and so forth. Hence, my version was designed to use method names that replicated the AD&D dice rolls, and include the number of dice at the same time. The call of ... Code: strength_roll = Dice.dice_roll(6, 3) ...would match that of the Dice.d6(3). It rolls a six-sided die 3 times. But the Dice.d6 command (and others included) are meant to make it easier to use. I went with an easy-to-use gamer mentality for d4, d6, d8, d10, d12 and d20 rolls. And call it an old-school methodology that I grew up with that reinitialized values ( the result = 0 ) as well as a mentality to include failsafe routines. RE: Calling Random Numbers - MechanicalPen - 09-08-2013 I personally think Code: thing = Roll.d(20) + Roll.d(20) Plus, no matter what way you do it, it is still 'rand(n)+1' and not 'rand(n)' to get a dice roll. For example, rand(6) returns a number from 0-5. rand(6)+1 returns a number from 1-6 as required by dice. RE: Calling Random Numbers - DerVVulfman - 09-08-2013 Oh, I see what you mean about rand +1. Um, I caught that at 1-ish (about when you posted. I changed it in the script to Code: result += rand(dice)+1 And wouldn't that be Code: thing = Roll.d(20) + (Roll.d(20) +2 With mine, it would be Code: thing = Dice.d20(2) RE: Calling Random Numbers - MechanicalPen - 09-08-2013 Nope! Just Code: thing = Roll.d(20) + Roll.d(20) Either way works. RE: Calling Random Numbers - DerVVulfman - 09-08-2013 Oooh. Guess I mis-saw yours just as you musta seen my pre-edit version (ironically when I was editing it?). :P |