There are a few slight differences amongst a couple of these functions. For example, Coin() will return 0 or 1, when D2() will return 1 or 2. D100() returns intervals of 10 and not 1-100. This is intended to be used with a D10() which returns 1-10 (e.g. D100() + D10()). This is common in the real-world where a D100 is actually a D10 with intervals of 10s and not 100 sides.
Each proc takes a number as an argument which tells the proc how many dice to use, and returns the total of the roll.
/////////////////
// DICE MODULE //
/////////////////
proc/Coin(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(0,1)
return d
proc/D2(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,2)
return d
proc/D4(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,4)
return d
proc/D6(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,6)
return d
proc/D8(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,8)
return d
proc/D10(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,10)
return d
proc/D12(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,12)
return d
proc/D16(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,16)
return d
proc/D20(N=1)
var/d = 0
for (var/i = 1 to N)
d += rand(1,20)
return d
proc/D100(N=1)
var/d = 0
for (var/i = 1 to N)
d += (rand(1,10)*10)
return d
An example of using the dice can be something like:
proc/CalcDamage()
return D20(1) + D6(3)
proc/InflictDamage(client/C)
var/d = CalcDamage()
world << "[C] inflicts [d] damage!"
Calculating a percentage:
proc/DicePercentage()
return D100() + D10() // 1-100