| View previous topic :: View next topic |
| Author |
Message |
Molitov Voice
Joined: 30 Jan 2007 Posts: 2
|
Posted: Tue Jan 30, 2007 8:59 am Post subject: Choose Random Nick From Channel |
|
|
Hi!
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.)
Help appreciated =) |
|
| Back to top |
|
 |
dwickie Halfop
Joined: 21 Aug 2004 Posts: 76 Location: /pub/beer
|
Posted: Tue Jan 30, 2007 9:21 am Post subject: |
|
|
| Code: | set nicks [chanlist $chan]
set randnick [lindex $nicks [rand [llength $nicks]] |
|
|
| Back to top |
|
 |
Molitov Voice
Joined: 30 Jan 2007 Posts: 2
|
Posted: Tue Jan 30, 2007 10:09 am Post subject: |
|
|
thanks heaps dwickie =) (was a missing ] though =o)
now i have had a quick look at the forums on how to choose a random setting from a list.
| Code: |
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. |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Jan 30, 2007 10:32 am Post subject: |
|
|
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:
| Code: | 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. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue Jan 30, 2007 11:49 am Post subject: |
|
|
Also, $randnick will be printed as is since it is being enclosed by {}.
| Code: | 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  _________________ Follow me on GitHub
- Opposing
Public Tcl scripts
Last edited by Sir_Fz on Tue Jan 30, 2007 11:57 am; edited 1 time in total |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Tue Jan 30, 2007 11:52 am Post subject: |
|
|
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.) _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
|