on 1:text:?dice*:*: {
  /msg $nick The formula for rolling dice is: [number of sets]<spacebar>[number of dice][d][number of sides][+/-][modifier][x][multiplier].
  /msg $nick The "d" and number of sides are mandatory; the other parameters are optional.
  /msg $nick Examples:  To roll one six-sided die, you would type "d6" or "1d6".
  /msg $nick To roll 5 six-sided dice and get the results added together, it would be "5d6".  To roll 3 sets of three four-sided dice, you'd type "3<spacebar>3d4".
  /msg $nick You can also add modifiers (positive or negative) and multipliers.  For example, "1d6+8", or "3<spacebar>1d10-2x5". *** End of Instructions ***
}

;--------------------------------------------------------------------------------------------------
;  BoneDevil mIRC dice roller v1.0
;  1997-98 Aaron Richards
;  Email questions or problems to Hellbender@geocities.com
;--------------------------------------------------------------------------------------------------
on 1:text:*d*:#: {
  set %screen a b c e f g h i j k l m n o p q r s t u v w y z
  set %x 1
  :scan
  if ($gettok(%screen,%x,32) isin $1-) { /halt }
  inc %x 1
  if ($gettok(%screen,%x,32) != $null) { goto scan }
  :prestart
  if (($count($1-,d) > 1) || ($count($1-,+) > 1) || ($count($1-,-) > 1) || ($count($1-,x) > 1)) { /msg $chan Too many parameters $nick $+ . | /halt }
  if (d isin $1) { /set %raw $1 | /set %sets 1 }
  else if (d isin $2)  { /set %raw $2 | /set %sets $1 }
  if (%sets !isnum) { /msg $chan %sets is not a valid number $nick $+ . | /halt }
  if (%sets > 12) { /msg $chan 12 sets of dice maximum per roll $nick $+ . | /halt }
  set %checkset 0
  %multiply = 1
  %modifier = 0
  :begin
  inc %checkset 1
  if %checkset > %sets goto final
  %result = 0
  :filter1
  if (x isin %raw) { set %multiply $gettok(%raw,2,120) | set %raw $remtok(%raw,%multiply,120) }
  if (+ isin %raw) { set %modifier $gettok(%raw,2,43) | set %raw $remtok(%raw,%modifier,43) }
  else if (- isin %raw) { set %modifier $gettok(%raw,2,45) | set %raw $remtok(%raw,%modifier,45) | set %modifier - $+ %modifier }
  if (%modifier !isnum) { /msg $chan %modifier is not a valid number $nick $+ . | /halt }
  if (%multiply !isnum) { /msg $chan %multiply is not a valid number $nick $+ . | /halt }
  if ($len(%modifier) > 6) { /msg $chan That modifier is too large $nick $+ . | /halt }
  if (%multiply > 20) { /msg $chan That multiplier is too large $nick $+ . | /halt }
  :filter2
  if ($left(%raw,1) isnum) {
    set %sides $gettok(%raw,2,100)
    set %times $gettok(%raw,1,100)
  }
  else { %sides = $remove(%raw,d) | %times = 1 }
  if (%sides !isnum) { /msg $chan %sides is not a valid number $nick $+ . | /halt }
  if ($len(%sides) > 6) { /msg $chan There are too many sides on that die $nick $+ . | /halt }
  if (%times !isnum) { /msg $chan %times is not a valid number $nick $+ . | /halt }
  if (%times > 1000) { /msg $chan 1000 dice of any type maximum $nick $+ . | /halt }
  set %checkresult 0
  :rolldice
  inc %checkresult 1
  if %checkresult > %times goto process
  else { %result = %result + $rand(1,%sides) | goto rolldice }
  :process
  if (%modifier != 0) { %result = %result + %modifier }
  if (%multiply != 1) { %result = %result * %multiply }
  set %total %total %result
  goto begin
  :final
  /describe $chan throws the bones for $nick ( $+ $1- $+ ) and gets %total $+ .
  /unset %total
}

