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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ General
➜ Need a better way to handle this RE...
|
Need a better way to handle this RE...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Ogomez92
(42 posts) Bio
|
| Date
| Mon 26 Apr 2010 06:30 PM (UTC) |
| Message
| Hi,
I really need a much better way to handle these regular expressions...
I have some RE's that I need to trigger on my mud and there are so many different ones, that they just keep triggering, and getting the wrong matches in different triggers and stuff.
Here's what i need to match...
id really appreciate some help here cuz its been like this for years and i just don't know how to do it better:
Also the sequences seem to be screwed...
Please help
trigger 1:
match="^.* (flaming|clawed|fiery|freezing|icy|venomous|poisonous) (bite|chop|snatch|crush|fiery slash|slap|kick|pierce|pound|punch|slash|slice|leaping attack|hack|claw|blast|foot|leaping attack|splat|sweep|spit|stomp|stab|whip) (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) you[!.]$"
regexp="y"
script="fight2"
group="combat"
send_to="14"
sequence="50"
2
match="^.* (bite|chop|snatch|crush|fiery slash|slice|hack|claw|foot|splat|sweep|spit|stomp|slap|kick|pierce|pound|punch|slash|stab|whip) (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) you[!.]$"
regexp="y"
script="fight22"
sequence="51"
group="combat"
<trigger
match="^.* (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) you[!.]$"
regexp="y"
script="fight3"
sequence="51"
group="combat"
match="^Your (bite|slap|slice|chop|crush|kick|pierce|pound|punch|slash|leaping attack|hack|claw|blast|foot|splat|sweep|spit|stomp|stab|whip) (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) (.*?)[!.]$"
regexp="y"
script="fight1"
sequence="50"
group="combat"
match="^Your (.*)\s*(bite|slap|slice|chop|crush|kick|pierce|pound|punch|slash|leaping attack|hack|claw|blast|foot|splat|sweep|spit|stomp|stab|whip) (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) (.*?)[!.]$"
regexp="y"
script="fight4"
send_to="14"
sequence="49"
and the group fight trig...
For when someone in the group fights something
<trigger
match="^(.*)'s (.*) (scratches|hits|wounds|injures|mauls|decimates|devastates|maims|MUTILATES|DISMEMBERS|DISEMBOWELS|MASSACRES|\*\*\* MASSACRES \*\*\*|\*\*\* DEVASTATES \*\*\*|\*\*\* OBLITERATES \*\*\*|\*\*\* DEMOLISHES \*\*\*|\*\*\* ANNIHILATES \*\*\*|\*\*\* DESTROYS \*\*\*) (\w+)[!.]$"
regexp="y"
script="gfight"
omit_from_output="y"
sequence="100"
enabled="y"
| | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Mon 26 Apr 2010 08:50 PM (UTC) Amended on Mon 26 Apr 2010 09:23 PM (UTC) by Nick Gammon
|
| Message
| It might be simpler to do most of the matching in a script if you can't find what is wrong. For example, the first one is really:
(someone) (adjective) (noun) (verb) (someone)[!.]
And the adjective (flaming, clawed etc.) seems to be optional.
So the regexp could be:
^(\S+) (\w+ )?(\w+) ([A-Za-z\*]+) (\S+)[!.]$
This gives us 5 wildcards:
- Who is doing it (eg. the mob, or "Your")
- The optional adjective (eg. flaming, clawed, fiery)
- The noun (eg. bite, chop, snatch)
- The verb (eg. scratches, hits, wounds)
- Who it is done to (eg. the mob, or "you")
Of course this rather broad regexp might match other things like chat, so we need to check for the actual words in the script.
So you might have a table like this:
adjectives = {
"", -- in case no adjective
flaming = true,
clawed = true,
fiery = true,
-- and so on
}
nouns = {
bite = true,
chop = true,
snatch = true,
-- and so on
}
verbs = {
scratches = true,
hits = true,
wounds = true,
-- and so on
['*** MASSACRES ***'] = true,
['*** DEVASTATES ***'] = true,
-- and so on
}
Note that words with non-alphabetic things in (like '*** MASSACRES ***') need to be put in square brackets like I showed.
Now in the fight function we can quickly check if the fight words match, eg.
function fighting (name, line, wildcards)
if not adjectives [wildcards [2]] then
return
end -- if wrong adjective
if not nouns [wildcards [3]] then
return
end -- if wrong noun
if not verbs [wildcards [4]] then
return
end -- if wrong verb
-- seems to match:
local attacker = wildcards [1]
local attacked = wildcards [5]
-- handle attack here
end -- function
Now you only need a single regexp, and you can add further nouns etc. to the table. This will be a lot simpler. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ogomez92
(42 posts) Bio
|
| Date
| Reply #2 on Tue 27 Apr 2010 06:43 AM (UTC) |
| Message
| Hi,
Thanks so much for your help. I have been converitng most of the fight functions to the new format and it's working so far.
However there is a problem...
In some cases, mobs have no weapon. So it'd say like:
Mobname hits you.
mobname *** MASSACRES *** you!
The regexp doesn't seem to match of these of course because it seems to require aa weapon.
Would it be easy to change it without having to change this format too much? Or would I need something else? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #3 on Tue 27 Apr 2010 06:56 AM (UTC) |
| Message
| In that case make the noun group optional too:
^(\S+) (\w+ )?(\w+ )?([A-Za-z\*]+) (\S+)[!.]$
The extra ? make the group optional.
Now you need to add an empty string in the nouns table:
nouns = {
[""] = true, -- in case no noun
bite = true,
chop = true,
snatch = true,
-- and so on
}
(I should have put the empty string in brackets in the adjectives table too).
Your only problem now is the trailing space, so the tests could look like this:
if not adjectives [Trim (wildcards [2]\)] then
return
end -- if wrong adjective
if not nouns [Trim (wildcards [3]\)] then
return
end -- if wrong noun
The Trim function will get rid of leading and trailing spaces.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Tue 27 Apr 2010 07:00 AM (UTC) |
| Message
| I'm a little concerned the regexp may be a bit confusing to the the trigger handler (too many optional words). If it doesn't work quite right, you may need to make 3 different ones, eg.
^(\S+) ([A-Za-z\*]+) (\S+)[!.]$
^(\S+) (\w+) ([A-Za-z\*]+) (\S+)[!.]$
^(\S+) (\w+) (\w+) ([A-Za-z\*]+) (\S+)[!.]$
They could call three slightly different functions (the tables of verbs, nouns, etc. can be shared). One expects verb, the next expects noun/verb, and the third expects adjective/noun/verb. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ogomez92
(42 posts) Bio
|
| Date
| Reply #5 on Tue 27 Apr 2010 10:05 AM (UTC) |
| Message
| Hi,
it's working so far, but there's one problem:
What I did was to make a function that would take the number of wildcards I had, like this:
Your slash MUTILATES him!
4 wildcards.
Your
slash
MUTILATES
him
But it won't match on stuff like
Your slash *** MUTILATES *** him!
Also, it won't match:
Some mob's slash scratches you.
I've been doing this with simulate but it should probably work anyway. I did create the 3 different regular expressions though
regexp="y"
keep_evaluating="y"
script="fighting"
group="combat"
match="^(\S+) ([A-Za-z\*]+) (\S+)[!.]$"
--
match="^(\S+) ([A-Za-z\*]+) (\S+)[!.]$"
match="^(\S+) (\w+) (\w+) ([A-Za-z\*]+) (\S+)[!.]$"
match="^(\S+) (\w+) ([A-Za-z\*]+) (\S+)[!.]$"
I'm sorry I keep asking questions, I'm just not good with regexps and this is already confusing for me so I wouldn't know how to fix it.
Thanks. | | 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.
20,081 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top