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;
}