Automatically colouring every letter

Posted by CordovaRules on Thu 15 Jun 2006 11:14 PM — 3 posts, 12,292 views.

#0
I'm trying to write some sort of code for mush client so that when I type chat it automatically changes the first letter to one color, second letter to another color and third letter to yet another color and resets at the beginning of each word.

I can do it in Z*grumble*mud and I can send you the script, but I can't figure out how to do it in Mushclient. Could you please help?


In that other program, I just put this...

#VAR chatstr {} {_nodef}
#FORALL %replace( %-1, " ", "|") {#VAR chatstr %additem( %concat( "&+W", %left( %i, 1), "&+w", %right( %left( %i, 2), 1), "&+L", %right( %i, 2)), @chatstr)}
chat %expandlist( @chatstr, " ")

Then every time I type chat it did what I needed it too.... could someone please help... I really prefer MushClient, and would like to use it instead.
Australia Forum Administrator #1
This alias will do it. Make sure you have Lua as the scripting language. If you don't want to do that make a small plugin with the alias in it, and make the plugin use Lua.


<aliases>
  <alias
   match="chat *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
function f ()
  local i = 1  -- current colour
  local colours = {
    "&amp;+W",
    "&amp;+w",
    "&amp;+L",
    -- more colours here
    }
  local max = table.getn (colours)  -- total number

  return function (s)
    if s == " " then  -- space resets to first colour
      i = 1
      return s
    end -- space

    if i &gt; max then
      i = 1
    end -- reached end

    local c = colours [i]  -- extract colour
    i = i + 1  -- update for next time through
    return c .. s  -- return colour code and letter
  end -- function
end -- f

Send ("chat " .. string.gsub ("%1", "[%%w ]", f ()))
</send>
  </alias>
</aliases>


Example:


chat hi there
You chat '&+Wh&+wi &+Wt&+wh&+Le&+Wr&+we'


The colours are in a table in the alias, you can add more by simply adding to the list. The ampersands look like &amp; in the XML code, but once you paste the alias into MUSHclient they will become simple & again.
Amended on Fri 16 Jun 2006 12:32 AM by Nick Gammon
#2
Thanks... works great!!!!