egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Choose Random Nick From Channel

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Molitov
Voice


Joined: 30 Jan 2007
Posts: 2

PostPosted: Tue Jan 30, 2007 8:59 am    Post subject: Choose Random Nick From Channel Reply with quote

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
View user's profile Send private message
dwickie
Halfop


Joined: 21 Aug 2004
Posts: 76
Location: /pub/beer

PostPosted: Tue Jan 30, 2007 9:21 am    Post subject: Reply with quote

Code:
set nicks [chanlist $chan]
set randnick [lindex $nicks [rand [llength $nicks]]
Back to top
View user's profile Send private message
Molitov
Voice


Joined: 30 Jan 2007
Posts: 2

PostPosted: Tue Jan 30, 2007 10:09 am    Post subject: Reply with quote

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
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Jan 30, 2007 10:32 am    Post subject: Reply with quote

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
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jan 30, 2007 11:49 am    Post subject: Reply with quote

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 Rolling Eyes
_________________
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
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Tue Jan 30, 2007 11:52 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber