# Dice Roll v1.0 by leadZERO # This script is public domain, however if you modify/change it please # give me credit for the initial code. Also if you use it drop me a # message, I would love to know my work didn't go to waste. This is my # first attempt at making a script available for public use... # # This should work with all v1.3 bots, and if it works on others let me # know. # # Syntax: !r xDy<+z> # If you do something like "!r 4d6" it will do 4 rolls of a 6 sided die. # If you do something like "!r 4d6+3" it will do the 4 rolls of a six # sided die, but also add them all together and add in the 3 modifier. # What would you like to be the channel command to roll the dice? ie !roll, roll. set pubr "!r" # What would you like the PRIVMSG command to roll be? set msgr "!r" bind pub -|- $pubr pub_roll bind msg -|- $msgr msg_roll proc pub_roll {nick userhost hand chan text} { if {([lindex $text 0] == "") || (![string match *d* $text] && ![string match *D* $text])} { puthelp "NOTICE $nick :Usage \"!d D\" With x being the number of dice, and y being the number of sides per die." return 0 } set com [lindex $text 0] set length [string length $com] set dpos [string first d $com] if {$dpos == -1} { set dpos [string first D $com] } if {[string match *+* $text]} { set mpos [string first + $text] set mod 1 } else { set mod 0 } if {[string match *-* $text]} { puhelp "NOTICE $nick :Sorry the subtraction modifier isn't working at the present time." return 0 } if {$mod == "0" } { set numdice [string range $com 0 [expr ${dpos}-1]] set numside [string range $com [expr ${dpos}+1] end] putcmdlog "<<$nick>> !$hand! Dice Roll: $chan $text" for {set x 0} { $x < $numdice } {incr x} { append rollist "[expr [rand $numside] + 1] " } putserv "PRIVMSG $chan :Rolls for \002$numdice\002 dice at \002$numside\002 sides per die: \002$rollist" return 0 } else { set numdice [string range $com 0 [expr ${dpos}-1]] set numside [string range $com [expr ${dpos}+1] [expr ${mpos}-1]] set modif [string range $com $mpos end] for {set x 0} { $x < $numdice } {incr x} { set roll [expr [rand $numside]+1] append rollis "$roll " append rlwm "$roll+" } set rlwma [string trimright $rlwm +] set rollist [string trimright $rollis] putcmdlog "<<$nick>> !$hand! Dice Roll: $chan $text" putserv "PRIVMSG $chan :Rolls, and total, for \002$numdice\002 dice at \002$numside\002 sides per die and a modifier of \002$modif\002:" putserv "PRIVMSG $chan : \002Rolls\002: ($rollist) \002Total(w/modifier)\002: [expr ${rlwma}${modif}]" } } proc msg_roll {nick userhost hand text} { if {([lindex $text 0] == "") || (![string match *d* $text] && ![string match *D* $text])} { puthelp "PRIVMSG $nick :Usage \"!d D\" With x being the number of dice, and y being the number of sides per die." return 0 } set com [lindex $text 0] set length [string length $com] set dpos [string first d $com] if {$dpos == -1} { set dpos [string first D $com] } if {[string match *+* $text]} { set mpos [string first + $text] set mod 1 } else { set mod 0 } if {[string match *-* $text]} { puhelp "PRIVMSG $nick :Sorry the subtraction modifier isn't working at the present time." return 0 } if {$mod == "0" } { set numdice [string range $com 0 [expr ${dpos}-1]] set numside [string range $com [expr ${dpos}+1] end] putcmdlog "<<$nick>> !$hand! Dice Roll: MSG $text" for {set x 0} { $x < $numdice } {incr x} { append rollist "[expr [rand $numside] + 1] " } putserv "PRIVMSG $nick :Rolls for \002$numdice\002 dice at \002$numside\002 sides per die: \002$rollist" return 0 } else { set numdice [string range $com 0 [expr ${dpos}-1]] set numside [string range $com [expr ${dpos}+1] [expr ${mpos}-1]] set modif [string range $com $mpos end] for {set x 0} { $x < $numdice } {incr x} { set roll [expr [rand $numside]+1] append rollis "$roll " append rlwm "$roll+" } set rlwma [string trimright $rlwm +] set rollist [string trimright $rollis] putcmdlog "<<$nick>> !$hand! Dice Roll: MSG $text" putserv "PRIVMSG $nick :Rolls, and total, for \002$numdice\002 dice at \002$numside\002 sides per die and a modifier of \002$modif\002:" putserv "PRIVMSG $nick : \002Rolls\002: ($rollist) \002Total(w/modifier)\002: [expr ${rlwma}${modif}]" } }