Some about triggers...

Posted by Madjack on Tue 10 Jan 2006 09:53 AM — 2 posts, 13,391 views.

Ukraine #0
1. ANSI Colours.
How i can get to lua script full coded ANSI line from mud, when trigger fires? For example when trigger fires on line "Almo tells you: Hey", where "Almo tells you:" - has white color, and "Hey" - has red color. And calls lua function:

function test_trigger( name, line, wildcards, styles )
...
AnsiNote( line );
...
end;

test_trigger function notes single color line. I need to get full coded ANSI line from mud. So, i need call AnsiNote( line ) and get same colors at the output.

2. Multi-Line Triggers from lua.
How i can create multi-line trigger from lua?

3. How i can replace text in mud output?

Thanks.
Australia Forum Administrator #1
Quote:

How i can get to lua script full coded ANSI line from mud, when trigger fires?


A scripted trigger function like this will do it. The "styles" argument has all the colour information in it for each style run.


function mytrigger (name, line, wildcards, styles)

  for k, v in ipairs (styles) do
    ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                v.text)
  end -- for loop
  Note ""

end -- mytrigger


Quote:

How i can create multi-line trigger from lua?


Create a trigger in the usual way, then use SetTriggerOption to set these fields:

multi_line = true
lines_to_match = 10 -- or whatever

For example:


AddTrigger("triggername", "attacks", "flee", 
          trigger_flag.Enabled + trigger_flag.RegularExpression, 
          custom_colour.Custom15, 0, "", "")
SetTriggerOption ("triggername", "multi_line", 1)
SetTriggerOption ("triggername", "lines_to_match", 10)


Quote:

How i can replace text in mud output?


You could omit the original line from the output and then do a "Replace" (or string.gsub) on the line to change the text in it.

If you are confident the text will all be in the same style (ie. the same colour) then you could do it with a modification of the earlier example:


function mytrigger (name, line, wildcards, styles)

  for k, v in ipairs (styles) do
    v.text = string.gsub (v.text, "Exits", "Ways to go")
    ColourTell (RGBColourToName (v.textcolour), 
                RGBColourToName (v.backcolour), 
                v.text)
  end -- for loop
  Note ""

end -- mytrigger


This will change "Exits" to "Ways to go" if it occurs inside a style.