# Make SURE there is no BOM in this file! It causes functions to be seen as non-existent! # This rolls the number and sides of the dice requested. # Any modifiers are applied after the roll. # $1 is the number of sides in the dice. # $2 is the number of dice to roll. # $3 is the modifier that is applied at the end. # This returns a modified list of the results. sub roll { local('@result $sum $toRet'); $toRet = "[ "; $sum = 0; while ($2 > 0) { push(@result, rand($1) + 1 + $3); $2--; } foreach $t (@result) { $toRet = "$toRet $t "; $sum = $sum + $t; } return "$toRet ] = $sum"; } # Rigging the die roll is done through a different method for ease of use. # $1 is the number of dice to "roll" (results in a list) sub rig { local('@results $toRet'); $toRet = "[ "; foreach $t ($1) { push(@results, int($t)); } foreach $t (@results) { $toRet = "$toRet $t "; } return "$toRet ]"; } # This is a helper for the dice rolling. # $1 is the @word passed in. sub IRCDice { this('@word $numDice $numSides $modifiers $toRet'); @word = $1; $numDice = 1; $numSides = 6; $modifiers = 0; if (size(@word) >= 3) { $numSides = int(@word[2]); } if (size(@word) >= 4) { $numDice = int(@word[3]); } if (size(@word) == 5) { $modifiers = int(@word[4]); } $toRet = roll("$numSides", "$numDice", "$modifiers"); call("/me rolls $numDice $numSides $+ -sided di[c]e! The results: $toRet"); return; } # The rolling commands are done here. alias dice { local('@word'); @word = split(' ',$0-); # /dice roll [] [] [] if (lc(@word[1]) eq lc("roll")) { IRCRoll(@word); } # /dice rig @(numbers to display) else if (lc(@word[1]) eq lc("rig")) { this('@rigging $toRet'); @rigging = subarray(@word, 2); $toRet = rig(@rigging); call("/me rigs some dice! The results: $toRet"); } else { say("\bERROR!\b Invalid command! (See the debug information)"); echo(@word); } } # The dice remote. on public { if (lc($remotesOn) eq lc("false")) { return; } local('@word $toRet'); @word = split(' ',$0-); if (@word[1] eq "#dice") { IRCRoll(@word); } return; } global('$remotesOn'); #boolean $remotesOn = "false"; #echo(roll(6, 3, 0)); #echo(rig(@(4, 1, 8)));