I have recently started .tcl and finding it fun to a certain degree..... How ever i have recently hit a block, google won't help and even search here didin't seem to help.
Is there anyway I can get my bot to select a random nick from the channel, and the put it in a PRIVMSG to the channel? (with other text and on command , but its just the grabbing the random nick that I need help with.)
proc text:attack { nick uhost hand chan text } {
set nicks [chanlist $chan]
set randnick [lindex $nicks [rand [llength $nicks]]]
set randmsg {
"fires a M16 at $randnick"
"throws a grenade at $randnick"
"rolls over $randnick with a tank"
}
putserv "PRIVMSG $chan :\001ACTION $randmsg"
}
that is the code so far and at the moment the bot just comes up with in IRC
[23:05:01] -Action- Tehbot
no errors in party line or anything
just a blank action.
Quite obviously, to be honest, since the first character within randmsg is a newline. And since the irc-protocol is newline-terminated, this means the next few rows will be treated separate commands - not part of the privmsg. You probably want something like this:
set randmsg [list "fires a M16 at $randnick" "throws a grenade at $randnick" "rolls over $randnick with a tank"]
set action [lindex $randmsg [rand [llength $randmsg]]]
And then use $action instead of $randmsg when you wish to send a random attack.
proc text:attack { nick uhost hand chan text } {
set nicks [chanlist $chan]
set randnick [lindex $nicks [rand [llength $nicks]]]
set randmsg [list \
"fires a M16 at $randnick" \
"throws a grenade at $randnick" \
"rolls over $randnick with a tank"]
set action [lindex $randmsg [rand [llength $randmsg]]]
putserv "PRIVMSG $chan :\001ACTION $action\001"
}
Edit: Indeed, I somehow missed it in your post nml375
Last edited by Sir_Fz on Tue Jan 30, 2007 11:57 am, edited 1 time in total.
I would still suggest building proper lists using the "list" command, rather than trying to create it by hand. (My example above also solves the problem with not evaluating $randnick.)