| View previous topic :: View next topic |
| Author |
Message |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Tue Jan 26, 2010 5:25 am Post subject: |
|
|
| Sir_Fz wrote: | You can use this proc, which is much faster:
| Code: | 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 |
|
| Back to top |
|
 |
arfer Master

Joined: 26 Nov 2004 Posts: 436 Location: Manchester, UK
|
Posted: Tue Jan 26, 2010 12:31 pm Post subject: |
|
|
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: |
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: |
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 |
|
| Back to top |
|
 |
Reynaldo Halfop
Joined: 11 May 2005 Posts: 54
|
Posted: Thu Jan 28, 2010 11:09 pm Post subject: |
|
|
| 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: |
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: |
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: | 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 |
|
| Back to top |
|
 |
|
|
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
|
|