alias d { $!-
if ($count($1-,d) > 1) { halt }
%input = $1-
%ctr = 1
%legalChars = $chr(32) $+ $chr(42) $+ $chr(43) $+ $chr(45) $+ $chr(35)
%check = $mid(%input,%ctr,1)
:scan
if (%check != $null) {
if (((%check !isnum 0-9) && (%check !isletter d)) && (%check !isin %legalChars) ) { halt }
else {
inc %ctr
%check = $mid(%input,%ctr,1)
goto scan
}
}
; Check that there is not more than one of each legal non-digit character in the input
; Separate input into two variables: number of sets and a string of remaining dice data
; Either a pound sign '#' or a blank space ' ' is used as the delimeter for separating the variables
if (($count(%input,+) > 1) || ($count(%input,-) > 1) || ($count(%input,x) > 1)) { /dice Too many parameters $+ . | halt }
if (($chr(35) !isin %input) && ($chr(32) !isin %input)) {
%raw = %input
%sets = 1
}
else {
if ($chr(35) isin %input) { %del = 35 }
else { %del = 32 }
%sets = $gettok(%input,1,%del)
%raw = $gettok(%input,2,%del)
}
if (%sets > 12) { /dice 12 sets of dice maximum per roll $+ . | halt }
%checkset = 0
%multiply = 1
%modifier = 0
%total = $null
:begin
inc %checkset
if (%checkset > %sets) { goto final }
; Assign values to multiply and modifier variables
; Check values for erroneous size
if ($chr(42) isin %raw) { %multiply = $gettok(%raw,2,42) | %raw = $remtok(%raw,%multiply,42) }
if (+ isin %raw) { %modifier = $gettok(%raw,2,43) | %raw = $remtok(%raw,%modifier,43) }
else if (- isin %raw) { %modifier = $gettok(%raw,2,45) | %raw = $remtok(%raw,%modifier,45) | %modifier = %modifier * -1 }
if ($len(%modifier) > 6) { /dice That modifier is too large $+ . | halt }
if (%multiply > 20) { /dice That multiplier is too large $+ . | halt }
; Set number of sides on die and number of times it is rolled
; Check for erroneous values
if ($left(%raw,1) isnum) {
%sides = $gettok(%raw,2,100)
%times = $gettok(%raw,1,100)
}
else { %sides = $remove(%raw,d) | %times = 1 }
if ($len(%sides) > 6) { /dice There are too many sides on that die $+ . | halt }
if (%times > 1000) { /dice 1000 dice of any type maximum $+ . | halt }
%result = 0
%checkresult = 1
:rolldice
if (%checkresult <= %times) {
%result = %result + $rand(1,%sides)
%rstore = %result
inc %checkresult
goto rolldice
}
; Apply multiplier/modifiers, if any
if (%modifier != 0) { %result = %result + %modifier }
if (%multiply != 1) { %result = %result * %multiply }
%total = %total %result
goto begin
:final
; describe $chan throws the bones for $nick ( $+ $1- $+ ) and gets %total $+ .
/dice Rolling: ( $+ $1- $+ ) Results: %total $+ .
if (%duser = 1) { /msg $chan $nick rolls ( $+ $1- $+ ) and gets %total $+ . }
; Check to see type of roll.. standard d20 or to hit
if ( %tohit = 1 ) {
if ( %rstore = 20 ) {
/dice Critical Hit! Rerolling for hit..
/crit }
}
%tohit = 0
}
alias crit { %tohit = 1
/d 1d20 }
alias tohit { %tohit = 1
/dice Rolling Attack...
/d 1d20 }