|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 11:47 am
replacing lines of text before they show... |
IS there a way for me to take a line of text from the MUD and have a trigger capture and replace it before it shows?
So... turning...
Your flaming bite *** DEVESTATES *** a sasquatch.
Into...
Your flaming bite *** DEVESTATES *** a sasquatch. (50) dmg
Would be sort of neat if I could make a database of creatures and their hp as well and have something reference that so I can use the total dmg in something like...
Your flaming bite *** DEVESTATES *** a sasquatch. (50) dmg (1567/2398hp)
or...
Your flaming bite *** DEVESTATES *** a sasquatch. (50) dmg ||| <- hp bars. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Apr 17, 2008 11:59 am |
You can use the #sub command.
#sub {(Your flaming bite ~*~*~* DEVESTATES ~*~*~* a sasquatch.)} {#sub %concat(%1," (50) dmg"}
Obviously you're going to want some code to change the number that's subbed, but that's the idea. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 1:19 pm |
Thanks. I suppose I should make a separate thread with the database question?
|
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 1:28 pm |
As a sort of side question... the trigger I'm using to catch damage has this pattern:
{^Your (\w+ (?:\w+ ))(.*) a (.*)!$}
It's supposed to catch something like
Your (shocking bite) (*** DEVESTATES ***) a (critter).
or
Your (slash) (MANGLES) a (critter).
What I want to capture is in parenthesis. |
|
|
|
chris-74269 Magician
Joined: 23 Nov 2004 Posts: 364
|
Posted: Thu Apr 17, 2008 2:24 pm |
Something you could do is set up a variable with your damage in increasing order with the relative dmg next to it in the string, so
#var dmglist hit|5|hit hard|10|very hard|20..... and so on.
Then you use could a trigger from that pattern of #if (%ismember(%2,@dmglist)) {#sub {%concat(%1,%item(@dmglist,%eval(%ismember(%2,@dmglist)+1))), dmg}} |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 2:46 pm |
I... Urm... Uh, the question is what again?
THIS would be a good place to use your square brackets!!! [!.]
This pattern should be what you are looking for.
You will need to follow this link to begin to understand it though...
http://unicode.org/reports/tr18/
You will want to go to the section titled. General Category Property
Code: |
^Your ([\p{Ll}\s]+)\s([\S\s]*\b[\p{Lu}\s]+\b[\s\S]*) a (.*)[\.\!]$ |
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 3:09 pm |
I guess a short explanation is in order.
\p{Ll} is any lowercase letter
\p{Lu} is any uppercase letter
\S is anything that is not a space or newline
[\p{Ll}\s]+ Means match at least one letter or space. It can match one to any amount of words and spaces spelled with lowercase letters. At least one!
[\p{Lu}\s]+ Same as above except Uppercase letters are used.
\b is what I use for word boundaries. I used it here to make sure we don't have any words that had both upper and lowercase letters.
If you didn't want to keep the asterisks you can just move the parenthesis in and use this pattern instead.
Code: |
^Your ([\p{Ll}\s]+)\s[\S\s]*(\b[\p{Lu}\s]+\b)[\s\S]* a (.*)[\.\!]$ |
Note: These patterns will NOT work in Zmud. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 3:27 pm |
Some of the damage is lower caste
Your punch maims a critter. |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 3:40 pm |
here's in damage types so you can get a feel of what I'm capturing and replacing.
[ Color ] [ Damage Amount ]
miss: 0
--- green ---
scratch: 1-4
graze: 5-8
hit: 9-12
injure: 13-16
wound: 17-20
maul: 21-24
decimate: 25-28
devastate: 29-32
maim: 33-36
--- YELLOW ---
MUTILATE: 37-40
DISEMBOWEL: 41-44
DISMEMBER: 45-48
MASSACRE: 49-52
MANGLE: 53-56
--- >>>BRIGHT RED<<< ---
*** DEMOLISH ***: 57-60
*** DEVASTATE ***: 61-75
=== OBLITERATE ===: 76-100
>>> ANNIHILATE <<<: 101-125
<<< ERADICATE >>>: 126-150
--- STRIPED ---
GHASTLY: 151-175
HORRID: 176-200
DREADFUL: 201-255
HIDEOUS: 226-250
INDESSCRIBABLE: 251-275
UNSPEAKABLE: 276+ |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 3:42 pm |
Damage Types:
"Acidic Bite" "Beating Bite"
"Blast" "Charge" "Chill"
"Chop" "Claw" "Cleave"
"Crush" "Divine" "Drain"
"Flame" "Flaming Bite" "Freezing Bite"
"Grep" "Magic" "None"
"Peck" "Pierce" "Pound"
"Punch" "Scratch" "Shocking Bite"
"Shock" "Slap" "Slash"
"Slice" "Slime" "Smash"
"Stab" "Sting" "Suction"
"Thrust" "Thwack" "Whip"
"Wrath"
and creatures, well creatures just vary. Some have a preceding a, other have a the, any players just have the player name with nothing preceding.
Ultimately, I'm trying to make my own damage calculator, but I also want to have options to have it show the damage I do if I want it, and maybe how much damage I've done thus far after each round, or how much the other creature has remaining, etc... and damage reports on the session, damage reports after a fight, etc... if I store fights in a database, I could even keep damage reports of a fight stored in a place. Would be sort of neat to also record the damage of other fights (watching Arena matches). I don't want someone to do it for me because I want to use it to learn and to know it so I can adjust it. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Apr 17, 2008 4:40 pm |
Good lord, that pattern is a million times more complex than it needs to be. The very unsightly \p{stuff} syntax can be much more pleasantly expressed with [a-z] and [A-Z]. The construct [\s\S] is a bit silly, too - since \S = [^\s], you've got a class there that'll match anything, same as . does. Your use of \b in this case is unecessary, too - the greedy star and plus before them will always end up catching a space before the word begins, which'll then create a word boundary. I'm not sure whether it'd speed up or slow down (or have no bearing on) match speed, because it's pretty mind-bending.
So yeah, that pattern has serious problems. Your original pattern, Chamenas, was too generic - the only non-variables in it were "Your", "a" and "!", which could feasibly match plenty of lines it shouldn't. Also, you used (?: ) when you didn't need to - since you're not doing anything to what's contained in the brackets (like some kind of +*? repetition), they're not needed. It should be trivial to make a list of all the possible damages and attacks:
#regex {^(Your (?:shocking bite|punch|chop|whatever) (?:misses|maims|scratches|whatever) a .+[!\.])$} {#sub %concat(%1," (50) dmg")}
which is a much better regex, because it's more specific. You could keep the attacks and stuff in variables if you like. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 17, 2008 4:56 pm |
The problem I see is that you want to match 1 or 2 words for the attack type and 1 or 3 words for the damage degree, making it a bit tricky. The way I would do it is to make an explicit list of the things that I expect to match. That also eliminates accidental matching to completely unrelated lines. Something like this:
^Your (*) ({scratches|grazes|hits|injures|wounds|mauls|decimates|devastates|~*~*~* DEVASTATES ~*~*~*|=== OBLITERATES ===}) a (*).
Or:
^Your ({acidic bite|beating bite|blast|charge|chill|chop|claw|cleave|crush}) (*) a (*).
Or a combination.
For the damage levels, a database variable will work, but you'll have to come up keys that distinguish between "devastates" and "*** DEVASTATES ***". Chris-74269 suggested a string list, but you can't guarantee the order of that. A db variable like this would work:
#var dmglist scratch=1|graze=5|hit=9|injure=13 ...
The damage value would be e.g @dmglist.graze
edit: ah, ninja'd! (I finally figured out what that means) |
|
Last edited by Rahab on Thu Apr 17, 2008 4:58 pm; edited 1 time in total |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 4:57 pm |
There's just a lot of damage types and damage amounts, the list would be much longer than what you have as an example :/
Isn't ?: the symbol for optional? the damage type and damage amount are never optional, it's always one of them.
Also, the sub would have to be used within an expression, so...
#regex {^(Your (?:shocking bite|punch|chop|whatever) (?:misses|maims|scratches|whatever) (a|the| ) .+[!\.])$} {#IF (%2="*** DEVESTATES ***") {#sub %concat(%1, " (50) dmg")} }
with all the damage types as an option. I already did something similar and it didn't work, but debugging was nightmare because it was massive and ugly trying to use switch to compensate all the different damages. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 17, 2008 5:02 pm |
Instead of an #if, use #switch. I don't see any option except that #if or #switch to test which damage level it is, regardless of what the trigger itself is. Unless you have a separate trigger for each damage level...
|
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Thu Apr 17, 2008 5:05 pm |
actually, I wouldn't have a #sub within each part of the #if or #switch structure. I would set a local variable to the number within the structure, and after that do a sub using the local variable.
|
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Thu Apr 17, 2008 5:28 pm |
chamenas wrote: |
Isn't ?: the symbol for optional? the damage type and damage amount are never optional, it's always one of them. |
?: is part of the non capturing group construct (?:) Which is different from the optional quantifier ? |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Thu Apr 17, 2008 5:33 pm |
What Rahab said. I think a switch looks much better than many triggers:
Code: |
$dmg=""
#switch (%2)
("*** DEVASTATES ***") {$dmg=50}
("maims") {$dmg=10}
#sub %concat(%1," (",$dmg,") dmg") |
You'd need to adjust the pattern I suggested slightly to get that to work:
^(Your (?:shocking bite|punch|chop|whatever) (misses|maims|scratches|whatever) (?:an?|the) .+[!\.])$
if the a/an/the is optional, just remove it:
^(Your (?:shocking bite|punch|chop|whatever) (misses|maims|scratches|whatever) .+[!\.])$
And yeah, the list'll be longer, but you only have to type it once. If you wanted, you could write a short script to make a bar-separated list from that forum post you made above.
Finally, ?: isn't the syntax for optional things, a question mark after something is. In the pattern above, I have "an?" - that means an "a" followed by an optional "n" - so it'll match either "a" or "an". The syntax (?:something) is used when you want to use brackets but don't want the result to be available in the %nn variables. |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Thu Apr 17, 2008 5:37 pm |
Basically the ? does not mean optional when it is immediately preceeded by an unescaped left paren (
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 5:58 pm |
I was demonstrating how to specifically pick upper and lower case letters. If you know of a better way to do it with a regex Fang feel free to show me.
The [a-z] and [A-Z] do NOT work.
Also, I was uncertain if the preceding and following *** were always the same number of characters or even if they WERE the same character.
The \S matches any non-white space but the way I had set it up using \b and a greedy uppercase-space match it would capture only what I intended.
And finally I was uncertain if the two sets of words were multiple or single words. If they are a single word they will NOT have padding spaces.
I was working under the assumption that the damage intensity words were always going to be capitalized and it turned out that they were not.
I knew that someone else would speak up once it was clear that he needed to use a string list match and Oh Look, they did. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
JQuilici Adept
Joined: 21 Sep 2005 Posts: 250 Location: Austin, TX
|
Posted: Thu Apr 17, 2008 6:36 pm |
Arminas wrote: |
I was demonstrating how to specifically pick upper and lower case letters. If you know of a better way to do it with a regex Fang feel free to show me.
The [a-z] and [A-Z] do NOT work. |
Arminas is right that the regex engine is invoked by CMUD in case-insensitive mode. However, you can turn that mode on and off if needed, right there in the pattern:
Code: |
#show %subregex("ABCDEF abcdef","ABC","xxx")
#show %subregex("ABCDEF abcdef","(?-i)ABC","xxx") |
gives
Code: |
xxxDEF xxxdef
xxxDEF abcdef
|
(I haven't specifically tested that with triggers, but I think it all uses the same engine...)
Also, note that even regex triggers can pull long lists of alternates out of CMUD variables. So you could stick all your damage types into a stringlist, and then use the pattern (?:@damageTypes) to match any one of 'em. |
|
_________________ Come visit Mozart Mud...and tell an imm that Aerith sent you!
Last edited by JQuilici on Thu Apr 17, 2008 6:41 pm; edited 1 time in total |
|
|
|
chamenas Wizard
Joined: 26 Mar 2008 Posts: 1547
|
Posted: Thu Apr 17, 2008 6:41 pm |
Yeah, I mentioned switches earlier. They just get ugly... also...
#switch (%2)
("*** DEVASTATES ***") {$dmg=50}
("maims") {$dmg=10}
wouldn't work for me when I used it before this thread, it seemed to want the ( ) to follow { } immediately, without a linebreak. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 6:47 pm |
Sweet. Thanks JQuilici!
(?-i)[A-Z] Does indeed give only uppercase letters.
(?-i)[a-z] Also only matches lowercase letters.
Perhaps some of this stuff should be moved into a regex matching portion of the help?
Also does anyone mind testing this in Zmud? |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 6:48 pm |
Chamenas you just need to add a few spaces before the () {} on the following lines.
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Thu Apr 17, 2008 6:50 pm |
(?-i) works in ZMud as well
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Thu Apr 17, 2008 6:56 pm |
Here are two examples of how to use a Switch that are not terribly ugly.
Code: |
#switch (@number)
1 {#show one}
2 {#show two}
3 {#show three}
4 {#show four}
{#show not 1 2 3 or 4}
#switch (@number==1) {#show one}
(@number==2) {#show two}
(@number==3) {#show three}
(@number==4) {#show four}
{#show not 1 2 3 or 4} |
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
|
|