|
Torin Novice
Joined: 16 Apr 2008 Posts: 37
|
Posted: Tue May 24, 2011 3:01 pm
[3.34] Pattern Matching String List Priority? |
I've got one trigger that I'm trying to use to capture every attack message with and parse out the mob name. Here are the 2 relevant message that it cannot parse correctly.
You obliterate A Dragon Warrior with your pierce.
You massacre A Dragon Warrior to small fragments with your pierce.
I've tried a few triggers...
Code: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {to small fragments|see stars with a terrific wallop from your|}{ |}{|with your} {slice|pierce|hit|slash|crush|hack}.$ |
Which divides it up like this:
"You" "obliterate" "A Dragon Warrior" "with your" "pierce".
or..
"You" "massacre" "A Dragon Warrior to small fragments" "with your" "pierce".
Code: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {to small fragments with your|with your|see stars with a terrific wallop from your} {slice|pierce|hit|slash|crush|hack}.$ |
Which divides it up like this:
"You" "obliterate" "A Dragon Warrior" "with your" "pierce".
or..
"You" "massacre" "A Dragon Warrior to small fragments" "with your" "pierce".
Code: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {to small fragments|see stars with a terrific wallop from your|}{ |}{| with your} {slice|pierce|hit|slash|crush|hack}.$ |
No pattern match...
or..
"You" "massacre" "A Dragon Warrior" "to small fragments" "with your" "pierce".
Regardless, I cannot find 1 single pattern that will match. I can't find any documentation that might allow you force a priority order for matching against a string list. It doesn't seem to care the order of the list, it will always match "A Dragon Warrior to small fragments with your" as "A Dragon Warrior to small fragments" "with your" if you include both "to small fragments with your" and "with your" in the string list. I'm really trying to avoid having 2 separate triggers for this, as it seems insane that you can't force this to work. I could provide more examples, but hopefully I've made my point. If you allow for blank values in the string list to accommodate the different patterns, it seems to incline to use those empty values and letting the (*) grab what would normally be taken by a possible string list value. |
|
Last edited by Torin on Tue May 24, 2011 6:27 pm; edited 1 time in total |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Tue May 24, 2011 4:51 pm |
All the examples you have included always have "with your" although I see one of the lines in the string lists says "from your", I'd be inclined to test the following:
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*){to small fragments|see stars with a terrific wallop|} {from|with} your {slice|pierce|hit|slash|crush|hack}.$
This assumes each line always has a with your or from your in it which itself follows the multi word mob name with either nothing or an extra phrase.
You obliterate A Dragon Warrior with your pierce.
You massacre A Dragon Warrior to small fragments with your pierce.
You make A Dragon Warrior see stars with a terrific wallop from your slash.
All the above examples tested as working with the given pattern, note the lack of space between (*) and the following string list in the pattern, meaning you will have to process %1 with a trim so use something along the lines of #var mobname %trim(%1) in the script portion of the trigger.
If this fails other combat lines then provide those as examples so the trigger pattern can be refined. |
|
_________________ Taz :) |
|
|
|
Torin Novice
Joined: 16 Apr 2008 Posts: 37
|
Posted: Tue May 24, 2011 5:02 pm |
Ah, didn't even think to split up "from" and "your", good thinking.
Although I'm not sure all possible messages can be lumped together into one trigger, here they are, in case you can think of a way..
Your tremendous pierce sends gouts of blood and gore showering from A Dragon Warrior.
A Dragon Warrior's bones crumble under your terrific pierce.
Your pierce makes A Bushi Guard think twice about his continued existence.
You make An Elite Guard see stars with a terrific wallop from your pierce.
You remove chunks of flesh from A Dragon Warrior with your pierce.
You obliterate A Dragon Warrior with your pierce.
You massacre A Dragon Warrior to small fragments with your pierce.
That isn't all of them, but it covers the range I'm capable of hitting, so it should suffice. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Tue May 24, 2011 5:02 pm |
Does this pattern work?
Code: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {to small fragments |see stars with a terrific wallop |}{with|from} your {slice|pierce|hit|slash|crush|hack}.$. |
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Tue May 24, 2011 5:04 pm |
and no, those will not easily fit into one trigger... not easily, you have three basic sentance structures though.
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
Torin Novice
Joined: 16 Apr 2008 Posts: 37
|
Posted: Tue May 24, 2011 5:52 pm |
Taz wrote: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*){to small fragments|see stars with a terrific wallop|} {from|with} your {slice|pierce|hit|slash|crush|hack}.$ |
This: You make A Dragon Warrior see stars with a terrific wallop from your pierce.
Gets processed as: "You" "make" "A Dragon Warrior see stars with a terrific wallop" "from" "your" "pierce".
This: You massacre A Dragon Warrior to small fragments with your pierce.
Gets processed as: "You" "massacre" "A Dragon Warrior to small fragments" "with" "your" "pierce".
The rest process fine, but the problem is, when given the chance, the trigger is opting to lump the "to small fragments" into the *, and opt out of the {to small fragments|see stars with a terrific wallop|} string list, because it can.
shalimar wrote: |
^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {to small fragments |see stars with a terrific wallop |}{with|from} your {slice|pierce|hit|slash|crush|hack}.$ |
Same here.. |
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Tue May 24, 2011 7:02 pm |
Sorry about that I forgot about the * being greedy and grabbing what it can until it no longer matches, that whole string list can be removed from the pattern.
Trigger Pattern: ^You {miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make} (*) {from|with} your {slice|pierce|hit|slash|crush|hack}.$
Trigger Code: #print %remove("see stars with a terrific wallop",%remove("to small fragments",%1))
It isn't particularly pretty but if you are solely after the mob name then that is what you get. If there are many more of these to match then put them in a variable and do a #FORALL. |
|
_________________ Taz :) |
|
|
|
Torin Novice
Joined: 16 Apr 2008 Posts: 37
|
Posted: Tue May 24, 2011 7:35 pm |
Yeah, that's essentially what I've got it doing now, I'm just using %replace instead, but I guess that is cleaner. Still, not pretty, stupid greedy *. I'm guessing there really is no way around it when you've got a string list with a blank value following an *.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed May 25, 2011 1:08 am |
not without breaking down and doing a true regex pattern... but i am no good at those.... have you thought about just having multiple triggers?
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
T0rin Beginner
Joined: 27 Dec 2008 Posts: 14
|
Posted: Wed May 25, 2011 2:25 pm |
Yeah, multiple triggers would be easier, I'm just trying to combine as much as possible, where possible, to cut down on performance issues, which I've got more than enough of. It's more of an issue of principle than anything, it seems like I _should_ be able to do it in one trigger, except for the fact that * in a pattern makes it grab as much as possible, which in this case is simply counter-productive. I guess a second trigger is no more of a performance hit than processing multiple %remove functions when it does trigger.
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed May 25, 2011 2:57 pm |
In regex:
Code: |
^You? (?:miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make) (.*?) (?:to small fragments |see stars )?with (?:a terrific wallop from )?your (?:slice|pierce|hit|slash|crush|hack).$[ |
If you need to add other elements but are unsure, let me know and I'll help you out with it. This is, I believe, the most efficient way you're going to be able to pull off what you want to do. |
|
|
|
T0rin Beginner
Joined: 27 Dec 2008 Posts: 14
|
Posted: Wed May 25, 2011 3:10 pm |
charneus wrote: |
In regex:
Code: |
^You? (?:miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make) (.*?) (?:to small fragments |see stars )?with (?:a terrific wallop from )?your (?:slice|pierce|hit|slash|crush|hack).$[ |
If you need to add other elements but are unsure, let me know and I'll help you out with it. This is, I believe, the most efficient way you're going to be able to pull off what you want to do. |
Looks good, and it works! I think I'll have to read some on regexp, as it seems to make the editor notably more powerful when caught in situations such as these. Thank you.
Edit: Also charneus, see if you can take a stab at a trigger that will work with all of these messages. To start with, I intentionally was only using those with equivalent sentence structure, but my next goal will be to try to accommodate every possible message in 1 trigger.
Your tremendous pierce sends gouts of blood and gore showering from A Dragon Warrior.
A Dragon Warrior's bones crumble under your terrific pierce.
Your pierce makes A Dragon Warrior think twice about his continued existence.
You make A Dragon Warrior see stars with a terrific wallop from your pierce.
You remove chunks of flesh from A Dragon Warrior with your pierce.
You obliterate A Dragon Warrior with your pierce.
You massacre A Dragon Warrior to small fragments with your pierce.
I'm reading up on regexp and will try it myself, but I figure a practiced hand will have a much better shot at it, since the structure of the first 3 vary greatly from the last 4. |
|
|
|
T0rin Beginner
Joined: 27 Dec 2008 Posts: 14
|
Posted: Wed May 25, 2011 4:23 pm |
Seems like I figured it out....
Code: |
^(?:You|Your|(.*?))(?:'s bones crumble under your terrific)? (?:tremendous|slice|pierce|hit|slash|crush|hack|miss|utterly annihilate|remove chunks of flesh from|obliterate|massacre|make) ?(?:slice|pierce|hit|slash|crush|hack|makes)?(?: sends gouts of blood and gore showering from)? ?(?:(.*?)) ?(?:to small fragments |see stars |think twice about )?(?:his|her|its|with)?(?: continued existence| a terrific wallop from )? ?(?:your)? ?(?:slice|pierce|hit|slash|crush|hack)?.?$ |
Probably messier than it needs to be, but for my first venture into regexp I guess it's not all bad.
Just have to check if %1!="" to decide whether to use %1 or %2, but otherwise, it's good. :)
Edit: Heh, seems like it is now catching other player's attacks, not just my own, because of the (.*?) I put in the beginning... wonder if there is some way around that...
Edit: Aha, my own attack messages from the mud are colored a specific way, so I used that to limit it to only my attacks. |
|
Last edited by T0rin on Wed May 25, 2011 8:24 pm; edited 1 time in total |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Wed May 25, 2011 5:20 pm |
For starters, you can change the You? in my trigger to just You (since I thought it could contain 'Your', but I was mistaken in the syntax anyway).
Second, your code definitely is messier than it needs to be, but you're attempting to learn, which is what I started out with. I had messy codes for a while myself, then I learned how to make them more efficient. I'm a bit busy right now (read, in excruciating pain right now...) so I'll have to help rewrite the regex later. Look up the program regexr. It's what I use when testing my regular expressions, and it's quite a handy tool, not to mention it teaches you a bit. Also, look up regex cheat sheets. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed May 25, 2011 8:08 pm |
Quote: |
I guess a second trigger is no more of a performance hit than processing multiple %remove functions when it does trigger.
|
a lot faster, actually. More triggers generally means each one's going to have relatively simpler patterns which means the trigger parser can more quickly tell if a trigger fails or not. The more plain text you include, the faster your trigger will become (your regex trigger pattern is horribly slow, fyi). |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4692 Location: Pensacola, FL, USA
|
Posted: Wed May 25, 2011 8:15 pm |
Yea, i have taken the route of using several single line patterns that all run the same event.
Usually different damage messages = different ammount of damage, and i have been known to want to track those as well... lots easier when they are seperated. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|