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.
Help for those learning Tcl or writing their own scripts.
Reynaldo
Halfop
Posts: 54 Joined: Wed May 11, 2005 2:51 am
Post
by Reynaldo » Tue Jan 26, 2010 5:25 am
Sir_Fz wrote: You can use this proc, which is much faster:
Code: Select all
proc randomcolors str {
set str2 ""
foreach token [split $str ""] {
set rdm [expr {[rand 15]+1}]
if {$rdm < 10} { set rdm 0$rdm }
if {$token != " "} {
append str2 \003${rdm}$token\003
} {
append str2 $token
}
}
set str2
}
Bro Sir_Fz, how to make it with random background aswell? offcourse will never same color with background. Thanks alot
arfer
Master
Posts: 436 Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK
Post
by arfer » Tue Jan 26, 2010 12:31 pm
The part that matters in the script below is the proc pColorRandom which, when called with a <text> argument, will return the text with randomly coloured foreground/background. A while loop is used to ensure that the foreground color cannot be the same as the background color.
A public command with syntax !color <text> has been provided to demonstrate.
Code: Select all
bind PUB - !color pColorCommand
proc pColorCommand {nick uhost hand chan text} {
if {[llength [split [string trim $text]]] != 0} {
putserv "PRIVMSG $chan :[pColorRandom $text]"
} else {putserv "PRIVMSG $chan :usage !color <text>"}
return 0
}
proc pColorRandom {text} {
set fore [set back 00]
while {[string equal $fore $back]} {
set fore [format %02s [rand 16]]
set back [format %02s [rand 16]]
}
return \003${fore},$back$text\003
}
The following script behaves in a similar fashion but colors all the words of the <text> argument differently.
Code: Select all
bind PUB - !color pColorCommand
proc pColorCommand {nick uhost hand chan text} {
if {[llength [split [string trim $text]]] != 0} {
putserv "PRIVMSG $chan :[pColorRandom $text]"
} else {putserv "PRIVMSG $chan :usage !color <text>"}
return 0
}
proc pColorRandom {text} {
foreach word [split $text] {
set fore [set back 00]
while {[string equal $fore $back]} {
set fore [format %02s [rand 16]]
set back [format %02s [rand 16]]
}
lappend newtext \003${fore},$back$word\003
}
return [join $newtext]
}
I must have had nothing to do
Reynaldo
Halfop
Posts: 54 Joined: Wed May 11, 2005 2:51 am
Post
by Reynaldo » Thu Jan 28, 2010 11:09 pm
arfer wrote: The part that matters in the script below is the proc pColorRandom which, when called with a <text> argument, will return the text with randomly coloured foreground/background. A while loop is used to ensure that the foreground color cannot be the same as the background color.
A public command with syntax !color <text> has been provided to demonstrate.
Code: Select all
bind PUB - !color pColorCommand
proc pColorCommand {nick uhost hand chan text} {
if {[llength [split [string trim $text]]] != 0} {
putserv "PRIVMSG $chan :[pColorRandom $text]"
} else {putserv "PRIVMSG $chan :usage !color <text>"}
return 0
}
proc pColorRandom {text} {
set fore [set back 00]
while {[string equal $fore $back]} {
set fore [format %02s [rand 16]]
set back [format %02s [rand 16]]
}
return \003${fore},$back$text\003
}
The following script behaves in a similar fashion but colors all the words of the <text> argument differently.
Code: Select all
bind PUB - !color pColorCommand
proc pColorCommand {nick uhost hand chan text} {
if {[llength [split [string trim $text]]] != 0} {
putserv "PRIVMSG $chan :[pColorRandom $text]"
} else {putserv "PRIVMSG $chan :usage !color <text>"}
return 0
}
proc pColorRandom {text} {
foreach word [split $text] {
set fore [set back 00]
while {[string equal $fore $back]} {
set fore [format %02s [rand 16]]
set back [format %02s [rand 16]]
}
lappend newtext \003${fore},$back$word\003
}
return [join $newtext]
}
Both of the scripts doesnt working well, tested already bro arfer?
Code: Select all
bind PUB - !color pColorCommand
proc pColorCommand {nick uhost hand chan text} {
if {[llength [split [string trim $text]]] != 0} {
putserv "PRIVMSG $chan :[pColorRandom $text]"
} else {putserv "PRIVMSG $chan :usage !color <text>"}
return 0
}
proc pColorRandom {text} {
set str2 ""
foreach token [split $text ""] {
set rdm [expr {[rand 15]+1}]
set rdm1 [expr {[rand 15]+1}]
if {$rdm1 < 10} { set rdm1 0$rdm1 }
if {$rdm < 10} { set rdm 0$rdm }
if {$rdm == $rdm1} { set rdm1 [expr $rdm1+1]}
if {$token != " "} {
append str2 \003${rdm},${rdm1}$token\003
} {
append str2 $token
}
}
set str2
}
that's working well