Page 1 of 2

Auto rescue triggers

Posted: Tue Feb 08, 2011 8:16 pm
by peko
Hi, i'm trying to make a trigger that excludes certain words

An example of the line it is in response to: A Sel'juk murlock's slash *** DEVASTATES *** Dvick!

This trigger is for tanking and auto rescuing players that are attacked in the middle of battle primarily.

I first tried using perl regex: \*\*\* DEVASTATES \*\*\* (\w+)! with.. send("res " .. matches[2])
Which works, only a bit too well because there are other lines in the game that create unwanted rescues:
Dvick's slice injures a Sel'juk murlock. (a Sel) becomes the match.
Dvick's punch *** DEVASTATES *** a woodwose! (a woodwose) becomes the match.
a woodwose's claw DISMEMBERS you! (you) becomes the match

I was looking through the manual and found what looked like a solution - to exclude certain words from triggers.
so then I tried: \*\*\* DEVASTATES \*\*\* (a|an|you|A|An) (\w+)! with.. send("res " .. matches[3]) I tried [1] [2] [4] as well
although now I get mixed results where it still matches with words like (a) or (an) but wont match with just a players name like: A woodwose's claw wounds Dvick.

Any suggestion on how I can make this trigger auto rescue any players name without all these unwanted matches?

Thanks, Peko (Alter Aeon)

Re: Auto rescue triggers

Posted: Wed Feb 09, 2011 12:17 am
by Rakon
You're not capturing the players name, therefore you'll never actually be able to access that data in 'matches'; it doesn't exist.

Try this:

Code: Select all

^(A|An) .* slash \*\*\* DEVASTATES \*\*\* (\w+)\!$

Re: Auto rescue triggers

Posted: Wed Feb 09, 2011 12:59 am
by tsuujin
You show two possible lines there:
A Sel'juk murlock's slash *** DEVASTATES *** Dvick!
and
Dvick's punch *** DEVASTATES *** a woodwose!
which means that you have two possible states for the same line: one with a players name at the end and one with an npc's which also includes "a" or "an". It seems like you want to ignore the second one, so I'll make that assumption.
Try this:
^An? .+ slash \*{3} DEVASTATES \*{3} (\w+)\!$
Also, you need to learn how to use non-capturing groups. (?:pattern) uses the normal grouping process but does -not- save a back reference.

Re: Auto rescue triggers

Posted: Wed Feb 09, 2011 7:50 pm
by peko
Thanks for your help. I tried both replies and found that they worked, given the case. For some reason I could only get it to happen once.. I'm afraid there are too many variables to cover, and i'm very much a beginner. Sometimes mobs have very unusual strings. Player names however are always a single word after the "damage". Also, the only color of lines in which this trigger is needed is cyan. I went looking through the forums and manual to try and find a way to combine color and regex in a standard matching trigger, but I didn't find anything that I could understand.

If I could combine just

injures (\w+). and send("res " .. matches[2]) with some sort of color recognition, that would eliminate all the unwanted matches and keep it simple.

My second thought is if combining color and regex matches isn't easy, could I have just the <injures (\w+).> but ignore words between (injures) and (match) like a, an, the, you. Including information before the dammage seems to prevent the matching because it doesn't add up.

I'd like to learn non-capturing groups, it must make things a bit quicker. It was the first time i'd heard of it. I'm quite new to this stuff - thank you for your input and patience in further help.

Re: Auto rescue triggers

Posted: Wed Feb 09, 2011 9:10 pm
by Omni
If you make it a multiline trigger with a delta of 0 then add the color condition with the color trigger option.

Re: Auto rescue triggers

Posted: Thu Feb 10, 2011 12:14 am
by tsuujin
Checking colors is easy, and you don't need a color chain.
Code: [show] | [select all] lua
selectString("the part of the string you want to check color on",1)
if isAnsiBgColor(13) then do stuff end
http://mudlet.org/asciidoc/manual.html#isAnsiFgColor

Re: Auto rescue triggers

Posted: Sat Feb 12, 2011 12:36 am
by Yetzederixx
To capture Sel'nik you have to use the pattern: ([\w']+)

Re: Auto rescue triggers

Posted: Sat Feb 12, 2011 1:52 am
by tsuujin
Yetzederixx wrote:To capture Sel'nik you have to use the pattern: ([\w']+)
Not all regex interpreters accept pattern groups inside brackets. A safer alternative is [A-Za-z']+ or just .+?

Re: Auto rescue triggers

Posted: Sat Feb 12, 2011 2:32 am
by Iocun
tsuujin wrote:Not all regex interpreters accept pattern groups inside brackets.
Mudlet does, though.

Re: Auto rescue triggers

Posted: Sat Feb 12, 2011 3:09 am
by tsuujin
Best to learn good general practices when you're first starting, rather than what's situationally acceptable at the moment.