Issue with targeting one word for a variable when line can have multiple words

Posted by Whisk3rz on Sun 06 Mar 2011 04:46 PM — 17 posts, 67,051 views.

#0
I'm trying to find a way to set this trigger to target "robber" or "imp" but when there are more than one creature in the room, the line reads like this...

In this room you see: 1st grave robber, 1st grave imp, 2nd grave robber, etc.

When there's only one it reads like this...

In this room you see: 1st grave robber


So how do I isolate "robber" or "imp" without capturing the rest of the line? The first thing I thought was to make a limit on the capture to 3 characters, but I don't know -anything- about coding, so I'm basically teaching myself this stuff as we go. Any help would be appreciated.
Trigger below:

Quote:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="HuntGY"
keep_evaluating="y"
match="^In this room you see\: 1st grave *(.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>--Sets target variable to "grave *" for further fighting.
Execute ("t %1")

--Sends kill command first time via alias "kill"
Execute ("kill")

--Displays target in bottom left
SetStatus ("Target: %1")
</send>
</trigger>
</triggers>


Edit: Version 4.43
Amended on Sun 06 Mar 2011 04:57 PM by Whisk3rz
USA Global Moderator #1
Based on your attempt, it looks like you're maybe trying to get this?


^In this room you see\: 1st grave (\w+)


That will put the first alphanumeric sequence following "grave" into %1, ending at the first non-alphanumeric character.
#2
Fiendish said:

Based on your attempt, it looks like you're maybe trying to get this?


^In this room you see\: 1st grave (\w+)


That will put the first alphanumeric sequence following "grave" into %1, ending at the first non-alphanumeric character.


Okay, so far that works great. Thank you.

... Now to make it a little more complex. what if "1st zombie" was a possible mob too?
I'm simply trying to find a way to combine this so I don't have 3+ triggers to hit the three + mobs that may be here...
USA Global Moderator #3
Right now I'm thinking something along the lines of

^In this room you see\: 1st (zombie)|(?:grave (\w+))


The only thing about this pattern is that if it's zombie, then zombie will be in %1, but if it's grave <something> then the something will be in %2 and not in %1. So you'll need to, in your script, check explicitly to see if "%1" == "zombie" and if not then use %2
USA #4
Fiendish said:
Right now I'm thinking something along the lines of
^In this room you see\: 1st (zombie)|(?:grave (\w+))


The only thing about this pattern is that if it's zombie, then zombie will be in %1, but if it's grave <something> then the something will be in %2 and not in %1. So you'll need to, in your script, check explicitly to see if "%1" == "zombie" and if not then use %2

Make sure you wrap that | in a group (), or it'll alternate between "^In this room you see\: 1st (zombie)" and "(?:grave (\w+))".

^In this room you see\: 1st (?:(zombie)|grave (\w+))
Australia Forum Administrator #5
Or, if you are looking for "zombie" or "grave robber" then allow for a space, eg.


^In this room you see\: 1st ([%a ]+)


Now %1 might be "grave robber" or "zombie". And since extra ones have a comma before them, that will terminate the search for characters.
#6
Nick Gammon said:

Or, if you are looking for "zombie" or "grave robber" then allow for a space, eg.


^In this room you see\: 1st ([%a ]+)


Now %1 might be "grave robber" or "zombie". And since extra ones have a comma before them, that will terminate the search for characters.



Will it capture "grave robber" that way? I need just robber/imp captured if its one of those two... thank you all for your help.
USA #7
Nick Gammon said:

^In this room you see\: 1st ([%a ]+)

What is %a? I know \a matches a bell character, but that doesn't make sense either
Australia Forum Administrator #8
Ooops, sorry I was in "Lua mode". In Lua that would be "an alphabetic character".


^In this room you see\: 1st ([A-Za-z ]+)


Quote:

Will it capture "grave robber" that way?


Try it and see. It should (or the amended one should). Just to explain, inside the brackets are groups of things, like A-Z and a-z for alphabetic characters, upper and lower case. Plus a space so we capture the space between "grave" and "robber".
#9
Nick Gammon said:

Ooops, sorry I was in "Lua mode". In Lua that would be "an alphabetic character".

Try it and see. It should (or the amended one should). Just to explain, inside the brackets are groups of things, like A-Z and a-z for alphabetic characters, upper and lower case. Plus a space so we capture the space between "grave" and "robber".


How would I get it to only plug "robber" "imp" or "zombie" when the names are grave robber or grave imp? My game wont accept "kill grave robber"
USA #10
^In this room you see: 1st (?:grave )?([A-Za-z ]+)
Amended on Sun 06 Mar 2011 09:58 PM by Twisol
Australia Forum Administrator #11
Whisk3rz said:

How would I get it to only plug "robber" "imp" or "zombie" when the names are grave robber or grave imp? My game wont accept "kill grave robber"


That is one of my pet hates.


In this room you see: grave robber

> kill grave robber

There is no grave robber here.

...

There is a silver sword lying here.

> take silver sword

There is no silver sword here.

Australia Forum Administrator #12
More generally (in case it isn't always the word "grave") you can get the last word. For example:


mobname = "big fat ugly grave robber"

last_word = string.match (mobname, "[%a]+$")

Send ("kill " .. last_word)



That sends "kill robber".
#13
Okay, so far this is what I have...


<triggers>
  <trigger
   expand_variables="y"
   group="HuntGY"
   keep_evaluating="y"
   match="^In this room you see\: 1st ([A-Za-z ]+)"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>--Define mobset prior to running
mobname = "grave robber"

--Checks to see if creature in the room is in mobset and if so, sets the last word of name as "last_word"

last_word = string.match (mobname, "[%a]+$")

--Command to kill mob if match is made from mobset
Send ("kill " .. last_word)


--Sets target variable to mob for further fighting.
  Execute ("t ".. last_word)

--Displays target in bottom left
SetStatus ("Target: %1")
</send>
  </trigger>
</triggers>



and it works great... for robbers. It's actually -only- trying to kill robbers, even if there are only grave imps in the room, though.

This is a standard set up of what i see when I look:



[Ancient Graveyard]
Paralleling the widening path are empty holes in the ground. The realization that these empty holes once held not only a coffin, but a body, becomes abundantly clear by the broken wood and scattered bone fragments still lying around. The large oak trees that surround these desecrated graves stand silently, their only purpose to drop their leaves and fill in the gaping holes.


The area is illuminated.

In this room you see: 1st grave robber, 1st grave imp, 1st zombie, 2nd grave imp
In this room are: large oak tree
Obvious exits are: northwest, south


Now I want it to ultimately kill any (and all) of these. But I need it to pick one target. But not necessarily just the grave robber. As it's currently set up, if there are only grave imps, it still tries to kill a grave robber... what would I need to do to fix this and make it viable to attack any of those three mobs?
Australia Forum Administrator #14
Well, mobname = "big fat ugly grave robber" was purely a test case to demonstrate the idea.

Change:


mobname = "grave robber"


to:


mobname = "%1"


#15
I THINK I HAVE IT!

So far this works perfect for me. I think this is what I was looking for.

Thank you all for your help and it did help. Thanks Nick for the Trigger line, that really pulled it all together once I figured out the if/then statements. Taught me a little bit about this HUGE language I don't know...yet. :-P


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="HuntGY"
   keep_evaluating="y"
   match="^In this room you see\: 1st ([A-Za-z ]+)"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

--Command to kill robber if match is made
if "%1" == "grave robber" then
Send ("kill " .. "robber")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "robber")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to kill imp if match is made
if "%1" == "grave imp" then
Send ("kill " .. "imp")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "imp")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to kill zombie if match is made
if "%1" == "zombie" then
Send ("kill " .. "zombie")
--Sets target variable to mob for further fighting.
  Execute ("t ".. "zombie")
--Displays target in bottom left
SetStatus ("Target: %1")
end --if

--Command to flee if match is made
if "%1" == "Master Zombie" then
ColourNote ("black", "red", "RUN FOR YOUR LIFE!")
world.EnableGroup ("HuntGY", 0)
end --if</send>
  </trigger>
</triggers>
#16
Nick Gammon said:

Well, mobname = "big fat ugly grave robber" was purely a test case to demonstrate the idea.

Change:


mobname = "grave robber"


to:


mobname = "%1"





OR, I could write all that code I just wrote! Same result, different path, I guess! Thanks again! [And please excuse the double post!!]