when I type !random 3 70 it display me a random number between 3 and 70
When you can build me one i be your slave

USG|Shinji wrote:Can somone build me a script that give me an randomnumber?
when I type !random 3 70 it display me a random number between 3 and 70
When you can build me one i be your slave
Code: Select all
bind pub - !random shins_rand
proc shins_rand {nick uhost hand chan text} {
set range1 [lindex [split $text] 0]
set range2 [lindex [split $text] 1]
set range1check [string trim $range1 "0123456789"]
set range2check [string trim $range2 "0123456789"]
if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} {
puthelp "PRIVMSG $chan :Usage: !random <min range> <max range>"
return
}
set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]
puthelp "PRIVMSG $chan :Your number is: $randnum"
}
Code: Select all
# Define the script
proc display:randnum {nick uh hand chan arg} {
# split the incoming var, for easier reading
set coup [split $arg]
#get a random number, using formular RAND = UPPER - (LOWER + 1)
set rand [rand [expr [lindex $coup 1] - [expr [lindex $coup 0] + 1]]]
#Now add LOWER + 1 on to the random number
set rand [expr $rand + [expr [lindex $coup 0] + 1]]
#print it to channel
puthelp "PRIVMSG $chan :Random $rand"
}
#bind the command
bind pub - "!random" display:randnum
And EG "!random [die] now" will cause his bot to die.ppslim wrote:/me pulls out his WHIP
EG "!random 3 70"Code: Select all
# Define the script proc display:randnum {nick uh hand chan arg} { # split the incoming var, for easier reading set coup [split $arg] #get a random number, using formular RAND = UPPER - (LOWER + 1) set rand [rand [expr [lindex $coup 1] - [expr [lindex $coup 0] + 1]]] #Now add LOWER + 1 on to the random number set rand [expr $rand + [expr [lindex $coup 0] + 1]] #print it to channel puthelp "PRIVMSG $chan :Random $rand" } #bind the command bind pub - "!random" display:randnum
Will prduce a random number between 3 and 70, excluding 3 and 70.
what can i do that my bot say a error to the one who use the command?strikelight wrote:USG|Shinji wrote:Can somone build me a script that give me an randomnumber?
when I type !random 3 70 it display me a random number between 3 and 70
When you can build me one i be your slaveThis is untested code.. but you get the idea..Code: Select all
bind pub - !random shins_rand proc shins_rand {nick uhost hand chan text} { set range1 [lindex [split $text] 0] set range2 [lindex [split $text] 1] set range1check [string trim $range1 "0123456789"] set range2check [string trim $range2 "0123456789"] if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} { puthelp "PRIVMSG $chan :Usage: !random <min range> <max range>" return } set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1] puthelp "PRIVMSG $chan :Your number is: $randnum" }
USG|Shinji wrote:what can i do that my bot say a error to the one who use the command?strikelight wrote:USG|Shinji wrote:Can somone build me a script that give me an randomnumber?
when I type !random 3 70 it display me a random number between 3 and 70
When you can build me one i be your slaveThis is untested code.. but you get the idea..Code: Select all
bind pub - !random shins_rand proc shins_rand {nick uhost hand chan text} { set range1 [lindex [split $text] 0] set range2 [lindex [split $text] 1] set range1check [string trim $range1 "0123456789"] set range2check [string trim $range2 "0123456789"] if {($range1 == "") || ($range2 == "") || ($range1check != "") || ($range2check != "")} { puthelp "PRIVMSG $chan :Usage: !random <min range> <max range>" return } set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1] puthelp "PRIVMSG $chan :Your number is: $randnum" }
( [17:59:20] <)Sarah> [16:00] Tcl error [shins_rand]: integer value too large to represent )
sorry for my bad english
Code: Select all
set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]
puthelp "PRIVMSG $chan :Your number is: $randnum"
Code: Select all
if {[catch {set randnum [expr [rand [expr ($range2 + 1) - $range1]] + $range1]}]} {
puthelp "PRIVMSG $chan :Please use a lower and proper range."
} else {
puthelp "PRIVMSG $chan :Your number is: $randnum"
}
USG|Shinji, there are a couple of questions/issues when writing such script.USG|Shinji wrote:Can somone build me a script that give me a random number?
when I type !random 3 70 it display me a random number between 3 and 70
When you can build me one i be your slave