This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Choose Random Nick From Channel

Help for those learning Tcl or writing their own scripts.
Post Reply
M
Molitov
Voice
Posts: 2
Joined: Tue Jan 30, 2007 8:50 am

Choose Random Nick From Channel

Post by Molitov »

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 =)
d
dwickie
Halfop
Posts: 76
Joined: Sat Aug 21, 2004 8:53 am
Location: /pub/beer

Post by dwickie »

Code: Select all

set nicks [chanlist $chan]
set randnick [lindex $nicks [rand [llength $nicks]]
M
Molitov
Voice
Posts: 2
Joined: Tue Jan 30, 2007 8:50 am

Post by Molitov »

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: Select all

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.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

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
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Also, $randnick will be printed as is since it is being enclosed by {}.

Code: Select all

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 :roll:
Last edited by Sir_Fz on Tue Jan 30, 2007 11:57 am, edited 1 time in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
Post Reply