Help on Multiline Trigger

Posted by Yasha on Sat 05 Nov 2005 01:34 PM — 7 posts, 25,644 views.

#0
Hi I'm trying to set up a regular expression trigger to match when someone in the same room removes or wears eq. It would look something like this:


John wears hat,pants,shirt,socks,ring
 gloves,jacket,shoes,leggings,boots
 X,X,X


The number of lines would vary of course from player to player and after the first line, there is a space before the rest of the eq is listed. I looked at the help under regular expressions and it gave me this example:


Match: You are carrying:\n(([ ]{5}.*\n)*)\z for the following:



You are carrying:
     a magic mushroom
     a torch
     a dragonskin
     a bag
     recall scroll


I tried using this for my example as follows:


(.*) (wears|removes) (.*)\n(([ ]{1}.*\n)*)\z


but this didn't seem to work.

Can someone help me?

(Edited by Nick to show spacing).
Amended on Sat 05 Nov 2005 08:59 PM by Nick Gammon
Australia Forum Administrator #1
This seemed to work for me:


<triggers>
  <trigger
   enabled="y"
   lines_to_match="15"
   match="(.*) (wears|removes) .*\n(([ ].*\n)*)\n(?![ ])\z"
   multi_line="y"
   regexp="y"
   send_to="2"
   sequence="100"
  >
  <send>Found %0</send>
  </trigger>
</triggers>


You don't need the {1} part, that just means "1 of the preceeding thing" which is a bit redundant.

Trying this out on your test data I got:


John wears hat,pants,shirt,socks,ring
 gloves,jacket,shoes,leggings,boots
 X,X,X
Found John wears hat,pants,shirt,socks,ring
 gloves,jacket,shoes,leggings,boots
 X,X,X



Part in bold was the echo from the trigger showing it matched.
#2
Thank you for the quick repsonse. I have couple questions if you don't mind. How do I implement the "trigger" that you posted? Do I just take the parameters that you posted and check them in the appropriate boxes under "edit trigger" or can I copy/paste your trigger program somewhere and have that automatically trigger for me? I am more familiar with checking the appropriate boxes under the edit trigger dialog. What confuses me is what the "2" means after the "send_to=" and the "lines_to match=15" (since it could be less than 15).

Thank you again
Australia Forum Administrator #3
See:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4776


and


http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4777
Amended on Sat 05 Nov 2005 11:15 PM by Nick Gammon
#4
Thanks for the links. That really cleared things up! Unfortunately, the trigger didn't work (I think my example was too simple). I've pasted the exact text from the MUD which includes "and" near the end of the phrase to conclude what he is wearing...Can you change your original trigger to match this instead? Also, this is only part of the entire text and the number of lines can increase or decrease accordingly (as few as 2 lines and up to prolly 20 lines max). Thank you again for your help.


Oro wears Blue glove of master Conjurer labeled as < Y > <white glow>, Blue
 glove of master Conjurer labeled as < Y > <white glow>, Beautiful emerald
 necklace labeled as <YA> <white glow>, The Amberley Ankh labeled as <int|Y>
 <white glow> and a black cloak (evil glow) labeled as <YA> <white glow>
Amended on Sun 06 Nov 2005 02:35 AM by Nick Gammon
Australia Forum Administrator #5
When you say it didn't work... It matched for me, are you saying it didn't match? Or it didn't split up the stuff he was wearing? Doing that is the next step, the first thing is to collect what it is.

If you might have 20 lines change the 15 to 20. It should then match up to 20 lines.

To break up the text into individual "wear" items you need to scan for the comma and the "and". This amended trigger will do that.


<triggers>
  <trigger
   enabled="y"
   lines_to_match="20"
   match="(.*) (wears|removes) .*\n(([ ].*\n)*)\n(?![ ])\z"
   multi_line="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>matched = [[%0]]

-- get rid of the line breaks
matched = string.gsub (matched, "\\n", "")

-- change the final "and blah" to another comma
matched = string.gsub (matched, " and ", ",")

-- put into a table
wearing = {}

for w in string.gfind (matched, "[^,]+") do
  table.insert (wearing, Trim (w))
end -- for

-- display table
tprint (wearing)</send>
  </trigger>
</triggers>



When I run that on your test data it gives:


Oro wears Blue glove of master Conjurer labeled as < Y > <white glow>, Blue
 glove of master Conjurer labeled as < Y > <white glow>, Beautiful emerald
 necklace labeled as <YA> <white glow>, The Amberley Ankh labeled as <int|Y>
 <white glow> and a black cloak (evil glow) labeled as <YA> <white glow>
1="Oro wears Blue glove of master Conjurer labeled as < Y > <white glow>"
2="Blue glove of master Conjurer labeled as < Y > <white glow>"
3="Beautiful emerald necklace labeled as <YA> <white glow>"
4="The Amberley Ankh labeled as <int|Y> <white glow>"
5="a black cloak (evil glow) labeled as <YA> <white glow>"



Generated output in bold. This uses tprint which is in exampscript.lua, so you would need to make that your script file.

#6
Thanx! I will try this