[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Trigger from a dynamic list?

Trigger from a dynamic list?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Dmtheorist   (2 posts)  [Biography] bio
Date Wed 29 Oct 2008 02:51 PM (UTC)
Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (22,991 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 29 Oct 2008 10:28 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dmtheorist   (2 posts)  [Biography] bio
Date Reply #2 on Thu 30 Oct 2008 12:28 AM (UTC)
Message
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!
[Go to top] top

Posted by Nick Gammon   Australia  (22,991 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Thu 30 Oct 2008 02:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


10,721 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]