function insertParsedMessageRoll($textParts) { if(count($textParts) == 1) {
// default is one d20:
$number = 1;
// need to set $parts to an empty array for the rest of this
$dicestring = "20";
} else {
// use lowercase, remove any user entered spaces and find a 'd'
$diceParts = explode('d', strtolower($textParts[1]).str_replace(' ', ''));
if(count($diceParts) == 1) {
// no 'd' was specified, so assume 1 die
$number = 1;
$dicestring = $diceParts[0];
} else if(count($diceParts) == 2) {
// note that the $number could still be blank/zero
$number = (int)$diceParts[0];
$dicestring = $diceParts[1];
} else {
// if dice syntax is invalid, roll one d20:
// this culd be multiple 'd's but we can't deal with that
$number = 1;
$dicestring = "20";
}
}
// Dice number must be a positive integer, else roll only one:
$number = ($number > 0) ? $number : 1;
// still need to parse sides and the modifiers
$dicestring = str_replace('+', ' + ', $dicestring);
$dicestring = str_replace('-', ' - ', $dicestring);
$dicestring = str_replace('x', ' x ', $dicestring);
$dicestring = str_replace('*', ' x ', $dicestring);
$dicestring = str_replace('/', ' / ', $dicestring);
// explode the whole thing to create tokens
$parts = explode(' ', $dicestring);
// Sides must be a positive integer , else use 20:
$sides = (int)$parts[0];
$sides = ($sides > 0) ? $sides : 20;
// now roll the dice, and total them up
$text = '/roll '.$this->getUserName().' '.$number.'d'.$sides.' (';
$total = 0;
for($i=0; $i<$number; $i++) {
$roll = $this->rollDice($sides);
if($i != 0)
$text .= ',';
$text .= $roll;
$total += $roll;
}
$text .= ')';
// add modifiers explicitly to $text
// modify the value of $total
// the rest of $parts should be modifier tokens - could check for the right number
// now apply all the modifiers to the roll, in the order the user specified them
for ($i = 1; $i < count($parts); $i+=2) {
// the value needs to be an integer
$value = (int)$parts[$i+1];
$v = $parts[$i+1];
if ("$value" != "$v") {
// if the value being used is not an integer, use 1?
$value = 1;
}
// the token needs to be one of the operators - otherwise skip
$token = $parts[$i];
switch ($token) {
case '+':
// add
$total += $value;
break;
case '-':
// subtract
$total -= $value;
// make minimum 1 - remove this like to allow 0 and lower
if ($total<1) $total=1;
break;
case 'x':
// multiply
$total *= $value;
break;
case '/':
// divide - round up so 1d6/3 will be the same as 1d2
$total = ceil($total/$value);
break;
default:
// ignore any modifier that we don't recognize
break;
}
// add the modifier to the display string
$text .= $token.$value;
}
$text .= '='.$total;
// send the text generated to the channel
$this->insertChatBotMessage(
$this->getChannel(), $text
); );
// Rolling dice: case '/d': case '/roll': $this->insertParsedMessageRoll($textParts);
break;
I managed to find my version of a 0.8.7 tested mod in another subdirectory http://gworldz.com/cxc/AJAXChatSalvage/ its the Advanced Dice Roller mod.
http://gworldz.com/cxc/AJAXChatSalvage/AJAXChat%20-%20Advanced%20Dice%20Roller%20Mod.html
/roll 200000d200000*200000
// ~cXc~ Advanced Dice Roller
function insertParsedMessageRoll($textParts) {
if(count($textParts) == 1) {
// default is one d20:
$number = 1;
// need to set $parts to an empty array for the rest of this
$dicestring = "20";
} else {
// use lowercase, remove any user entered spaces and find a 'd'
$diceParts = explode('d', strtolower($textParts[1]).str_replace(' ', ''));
if(count($diceParts) == 1) {
// no 'd' was specified, so assume 1 die
$number = 1;
// Users limited from rolling more than 100 dice if input exceeds 100, user rolls 1 instead
$number = ($number > 0 && $number <= 100) ? $number : 1;
$dicestring = $diceParts[0];
} else if(count($diceParts) == 2) {
// note that the $number could still be blank/zero
$number = (int)$diceParts[0];
// Users limited from rolling more than 100 dice if input exceeds 100, user rolls 1 instead
$number = ($number > 0 && $number <= 100) ? $number : 1;
$dicestring = $diceParts[1];
} else {
// if dice syntax is invalid, roll one d20:
// this culd be multiple 'd's but we can't deal with that
$number = 1;
// Users limited from rolling more than 100 dice if input exceeds 100, user rolls 1 instead
$number = ($number > 0 && $number <= 100) ? $number : 1;
$dicestring = "20";
}
}
// Dice number must be a positive integer, else roll only one:
$number = ($number > 0) ? $number : 1;
// still need to parse sides and the modifiers
$dicestring = str_replace('+', ' + ', $dicestring);
$dicestring = str_replace('-', ' - ', $dicestring);
$dicestring = str_replace('x', ' x ', $dicestring);
$dicestring = str_replace('*', ' x ', $dicestring);
$dicestring = str_replace('/', ' / ', $dicestring);
// explode the whole thing to create tokens
$parts = explode(' ', $dicestring);
// Sides must be a positive integer , else use 20:
$sides = (int)$parts[0];
$sides = ($sides > 0) ? $sides : 20;
// If input for number of sides exceeds 100 roll a 20 sided die instead
$sides = ($sides > 0 && $sides <= 100) ? $sides : 20;
// ~cXc~ Advanced Dice Roller