alias dice {
var %print, %roll
var %counter = 1
var %howmany, %type, %rollcounter = 0
while (%counter <= $0) {
if ($pos($gettok($1-,%counter,32),d,1) != $null) {
if ($left($gettok($1-,%counter,32),1) == $chr(100)) set %howmany 1
else set %howmany $remove($left($gettok($1-,%counter,32),2),d)
set %type $mid($gettok($1-,%counter,32),$calc($pos($gettok($1-,%counter,32),d,1)+1),3)
while ($calc(%rollcounter + 1) <= %howmany) {
if (%type == 100) set %roll %roll $calc(10 * $rand(1,10))
else set %roll %roll $rand(1,%type)
set %rollcounter $calc(%rollcounter + 1)
}
say $gettok($1-,%counter,32) $+ : %roll
unset %roll
unset %howmany
unset %type
unset %rollcounter
}
else if ($gettok($1-,%counter,32) == 4) set %print %print d4: $rand(1,4) /
else if ($gettok($1-,%counter,32) == 6) set %print %print d6: $rand(1,6) /
else if ($gettok($1-,%counter,32) == 8) set %print %print d8: $rand(1,8) /
else if ($gettok($1-,%counter,32) == 10) set %print %print d10: $rand(1,10) /
else if ($gettok($1-,%counter,32) == 12) set %print %print d12: $rand(1,12) /
else if ($gettok($1-,%counter,32) == 20) set %print %print d20: $rand(1,20) /
else if ($gettok($1-,%counter,32) == 100) set %print %print d100: $calc($rand(1,10) * 10) /
else set %print %print Entry %counter (d $+ $gettok($1-,%counter,32) $+ ) invalid /
set %counter $calc(%counter + 1)
}
set %print $deltok(%print,-1,32)
if (%print) say %print
unset %print
}