Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ Match "wolf", not "werewolf"
Match "wolf", not "werewolf"
|
Posting of new messages is disabled at present.
Refresh page
Posted by
| Blixel
(80 posts) 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
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 | Top |
|
Posted by
| Nick Gammon
Australia (23,122 posts) 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 | Top |
|
Posted by
| Blixel
(80 posts) 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. | 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.
8,601 views.
Posting of new messages is disabled at present.
Refresh page
top