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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  AddTriggerEx / SetTriggerOption question
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

AddTriggerEx / SetTriggerOption question

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


Posted by Cripsi   (4 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Cripsi   (4 posts)  [Biography] 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
[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.


2,810 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 FutureQuest]