Sure. Just replace the insertParsedMessageRoll function in chat\lib\class\AJAXChat.php with the one belowGameraFan wrote:I'd like to see this code. Would you post it here?RiTz21 wrote:Well, since I really wanted the feature #1 I requested, I implemented it on my copy of the chat mod...
Example:
/roll 2d6+12 returns:
(21:12:03) ChatBot: (admin) rolls 2d6+12 and gets [6,4]+12=22.
If anyone else needs this, lemme know and I'll share
Code: Select all
// 12/06/2008: Bonus value can now be added to result (i.e. xdy+z) - RiTz21 http://TheOnlySheet.com
function insertParsedMessageRoll($textParts) {
if(count($textParts) == 1) {
// default is one d6:
$text = '/roll '.$this->getUserName().' 1d6 '.$this->rollDice(6);
} else {
$diceParts = explode('d', $textParts[1]);
if(count($diceParts) == 2) {
$bonus = 0;
$number = (int)$diceParts[0];
$diceandbonusParts = explode('+', $diceParts[1]);
if(count($diceandbonusParts) == 1) {
$sides = (int)$diceParts[1];
} else {
$sides = (int)$diceandbonusParts[0];
$bonus = (int)$diceandbonusParts[1];
if ($bonus > 1000)
$bonus = 1000;
}
// Dice number must be an integer between 1 and 100, else roll only one:
$number = ($number > 0 && $number <= 100) ? $number : 1;
// Sides must be an integer between 1 and 100, else take 6:
$sides = ($sides > 0 && $sides <= 100) ? $sides : 6;
if ($bonus == 0) {
$text = '/roll '.$this->getUserName().' '.$number.'d'.$sides.' '.'[';
} else {
$text = '/roll '.$this->getUserName().' '.$number.'d'.$sides.'+'.$bonus.' '.'[';
}
$totalresult = 0;
$tmpvalue = 0;
for($i=0; $i<$number; $i++) {
if($i != 0)
$text .= ',';
$tmpvalue = $this->rollDice($sides);
$text .= $tmpvalue;
$totalresult += $tmpvalue;
}
$totalresult += $bonus;
$text .= ']';
if ($bonus != 0)
$text .= '+'.$bonus;
$text .= '='.$totalresult;
} else {
// if dice syntax is invalid, roll one d6:
$text = '/roll '.$this->getUserName().' 1d6 '.$this->rollDice(6);
}
}
$this->insertChatBotMessage(
$this->getChannel(),
$text
);
}
RiTz21