[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]  Trigger on matches based on a table
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Trigger on matches based on a table

You need to log onto the forum to reply or create new threads.

  [Refresh] Refresh page


Posted by Rene   (22 posts)  [Biography] bio
Date Wed 06 Dec 2017 06:21 AM (UTC)
Message
Is there a way to make a plugin that matches based on a table within the plugin?

I know I can do it by using '*' to match everything and then have the script check if it matches, the problem is if it does I want to omit it from output, and it doesn't seem right to have the script catching everything then putting it back in with a ColourNote if it did not match.

I know I can also do a regex that includes all of them, but I want to be able to simply add to the table later and have it start matching that as well.
Thanks.

(Meaning it should match a table
matchtable = { "There is a chair here", "You have a pot", Why are there no flowers?" }
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Wed 06 Dec 2017 06:53 PM (UTC)
Message
I don't think so.

Quote:
it doesn't seem right to have the script catching everything then putting it back in with a ColourNote if it did not match.

This is pretty much what I do.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Rene   (22 posts)  [Biography] bio
Date Reply #2 on Wed 06 Dec 2017 07:24 PM (UTC)
Message
Hmm, two things then, will it lose other changes to the colour from other colour triggers if the plugin is replacing the text?

Also, my reason for this is I want to check for aggressive lines by specific char names, so I want to be able to easily add more types of aggro lines or edit the table of char names I am worried about, so if the plugin can save these as a table and then check from there it will be simple to add or remove.
I was thinking now of having it build triggers using AddTrigger from a table that might allow me to not have to write individual triggers for each one and build the triggers from a table, any thoughts?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 06 Dec 2017 10:53 PM (UTC)

Amended on Wed 06 Dec 2017 11:42 PM (UTC) by Nick Gammon

Message
One approach is to make a variable on-the-fly from your table. For example, with this trigger:


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   match="@!my_trigger_list"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
ColourNote ("orange", "", [[Omitted line: %0]])</send>
  </trigger>
</triggers>



Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Then run this script in a function when you want to alter the items to be matched on:


matchtable = { "There is a chair here", "You have a pot", "Why are there no flowers?" }

local whatToMatch = { }
for k, v in ipairs (matchtable) do
  -- "escape" magic characters
  local fixed = string.gsub (v, "[%^%$%(%)%.%[%]%*%+%-%?{}\\]", "\\%1")
  table.insert (whatToMatch, fixed)
end -- for

SetVariable ("my_trigger_list", "^(" .. table.concat (whatToMatch, "|") .. ")$")


That changes the variable "my_trigger_list" used in the trigger. Basically it concatenates all the strings you want to match, allowing for "magic" regexp characters appearing in the string and escaping them.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Wed 06 Dec 2017 10:55 PM (UTC)
Message
An alternative approach would be to use AddTrigger to generate the triggers from your table. Put them into a group so you can easily delete the old ones (go through the group and delete each one) and then add in the new ones based on what is in the table.

- 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.


96 views.

You need to log onto the forum to reply or create new threads.

  [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]