[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Match "wolf", not "werewolf"

Match "wolf", not "werewolf"

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Blixel   (80 posts)  [Biography] bio
Date Sun 02 Jan 2022 03:37 AM (UTC)

Amended on Sun 02 Jan 2022 03:40 AM (UTC) by Blixel

Message
In my game, when I navigate to a new room of the dungeon, I always get a line displaying the monsters that are in the room (if there are any). The line is always is this format:

M - monster, monster, monster


Naturally some monsters are much stronger than others, and some monsters can infect you. So it's important to know the name of the monster I'm going to fight before I start slashing away at it.

So I have triggers like this:

  <trigger
   enabled="y"
   group="Monster List for Auto-Killing"
   keep_evaluating="y"
   match="^M - .*?(troglodyte|magician).*$"
   regexp="y"
   send_to="12"
   sequence="111"
  >
  <send>-- HIT DAMAGE: 7 + dice(1,4)
-- MAX DAMAGE: 11

Execute("disableHitMessages")
EnableTrigger("hitMessage11", true)

if (autokill) then
  Execute ("killonemob %1")
end</send>
  </trigger>


I have different monsters activate different hitMessage# triggers based on the maximum amount of damage they can do. This all works great except when I have ambiguous monster names like "owl" and "howler", or "wolf" and "werewolf", or "gorgon" and "demogorgon". Using the wolf/werewolf as an example, I have these regex statements:

^M - .*?(wolf|troll|piercer).*$


and

^M - .*?(werewolf).*$


I want these to be 2 separate triggers because the wolf/troll/piercer monsters are of equal strength, but the werewolf is a bit tougher and can also infect me, so I can't just do a basic attack on the werewolf. The problem I'm having is that when a werewolf is in the room, my trigger tries to attack "wolf" because wereWOLF is the same as wolf as far as the regex is concerned. So I'm trying to figure out how to make it so that the first trigger will match wolf, but not match werewolf. I thought I had figured it out using the regex101 site, but once I put the regex into practice, it didn't work.

I'm having this same problem with "owl" and "howler" (2 monsters that are polar opposite on the difficulty scale). This was the regex that at first seemed to be working, but ultimately was not.

^M - ?.*?([^h](owl)|weasel|fox|frostbat|lynx|icetoad|wolverine|dervish|brigand|robber).*$


So my question is - how do I fix my regex lines to only match exact monster names?

Thanks
[Go to top] top

Posted by Nick Gammon   Australia  (23,002 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sun 02 Jan 2022 06:27 AM (UTC)

Amended on Sun 02 Jan 2022 06:28 AM (UTC) by Nick Gammon

Message
See http://gammon.com.au/regexp

In particular, you can put things that should be whole words with a \b around them, so instead of wolf you would put \bwolf\b.

You could probably put the \b around the whole group (the alternatives) rather than each one.

- Nick Gammon

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

Posted by Blixel   (80 posts)  [Biography] bio
Date Reply #2 on Sun 02 Jan 2022 03:05 PM (UTC)
Message
Nick Gammon said:

See http://gammon.com.au/regexp

In particular, you can put things that should be whole words with a \b around them, so instead of wolf you would put \bwolf\b.


That works, thank you so much.


Nick Gammon said:

You could probably put the \b around the whole group (the alternatives) rather than each one.


That works and is probably even better. Thanks, I appreciate it.
[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.


7,173 views.

It is now over 60 days since the last post. This thread is closed.     [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 HostDash]