Trigger from a dynamic list?

Posted by Dmtheorist on Wed 29 Oct 2008 02:51 PM — 4 posts, 16,315 views.

#0
I'm trying to figure out a way to display the names of all playerkillers (PKs) in red every time the name appears. In my MUD, the only (easy) way to determine who is a player killer is to use the command "killers," which results in an output similar to:

There are currently <x> player killers online:
<name 1> <name 2> <name 3> <etc>

Conceptually, I know I need to a) read the results of the "killers" command into a variable(/table?) and b) construct a trigger that will match if the player's name is included in this variable (e.g., if it's part of the string). Any suggestions as to the best way to do this?
Australia Forum Administrator #1
Something like this should work:


<triggers>
  <trigger
   enabled="y"
   group="Multi Line"
   lines_to_match="2"
   keep_evaluating="y"
   match="There are currently \d+ player killers online\:\n(.*)\Z"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

local names = {}

-- build names into table

for w in string.gmatch ("%1", "%a+") do
  table.insert (names, w)
end -- for

require "addxml"

if #names &gt; 0 then
  addxml.trigger {
    enabled = 'y',
    regexp = 'y',
    ['repeat'] = 'y',
    custom_colour = '17',
    sequence = '100',
    other_text_colour = 'red',
    match = '\\\\b(' .. table.concat (names, '|') .. ')\\\\b',
    name = 'pkillers',
    }
else
  DeleteTrigger ('pkillers')
end -- if

</send>
  </trigger>
</triggers>


I tested the above with:


/Simulate [[

There are currently 4 player killers online:
Neddie Seagon Fred Nurk John
]]


That added a trigger which matches on any of those names.

See http://mushclient.com/pasting for how to copy that into the client.
#2
Sweet! That did the trick! I tweaked the initial trigger, though, because the syntax I originally posted was incorrect. Here's an example of how "killers" actually outputs:

There are four players logged in:
roger, steve, amy, and anne

So, I changed the match criterion to:

There are \b.*? player killers logged in\:\n(.*)\Z

Now I have a timer set up to regularly update the trigger by sending the "killers" command (btw - is there a way to suppress the output of this command in the MUD while still having the trigger work?).

Thanks for the help!
Australia Forum Administrator #3
Probably the easiest way to do that is to make two triggers (a multi-line trigger can't omit from output), like this:


<triggers>

  <trigger
   enabled="y"
   lines_to_match="1"
   match="There are currently * player killers online:"
   omit_from_output="y"
   send_to="12"
   sequence="100"
  >
  <send>EnableTrigger ("capturePKs", true)</send>
  </trigger>

  <trigger
   lines_to_match="1"
   match="*"
   name="capturePKs"
   omit_from_output="y"
   send_to="12"
   sequence="100"
  >
  <send>

local names = {}

-- build names into table

for w in string.gmatch ("%1", "%a+") do
  table.insert (names, w)
end -- for

require "addxml"

if #names &gt; 0 then
  addxml.trigger {
    enabled = 'y',
    regexp = 'y',
    ['repeat'] = 'y',
    custom_colour = '17',
    sequence = '100',
    other_text_colour = 'red',
    match = '\\\\b(' .. table.concat (names, '|') .. ')\\\\b',
    name = 'pkillers',
    }
else
  DeleteTrigger ('pkillers')
end -- if

EnableTrigger ("capturePKs", false) -- disable ourselves

</send>
  </trigger>

</triggers>


The first trigger, which is always active, matches the line about "There are currently * player killers online:". This enables the second trigger. The second trigger, which matches anything, capture the player names and then disables itself, ready for next time.

Both triggers omit from output, so you don't see the matching lines.