DND Dice code

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

DND Dice code

Post by dragon slayer »

var rand = rollDie();       //# d6
var rand = rollDie(6);      //# d6
var rand = rollDie(20);     //# d20
var rand = rollDice(3);     //# 3d6
var rand = rollDice(3, 6);  //# 3d6
var rand = rollDice(2, 12); //# 2d12

function rollDie(sides)
{
    if (!sides)
        sides = 6;
    with (Math)
    return 1 + floor(random() * sides);
}

function rollDice(number, sides)
{
    var total = 0;
    while (number-- > 0) total += rollDie(sides);
    return total;
}
hope this comes in handy for some one
Post Reply