AddTriggerEx / SetTriggerOption question

Posted by Cripsi on Wed 16 Mar 2011 06:01 PM — 3 posts, 13,958 views.

#0
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
Amended on Wed 16 Mar 2011 06:03 PM by Cripsi
Australia Forum Administrator #1
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



#2
Nick, you once again prove to be a genius, this solved the problem brilliantly. Thanks =D