-
-
Save DavidSandey/144039 to your computer and use it in GitHub Desktop.
Ubiquity Roll noun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Rolls dice!! | |
Arb dice size and number | |
with options to get bonus dice for high results | |
i.e. exploding dice pool as per World of Darkness | |
By Brett Dalton | |
original idea based on Dustin Calhoun's Roll Verb | |
*/ | |
CmdUtils.CreateCommand({ | |
names: ["roll"], | |
arguments: [{ role:"object", | |
nountype: noun_arb_text, | |
label: "dice to roll"}], | |
author: [{ name: "David Sandey", | |
email: "david@sandey-family.com"}], | |
license: ["Use it and Abuse it License"], | |
preview: function(pblock, arguments) | |
{ | |
var msg = "Rolls dice with re-rolls <br><br> <b>Syntax </b><br> <b>4 </b> - rolls 1x4 sided dice <br><br> <b> 2d8</b> - rolls 2x8 sided dice <br><br> <b> 4d10x8 </b> - rolls 4x10 sided dice with extra rolls for any result of 8 or above.<br> Useful for World of Darkness games<br><br> <b>d6x </b>- rolls 1x6 with re-rolls equal to dice size, in this case 6" | |
pblock.innerHTML = _(msg); | |
/* var i = 0; | |
var r = 0; | |
var d = 0; | |
var x = 0; | |
var randNum = 0; | |
var delim_D = 0; | |
var delim_X = 0; | |
var doc = CmdUtils.getWindowInsecure(); | |
var resultStr =""; | |
// Find if the D and X are in the string | |
delim_D = arguments.object.text.indexOf("d") + arguments.object.text.indexOf("D") +1; | |
delim_X = arguments.object.text.indexOf("x") + arguments.object.text.indexOf("X") +1; | |
// try to parse the string regardless of if entire string exists | |
r = parseInt(arguments.object.text.substring(0)); | |
d = parseInt(arguments.object.text.substring(delim_D+1)); | |
x = parseInt(arguments.object.text.substring(delim_X +1)); | |
if(isNaN(r)) | |
{ | |
r = 1; | |
} | |
if (delim_D == -1) // if there is no 'D' ie 12 or 12x10 | |
{ | |
d = r; | |
r = 1; | |
} | |
if (delim_X == -1) // if no 'X' make the ie 10 or 4d8 | |
{ | |
x = d+1; | |
} | |
if (delim_X +1 == arguments.object.text.length) | |
{ | |
x = d; | |
} | |
// AVOID INFINITE LOOP | |
if (x == 1) | |
{ | |
doc.alert("value for exploding dice MUST be > 1"); | |
return -1; | |
}; | |
// actually do the rand and gen the output | |
for(i==0; i<r; i++) | |
{ | |
randNum = Math.floor(Math.random()*d +1); | |
tempStr = resultStr; | |
if(i==0) | |
{ | |
resultStr = randNum; | |
if(randNum >= x) | |
{ | |
r++; | |
} | |
} | |
else | |
{ | |
resultStr = tempStr + ", " + randNum; | |
if(randNum >= x) | |
{ | |
r++; | |
} | |
} | |
} | |
pblock.innerHTML = _(theRoll.object.text + " " + resultStr.object.text); | |
*/ | |
pblock.innerHTML = _(arguments.object.text) | |
}, | |
execute: function (arguments) { | |
var msg = arguments.object.text + " = " + ""; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment