World of Darkness Roller
Posted: Thu May 09, 2013 12:13 am
First post, but if you're using the DiceTool and playing New World of Darkness, then I figured I should share this function.
To use, paste the code at end of this post into a "functions.js" file in the same directory as your dicetool-1.0*.jar file. This will give you a new function called wodRoll. The first argument is the number of dice, then the number to re-roll (in case you're playing 8/9/10 again), and finally a 'chance roll' boolean (where 0 is false, and anything else is true).
The total number of successes is given at the top, followed by each die roll. Blue rows are successes, green rows accrue an extra die (/reroll), and black rows show a Dramatic Failure (only in chance rolls).
This means you can put the following rolls in your tabs:
This will roll 4d10, and reroll any 10s.
This will roll 4d10s, and reroll any 8s, 9s, or 10s.
This will roll a chance roll, rerolling 10s (only a 10 is a success, 1s come out as black)
This will roll a chance roll, but reroll 8s, 9s, or 10s (Still only 10 is success)
As above. The number of dice are ignored on a chance roll.
You can also combine that function and some constants, if you'd like, by using:
Roll 4d10, reroll any 10s, add 4 to the total number of successes
The code to paste in your functions.js file follows. Enjoy!
To use, paste the code at end of this post into a "functions.js" file in the same directory as your dicetool-1.0*.jar file. This will give you a new function called wodRoll. The first argument is the number of dice, then the number to re-roll (in case you're playing 8/9/10 again), and finally a 'chance roll' boolean (where 0 is false, and anything else is true).
The total number of successes is given at the top, followed by each die roll. Blue rows are successes, green rows accrue an extra die (/reroll), and black rows show a Dramatic Failure (only in chance rolls).
This means you can put the following rolls in your tabs:
Code: Select all
wodRoll(4)
Code: Select all
wodRoll(4, 8)
Code: Select all
wodRoll(1, 10, 1)
Code: Select all
wodRoll(1, 8, 1)
Code: Select all
wodRoll(10, 8, 1)
You can also combine that function and some constants, if you'd like, by using:
Code: Select all
wodRoll(4) + 4
The code to paste in your functions.js file follows. Enjoy!
Code: Select all
function registerFunctions() {
var map = new java.util.HashMap();
map.put("wodRoll", wodRoll);
return map;
}
function wodRoll(numDice, rerollAt, isChanceRoll) {
row.setLabel("Successes:");
if (!rerollAt) {
rerollAt = 10;
}
// Can only roll one, regardless of what they way.
if (isChanceRoll) {
numDice = 1;
}
var originalDice = numDice;
var successes = 0;
for (var i = 0; i < numDice; i++) {
var value = rand.nextInt(10) + 1;
resultSet.addExpression("Die " + (i + 1) + (i >= originalDice ? ' (Extra die!)' : ''), value + '', null, value);
var innerRow = resultSet.getCurrentRow();
if (isChanceRoll) {
if (value == 10) {
// If chance roll, only 10s are successes.
// 10s give another chance.
successes++;
numDice++;
innerRow.setBackgroundColor(0, 0, 255);
innerRow.setForegroundColor(255, 255, 255);
}
if (value == 1) {
innerRow.setBackgroundColor(0, 0, 0);
innerRow.setForegroundColor(255, 255, 255);
}
} else {
if (value >= 8) {
successes++;
innerRow.setBackgroundColor(0, 0, 255);
innerRow.setForegroundColor(255, 255, 255);
}
if (value >= rerollAt) {
numDice++;
innerRow.setBackgroundColor(0, 255, 0);
innerRow.setForegroundColor(0, 0, 0);
}
}
innerRow.setTotal(successes);
}
return successes;
}