mIRC Home    About    Download    Register    News    Help

Print Thread
B
buttsley
buttsley
B
I am using this script for random color, but I am having trouble adding a random background color as well to the text, can someone help me?

I tried to add " var %coltext = $rand(1,15),$rand(1,15)" but it didnt do anything

/cw /say $colwords($1-)

colwords {
; declare some variables
var %newstring = ""
var %entered = $1-
var %counter = 1
var %word = " "
while (%word != $null) {
; extract a word
%word = $gettok(%entered,%counter,32)
; make up a random number
var %coltext = $rand(1,15)
; build up the new phrase, with colour codes in
%newstring = %newstring $+ $chr(3) $+ %coltext $+ %word $+ $chr(1)
inc %counter
}
; put the spaces back in to our sentence
%newstring = $replace(%newstring,$chr(1),$chr(32))
return %newstring
}

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Use this in place of the one you tried
Code:
 var %foreground = $r(1,15)
while %foreground = %background {
var %background = $r(1,15)
}
var %coltext = $+(%foreground,$chr(44),%background)
 



Last edited by RusselB; 21/04/06 03:10 AM.
B
buttsley
buttsley
B
awesome thank you very much.

Is there an easy way to ensure it doesn't pick the same colors for bg and text color?

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
Code edited

B
buttsley
buttsley
B
it keeps coming out like ",a ,a ,a ,a ,a ,"

the A's are colored but there is no background, and the commas won't go away. I'm not sure how to fix it

This is using my original script with your $coltext part pasted in

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
an "oldschool" and ugly
Code:
alias ranfbcol {
  var %string1 = $replace($1-,$chr(32),$+($chr(1),$chr(0160)))
  echo -a %string1
  var %len = $len(%string1)
  var %toks = $gettok(%string1,0,160)
  var %i = 1
  var %x = 1
  var %newword = ""
  var %newstring = ""
  var %fore = ""
  var %back = ""
  :string
  var %newword = $gettok(%string1,%i,160)
  var %L = $len(%newword)
  :stringloop
  var %back = $r(0,15)
  :fore
  var %fore = $r(0,15)
  if (%fore == %back) { goto fore }
  var %newstring = $+(%newstring,$chr(3),%fore,$chr(44),%back,$mid(%newword,%x,1))
  inc %x
  if (%x <= %L) { goto stringloop }
  if (%x > %L) {
    var %x = 1 
    inc %i
    if (%i <= %toks) { goto string }
    if (%i > %toks) { goto end }
  }
  :end
  msg $active $replace(%newstring,$chr(160),$chr(32),$chr(1),$chr(32))
}

but it should work
not what I'd call "pretty" though

B
buttsley
buttsley
B
Thanks but I'm not even sure how to use that one frown

I am a very big newbie

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
ion a channel window or msg/query/dcc window type
/ranfbcol and some text

to use midline change it to return instead of msg $active
like this [code]
alias ranfbcol {
var %string1 = $replace($1-,$chr(32),$+($chr(1),$chr(0160)))
var %len = $len(%string1)
var %toks = $gettok(%string1,0,160)
var %i = 1
var %x = 1
var %newword = ""
var %newstring = ""
var %fore = ""
var %back = ""
:string
var %newword = $gettok(%string1,%i,160)
var %L = $len(%newword)
:stringloop
var %back = $r(0,15)
:fore
var %fore = $r(0,15)
if (%fore == %back) { goto fore }
var %newstring = $+(%newstring,$chr(3),%fore,$chr(44),%back,$mid(%newword,%x,1))
inc %x
if (%x <= %L) { goto stringloop }
if (%x > %L) {
var %x = 1
inc %i
if (%i <= %toks) { goto string }
if (%i > %toks) { goto end }
}
:end
return $replace(%newstring,$chr(160),$chr(32),$chr(1),$chr(32)) $+ $chr(15)
}
would be //say testing $ranfbcol(this thing) out
which would color only the "this thing" part of the string

Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
if you are putting the code in aliases rather than remotes
take the "alias ranfbcol {" off the start of the code

so its only
ranfbcol {

rather than
alias ranfbcol {


Link Copied to Clipboard