Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ 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 page
Posted by
| Dmtheorist
(2 posts) 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? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 > 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 | Top |
|
Posted by
| Dmtheorist
(2 posts) 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! | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) 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 > 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 | 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.
12,231 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top