Sending Alternate text colours per word to the mud...

Posted by David Berthiaume on Wed 20 Apr 2005 06:07 AM — 29 posts, 97,771 views.

#0
All right, What I'd like to do is send every other word in says, IC, and yells varying colours.

So, the ansi codes are:

^o - Light Black, A.K.A Dark Gray
^W - Bright White
^^ - Normal Text: Light Grey

I'd like to change each word a different colour.

First word, Bright White, then Light Grey, Then Dark Grey, then repeated per word.

I don't even know if this is possible, or what one would have to do to accomplish this.
USA #1
<aliases>
<alias
match="^(say|ic|yell)( \w.*\w)+.*$"
enabled="y"
echo_alias="y"
regexp="y"
ignore_case="y"
keep_evaluating="y"
sequence="100"
>
<send>%1 [the words, colorized]</send>
</alias>
</aliases>

That will capture it, what script language are we using? Since I'd hate to code it and then have it be the wrong one.
That regexp can be tweaked to suit needs (like getting rid of the leading space, but then it'd be every second wildcard, etc) but that too depends on the script routine. So, what are we coding it in?
#2
Coding in VBscript right now. I learned on it, and I know it more than I know Lua... Hard to switch over when you've had a couple of computer crashes to contend with and lose a lot of stuff.
#3
The saddest part about all of this. When I see the code, I'm gonna be like. DAMN: I shoulda known that!
USA #4
Actually, that regexp was wrong, since, the \ws should have been \bs, and the space infront is now going to be \s+
Im worried about hyphenated words, but I think that setup should work.
New regexp becomes:
^(say|ic|yell)([ \t]+\b.*\b)+.*$

And we're going to be using a script file (because cycling through an array is much easier than trying to figure out how many wildcards we have inside the trigger).

And this could still all change (the regexp will probably change at least once more, just for fun).
Amended on Wed 20 Apr 2005 06:55 AM by Flannel
#5
Something however seems to be missing...

Type: say Blah blah

Output: You say '[the words, colorized]'

Unless you haven't put up the code that is the words and colorized... Did I miss something?


EDIT: Oh yeah, additionally... There is also sayto <name> <string>

That'll probably have to be a seperate alias, which is fine, and should be easy enough to make once I have the script itself. It's just adding in another wildcard, no biggie
Amended on Wed 20 Apr 2005 07:03 AM by David Berthiaume
USA #6
Yeah, that trigger was script-less, it was just the trigger. I figured I might as well post that, since I needed to ask you what language anyway.

This is what I have thus far for the script (obviously it doesn't work).
The problem (as far as I can tell) is the trigger. Since it's not returning one word per wildcard. The commented lines (at the beginning) should (once everything works correctly) have one word per line.
I'm going to reread some of the basics of MC and scripts, since obviously I'm forgetting something (there are always 10 array pieces passed, regardless of how many wildcards there actually are?).
If that's true, then it looks like doing it via send to script may end up being more convenient (and feasible) anyway.


Option Explicit

Sub colorize (sName, sLine, aryWild)
  dim size
  dim Colored
  dim codes
'DEBUG TRIGGER
'  for i = LBound(aryWild) to UBound(aryWild)
'    note i & ": " & aryWild(i)
'  next
  
  codes = Array("^o","^W","^^") 'color codes
  size = UBound(aryWild) '1+3X+1?
  'except its length-1, so we dont need to 
  'subtract the 1 for the say/ic/yell
  Colored = aryWild(1)
  dim i
  For i = 2 to size Step 3
    'aryWild(i) whole thing
    'aryWild(i+1) whitespace
    'aryWild(i+2) word
    Colored = Colored & aryWild(i+1)
    Colored = Colored & codes(((i-1) mod 9)/(UBound(codes)+1))
    'append the color code (i-1) mod 9 is 0,3,6
    'divided by codes length (Ubound + 1) gives a corresponding
    'array element (0,1,2), this way you can simply change the
    'codes aray and not have to change anything else
    Colored = Colored & aryWild(i+2) 'append word
  Next
  Colored = Colored & aryWild(size) 'last bit
  
  Send Colored 'can't forget this
End Sub
#7
Something similar, I think what we're missing in this particular case is the split command...
sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
     for i=lbound (AutoCombo ) to ubound (AutoCombo )
      Select Case AutoCombo (i)
       case "rp" attack = "punch right"
       case "lp" attack = "punch left"
       case "s" attack = "sweep"
       case "r" attack = "roundhouse"
       case else attack = "" ' unknown attack type
      End Select
  if i = ubound (AutoCombo ) then
  world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Amended on Fri 22 Apr 2005 01:33 AM by David Berthiaume
#8
Did a little experimenting on my own with this. I don't know if it'll help. But here's what I got.

Sub colorize (sName, sLine, aryWild)
dim string, i
string = split (aryWild(1))
  for i = LBound(string) to UBound(string)
    note i & ": " & string(i)
  next

End Sub
Hope this helps a little bit atleast.


I searched the forums for one of my OLD postings with Autocombo. I knew that Lbound and Ubound were going to come into play with this, it was the rest I wasn't sure about. When you didn't put a split in there, it got me to thinking about the autocombo script Nick helped me write. I started fiddling with it. and I got it to note properly, I just do not know how to incorperate the split into the rest of your code you put up there. I think once that is done it will work very well.
Amended on Fri 22 Apr 2005 01:20 AM by David Berthiaume
#9
Ok, more playing around with
Sub colorize3 (sName, sLine, aryWild)
  dim size
  dim Colored
  dim codes
  dim string
string = split(aryWild(2))
  for i = LBound(string) to UBound(string)
  next
  
  codes = Array("^o","^W","^^")
  size = UBound(string) '1+3X+1?
  Colored = aryWild(1)
  dim i
  For i = 2 to size Step 3
    Colored = Colored & aryWild(i+1)
    Colored = Colored & codes(((i-1) mod 9)/(UBound(codes)+1))
    Colored = Colored & aryWild(i+2) 'append word
next
  Colored = Colored & arywild(2) 'last bit
  
  Note Colored 
End Sub


Still not working right. But getting closer.
#10
All righty... Got it working... Sorta...
Sub colorize3 (sName, sLine, aryWild)
dim size, Colored, codes, string
string = split(aryWild(2))
  for i = LBound(string) to UBound(string)
  next  
  codes = Array("^o","^W","^^") 'color codes
for i = LBound(codes) to UBound(codes)
next
  size = UBound(string) '1+3X+1?
  'except its length-1, so we dont need to 
  'subtract the 1 for the say/ic/yell
  Colored = aryWild(1)

  dim i
  For i = 1 to size Step 1
    Colored = Colored & " " & codes(((i-2) mod 7)/(UBound(codes)+1)) & string(i)
  Next
 Send Colored
  
End Sub
The problem as you'll see when you use it. It won't change every other word. Perhaps you can figure out where the error in the step is. I dunno. It's doing something funky, I don't understand that whole mod thing. That's probably where my error is. But I got it semi-working. More than it was before.
Amended on Fri 22 Apr 2005 05:08 AM by David Berthiaume
#11
Been working on this a LONG LONG time... Much more difficult this is, then I realized. I'll give an update later.

From what I've found out, Mod doesn't work as well as we hoped it would.
#12
Final Working Code. Thanks to my friend Nomad who helped me out
Sub colorize3 (sName, sLine, aryWild)
dim size, Colored, codes, String, i, x
Colored = aryWild(1)
string = split(aryWild(2))
  for x = LBound(string) to UBound(string)
  	next  
Size = UBound(string)
codes = Array("^W","^^","^o")
		for i = LBound(codes) to UBound(codes)
			Next
  For i = 1 to size Step 1
    Colored = Colored & " " & codes((i-1) mod (UBound(codes)+1)) & string(i)
  Next
	Colored = Colored & "^^"
send Colored 
End Sub
#13
Not sure on how to make this next alias work.

I got the say, ic, yell alias fine.

I need an alias that does:
sayto (characters name) (string)
USA #14
All you're doing is making the beginning thing different. You could reuse the script and just join the first and second thing (instead of ic the first thing is "sayto bob") in the script and then sent to the colorize routine.

Why do you have empty fors? You have two:
for x = LBound(string) to UBound(string)
next
and another with i, that do absolutely nothing.

You could change your colorize code to be a subroutine that doesn't send, and that doesn't worry about anything except coloring, then you could handle the specific i/o (including the prefix) outside of the colorize sub.
I guess a function would be easiest, since then you could return the string.
Actually, if you're going to do that, having the function itself figure out the splitting stuff might be best (pass it a string, it tokenizes it, adds color codes, and returns the new string).
Then you could use it whenever you wanted, in whatever context you wanted.
Amended on Mon 25 Apr 2005 08:33 PM by Flannel
#15
I tried that. Couldn't get it to work.

I need the alias to be sayto * *

I don't know enough about regular expressions to make it work.
USA #16
Are you only going to be using single spaces in between? If so, you could just use split. I suppose that would even work for multiples of spaces (except you'd skip a color, but that probably wouldnt be a problem).

Actually, here it is (as a function), provided that it only uses certain delimiters (you can specify) so a space and a tab in the same thing won't work. And that if you have duplicate spaces, you'll 'skip' a color (Youll have a space, a color code, another space, then another colorcode).


function colorize (sLine, sSplit)
dim codes, tokens
dim uCodes, uTokens 'lengths (UBound)
dim i
codes = array("^^","^o","^W")
tokens = split(sLine,sSplit)
uCodes = UBound(codes)
uTokens = UBound(tokens)
for i = 0 to uTokens
  tokens(i) = codes(i mod (uCodes+1)) & tokens(i)
next
colorize = join(tokens,sSplit)
end function
USA #17
Actually, this one is better, it uses a regexp:

To do what you want, you'll pass your string (to be colored) and the regexp: "\s*\w+\s*"
You will always have to pass the regexp, but you could easily hardcode that regexp into it (and remove the parameter) if that's all you'll ever be doing with this function.
By making this line:regEx.pattern = reSplit
and making reSplit be the regexp ("\s*\w+\s*")

function colorize (sLine, reSplit)
dim codes, colored
dim uCodes, i 'lengths (UBound)
dim regEx, Matches, Match
codes = array("^^","^o","^W")
uCodes = UBound(codes)
Set regEx = New RegExp
regEx.pattern = reSplit
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(sLine)
i = 0
colored = ""
for each Match in Matches
  colored = colored & codes(i mod (uCodes+1)) & Match
  i = i + 1
next
colorize = colored
end function
Amended on Mon 25 Apr 2005 10:06 PM by Flannel
#18
Well, I got sayto to work. Actually, my friend got it to work just fine.

Even got it to work embedded into the alias itself.


The problem now is it's dropping the punctuation on the last word. It doesn't drop it in the middle of the array though, just on the UBound word.
USA #19
Ah yes, punctuation.
Try this regexp:
"\s*\S+\s*"
Amended on Mon 25 Apr 2005 11:58 PM by Flannel
#20
Aliases with code embedded.
<aliases>
  <alias
   match="^(sayto)([ \t]+\b.*\b)+.*$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="10"
  >
  <send>dim string
Colored = "%1"
string = split("%2")
Size = UBound(string)
randomnumber = (Int((6-1+1)*Rnd+min))
select case randomnumber
	case "1"
		codes = Array("^o","^W","^^")
	case "2"
		codes = Array("^o","^^","^W")
	case "3"
		codes = Array("^W","^o","^^")
	case "4"
		codes = Array("^W","^^","^o")
	case "5"
		codes = Array("^^","^W","^o")
	case Else
		codes = Array("^^","^o","^W")
end select
Colored = Colored &amp; " " &amp; string(1)
	For i = 2 to size Step 1
		Colored = Colored &amp; " " &amp; codes((i-1) mod (UBound(codes)+1)) &amp; string(i)
	Next
Colored = Colored &amp; "^^"
Send Colored</send>
  </alias>
  <alias
   match="^(yell|say|ic)([ \t]+\b.*\b)+.*$"
   enabled="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="10"
  >
  <send>Colored = "%1"
string = split("%2")
Size = UBound(string)
randomnumber = (Int((6-1+1)*Rnd+min))
select case randomnumber
 case "1"
  codes = Array("^o","^W","^^")
 case "2"
  codes = Array("^o","^^","^W")
 case "3"
  codes = Array("^W","^o","^^")
 case "4"
  codes = Array("^W","^^","^o")
 case "5"
  codes = Array("^^","^W","^o")
 case Else
  codes = Array("^^","^o","^W")
end select
 For i = 1 to size Step 1
  Colored = Colored &amp; " " &amp; codes((i-1) mod (UBound(codes)+1)) &amp; string(i)
 Next
Colored = Colored &amp; "^^"
Send Colored</send>
  </alias>
</aliases>
Ok, but not sure where to put that in the current alias that I have.
USA #21
Suggest you get rid of the aliases you have, and make it a function (my second one, the regexp). Then your aliases become this simple:


<aliases>
  <alias
   match="^(say|ic|yell) (.*)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>send "%1 " &amp; colorizeRand("%2","\\s*\\S+\\s*") &amp; "^^"</send>
  </alias>
  <alias
   match="^sayto (\w+) (.*)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   keep_evaluating="y"
   sequence="100"
  >
  <send>send "sayto %1 " &amp; colorizeRand("%2","\\s*\\S+\\s*") &amp; "^^"</send>
  </alias>
</aliases>


And the code (since I renamed it colorizeRand to reflect the random color, you can change it back of course):

Randomize
function colorizeRand (sLine, reSplit)
dim codes, colored
dim uCodes, i 'length (UBound)
dim regEx, Matches, Match
'codes = array("^^","^o","^W")
'Start Randomization
i = Int(6*Rnd)
select case (i)
  case 0
    codes = Array("^o","^W","^^")
  case 1
    codes = Array("^o","^^","^W")
  case 2
    codes = Array("^W","^o","^^")
  case 3
    codes = Array("^W","^^","^o")
  case 4
    codes = Array("^^","^W","^o")
  case else 'we could do 5, but just incase
  'someone edits something they shouldn't
    codes = Array("^^","^o","^W")
end select
'End Randomization
uCodes = UBound(codes)
Set regEx = New RegExp
regEx.pattern = reSplit
regEx.IgnoreCase = True
regEx.Global = True
Set Matches = regEx.Execute(sLine)
i = 0
colored = ""
for each Match in Matches
  colored = colored & codes(i mod (uCodes+1)) & Match
  i = i + 1
next
colorizeRand = colored
end function

Amended on Tue 26 Apr 2005 12:15 AM by Flannel
#22
That works, except when you start putting numbers in there.

You say '2'
You say '1'
You say 'x 3'
You say '1 2'
You say '1 2 x'
You say '1 x 3 4'
You say 'x 2 3 x 5'
You say '1 x 3 4 x 6'
USA #23
What doesn't work? It works fine for me. What version of everything are you using? My latest one?

Edit:
Oh, and you'll probably want to uncheck "echo alias" once you get down to actually using it. Or SendNoEcho, or whatever other permutation of that.
Amended on Tue 26 Apr 2005 12:30 AM by Flannel
#24
Yes, I copy and pasted your aliases, and the code.

When you(I mean myself) type say 1 2 3 4 5 6 7

It does this:

You say '1 2 x 4 5 x 7'

EDIT: Apparently the x's show up depending upon thecolor codes. If you do 1 2 3 4 5 6 7 several times, the x blots out certain numbers depending on the color codes.
Amended on Tue 26 Apr 2005 12:32 AM by David Berthiaume
USA #25
say 1 2 3 4 5 6 7
say ^W1 ^o2 ^^3 ^W4 ^o5 ^^6 ^W7^^
You say "^W1 ^o2 ^^3 ^W4 ^o5 ^^6 ^W7^^"


Could it maybe be the color codes eating characters? Since, obviously that isn't a problem for me (my colors aren't parsed, obviously). It's sending what it's supposed to be sending.
USA #26
Yeah. So, it's a problem with the server (or a combination of color codes and numbers), and not the alias (you can see what you're sending as it echos and verify that they are infact being sent correctly, just echod incorrectly).
#27
Yeppers, nothing wrong with the code, it's a server issue with using the default color and a number together.
USA #28
You could send to execute (you WILL need to do world.execute, since otherwise you'll hit the VBScript execute) and then replace any ^^\d+ with ^^ \d+ with an alias (except, you would hit this alias again. So... I guess you'd need to change this alias to send something else and then make that one send it on completely).

Or you could just do it before sending internally in this alias. Or find another color code (or some other work around). I'm sure there are other options that the server introduces as well.