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.

How do i set a random nickname

Help for those learning Tcl or writing their own scripts.
Post Reply
c
chaokusc
Voice
Posts: 18
Joined: Tue Apr 25, 2006 5:57 am

How do i set a random nickname

Post by chaokusc »

When a user types !random it should post a random username in the string, except the bots name or the user who posted the command... but im unsure how to do it.
Any help is greatly appreciated.

Code: Select all

bind pub - !random pub_random
proc pub_random {nick uhost hand chan t} {
if {$t == ""} {
putserv "NOTICE $nick : Hi $nick, a random user is $randomuser"
 }
}
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

a random username from the current people on the channel?!

Code: Select all

set users [chanlist $chan]
if {[set total [llength $users]] < 3} {
   puthelp "NOTICE $nick :We are the only ones here!"
  return 0
}
set randomuser $nick
while {$randomuser == $nick || [isbotnick $randomuser]} {
   set randomuser [lindex $users [rand $total]]
}
The check for <3 just makes sure to not loop infinite, if the user and the bot are the only one in the channel :D
Last edited by De Kus on Thu Jun 15, 2006 4:04 am, edited 2 times in total.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

De Kus wrote:a random username from the current people on the channel?!

Code: Select all

set users [chanlist $chan]
if {[set total [llength $users]] < 3} {
   puthelp "NOTICE $nick :We are the only ones here!"
  return 0
}
set randomuser $nick
while {$randomuser != $nick && ![isbotnick $randomuser]} {
   set randomuser [lindex $users [rand $total]]
}
The counter to 10 just makes sure to not loop infinite, if the user and the bot are the only one in the channel :D
you set randomuser $nick then check if $randomuser != $nick in the while condition, the code will never enter the loop then. You probably meant to set randomuser "" instead of $nick.
c
chaokusc
Voice
Posts: 18
Joined: Tue Apr 25, 2006 5:57 am

Post by chaokusc »

So the full code would be this ?

Code: Select all

bind pub - !random pub_random
proc pub_random {nick uhost hand chan t} {
 if {$t == ""} {
  set users [chanlist $chan]
   if {[set total [llength $users]] < 3} {
    puthelp "NOTICE $nick :We are the only ones here $nick!"
   return 0
  }
 set randomuser $nick
  while {$randomuser != $nick && ![isbotnick $randomuser]} {
   set randomuser [lindex $users [rand $total]]
  }
  putserv "NOTICE $nick : Hi $nick, a random user is $randomuser"
 }
}
or

Code: Select all

bind pub - !random pub_random
proc pub_random {nick uhost hand chan t} {
 if {$t == ""} {
  set users [chanlist $chan]
   if {[set total [llength $users]] < 3} {
    puthelp "NOTICE $nick :We are the only ones here $nick!"
   return 0
  }
 set randomuser ""
  while {$randomuser != $nick && ![isbotnick $randomuser]} {
   set randomuser [lindex $users [rand $total]]
  }
  putserv "NOTICE $nick : Hi $nick, a random user is $randomuser"
 }
}
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

chaokusc wrote:So the full code would be this ?
The code with Sir_Fz's changes. :)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
c
chaokusc
Voice
Posts: 18
Joined: Tue Apr 25, 2006 5:57 am

Post by chaokusc »

It still did not work, but i tried it a little different.
Here is what i came up with and it works.

Code: Select all

bind pub - !random pub_random
proc pub_random {nick uhost hand chan t} {
 global botnick
  if {$t == ""} {
   set users [chanlist $chan]
   set rembot [lsearch $users $botnick]
   set mylist [lreplace $users $rembot $rembot]
   set listlength [llength $users]
   set myindex [rand $listlength]
   set target [lindex $users $myindex]
  if {[set total [llength $users]] < 3} {
   puthelp "NOTICE $nick :We are the only ones here $nick!"
  return 0
 }
  set randomuser $nick
   while {$randomuser != $nick && ![isbotnick $randomuser]} {
    set randomuser [lindex $users [rand $total]]
   }
  putserv "PRIVMSG $chan : Hi $nick, a random user is $target"
 }
}
Thanks for all the help ^^
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

chaokusc wrote:It still did not work, but i tried it a little different.
Here is what i came up with and it works.

Code: Select all

bind pub - !random pub_random
proc pub_random {nick uhost hand chan t} {
 global botnick
  if {$t == ""} {
   set users [chanlist $chan]
   set rembot [lsearch $users $botnick]
   set mylist [lreplace $users $rembot $rembot]
   set listlength [llength $users]
   set myindex [rand $listlength]
   set target [lindex $users $myindex]
  if {[set total [llength $users]] < 3} {
   puthelp "NOTICE $nick :We are the only ones here $nick!"
  return 0
 }
  set randomuser $nick
   while {$randomuser != $nick && ![isbotnick $randomuser]} {
    set randomuser [lindex $users [rand $total]]
   }
  putserv "PRIVMSG $chan : Hi $nick, a random user is $target"
 }
}
Thanks for all the help ^^
Excellent job. :) Witha little help and an effort on your part your problem was solved. :)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Post Reply