| View previous topic :: View next topic |
| Author |
Message |
chaokusc Voice
Joined: 25 Apr 2006 Posts: 18
|
Posted: Tue Jun 13, 2006 5:50 am Post subject: How do i set a random nickname |
|
|
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 |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Tue Jun 13, 2006 6:22 am Post subject: |
|
|
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  _________________ 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 |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue Jun 13, 2006 11:58 am Post subject: |
|
|
| 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  |
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 |
|
 |
chaokusc Voice
Joined: 25 Apr 2006 Posts: 18
|
Posted: Tue Jun 13, 2006 4:50 pm Post subject: |
|
|
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 |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Wed Jun 14, 2006 7:56 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
chaokusc Voice
Joined: 25 Apr 2006 Posts: 18
|
Posted: Thu Jun 15, 2006 12:59 am Post subject: |
|
|
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 |
|
 |
Alchera Revered One

Joined: 11 Aug 2003 Posts: 3344 Location: Ballarat Victoria, Australia
|
Posted: Thu Jun 15, 2006 3:47 am Post subject: |
|
|
| 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. 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 |
|
| Back to top |
|
 |
|