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 

How do i set a random nickname

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


Joined: 25 Apr 2006
Posts: 18

PostPosted: Tue Jun 13, 2006 5:50 am    Post subject: How do i set a random nickname Reply with quote

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:
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"
 }
}
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue Jun 13, 2006 6:22 am    Post subject: Reply with quote

a random username from the current people on the channel?!
Code:
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 Very Happy
_________________
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...


Last edited by De Kus on Thu Jun 15, 2006 4:04 am; edited 2 times in total
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jun 13, 2006 11:58 am    Post subject: Reply with quote

De Kus wrote:
a random username from the current people on the channel?!
Code:
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 Very Happy

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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
chaokusc
Voice


Joined: 25 Apr 2006
Posts: 18

PostPosted: Tue Jun 13, 2006 4:50 pm    Post subject: Reply with quote

So the full code would be this ?

Code:
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:
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"
 }
}
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Wed Jun 14, 2006 7:56 pm    Post subject: Reply with quote

chaokusc wrote:
So the full code would be this ?

The code with Sir_Fz's changes. Smile
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
chaokusc
Voice


Joined: 25 Apr 2006
Posts: 18

PostPosted: Thu Jun 15, 2006 12:59 am    Post subject: Reply with quote

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

Code:
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 ^^
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Jun 15, 2006 3:47 am    Post subject: Reply with quote

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:
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. Smile Witha little help and an effort on your part your problem was solved. Smile
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
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