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
➜ Lua
➜ AddTriggerEx / SetTriggerOption question
|
AddTriggerEx / SetTriggerOption question
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Cripsi
(4 posts) Bio
|
| Date
| Wed 16 Mar 2011 06:01 PM (UTC) Amended on Wed 16 Mar 2011 06:03 PM (UTC) by Cripsi
|
| Message
| I'm currently trying to write a plugin for the Discworld Mud that takes the output of:
There are six assassin player killers logged in:
Akeelah, Beale, Chosig, Effaxe, Haassasin and Oxygene
And adds those names to a trigger which then shows them in a highlighted colour on the output. I already have 6 client side triggers but I have to manually update each one with new names everytime a new person goes PK, for 6 different guilds, and this gets time consuming and annoying. I have written most of the plugin out, and it is converting the above into
assassinslist = akeelah|beale|chosig|effaxe|hassassin|oxygene
And will add new names without making duplicates everytime I run it. The only problem is converting it into a trigger, as I can do that from
AddTriggerEx("assassintrigger", assassinlist, "", 57, 16, 0, "", "", 12, 100)
but it only highlights one name per line, so if my output reads "Akeelah, Beale and Chosig are standing here." only Akeelah will be highlighed. To solve this in the client side triggers the trigger looks like:
((?<=^|\s|[)(akeelah|beale|chosig|effaxe|hassassin|oxygene)(?!\w))
But I can't get the AddTriggerEx or SetTriggerOption functions to work with those bits of text, and was wondering if anyone has any suggestions/advice or knows why this is and can tell me what would work so that all occuring names on one line will highlight?
Thanks in advance | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Wed 16 Mar 2011 11:09 PM (UTC) |
| Message
| I wouldn't be adding and removing triggers all the time - after all, you only need one trigger, right? It's just the things it matches on.
Use variables for this. You need a variable (eg. "assassinslist") and have that contain the names of the assassins, like this:
SetVariable ("assassinslist", "akeelah|beale|chosig|effaxe|hassassin|oxygene")
Now in the trigger just match on:
match = "(@!assassinslist)"
And check "expand variables".
And the variable is easy to keep maintained. Just have a table of assassins, and when you add or remove from it, regenerate the variable.
Example code:
-- this generates the variable with "|" between each name
function make_assassins_variable ()
local t = {}
-- generate numeric table:
for k, v in pairs (assassins) do
table.insert (t, k)
end -- for each one
-- make the variable
SetVariable ("assassinslist", table.concat (t, "|"))
end -- make_assassins_variable
-- make sure table exists
assassins = assassins or {}
-- add as required (this won't make duplicates because the same name will only be there once)
assassins ["akeelah"] = true
assassins ["beale"] = true
assassins ["chosig"] = true
assassins ["effaxe"] = true
make_assassins_variable ()
-- debug
print (GetVariable ("assassinslist")) --> effaxe|beale|chosig|akeelah
-- now remove one:
assassins ["akeelah"] = nil
-- and add another:
assassins ["oxygene"] = true
-- remake variable
make_assassins_variable ()
-- debug
print (GetVariable ("assassinslist")) --> effaxe|beale|chosig|oxygene
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Cripsi
(4 posts) Bio
|
| Date
| Reply #2 on Thu 17 Mar 2011 01:07 PM (UTC) |
| Message
| | Nick, you once again prove to be a genius, this solved the problem brilliantly. Thanks =D | | 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.
13,334 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top