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 

help wih colour
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Tue Jan 26, 2010 5:25 am    Post subject: Reply with quote

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
View user's profile Send private message
arfer
Master


Joined: 26 Nov 2004
Posts: 436
Location: Manchester, UK

PostPosted: Tue Jan 26, 2010 12:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
Reynaldo
Halfop


Joined: 11 May 2005
Posts: 54

PostPosted: Thu Jan 28, 2010 11:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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