Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
guganslof
Beginner


Joined: 05 Apr 2008
Posts: 19

PostPosted: Fri Apr 25, 2008 2:27 pm   

Event Counting Script
 
So I want to make a script that counts damage types as the hits occur, then lists them later for comparison.


You pierce the ancient tree's trunk into bloody fragments!
You pierce the ancient tree's crown extremely hard.
You pierce the ancient tree's trunk very hard.
You pierce the ancient tree's branch hard.
You pierce the ancient tree's trunk.

Those would be the damage types, bloody fragments, extremely hard, very hard, hard, and nothing at all. Then after a few minutes of fighting be able to do a 'list damage' and have:
Bloody fragments - 15 hits
Extremely Hard - 28 hits
Very Hard - 42 hits
etc.

Could someone point me towards an already make script I could work from or give me a starter one, it'd be greatly appreciated :)
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 25, 2008 2:40 pm   
 
Code:
#var damagetypes ""
#addkey damagetypes bloody 0
#addkey damagetypes extremely 0
#addkey damagetypes very 0
#addkey damagetypes hard 0
#addkey damagetypes normal 0
#regex {You pierce [^.]+(into bloody fragments|extremely hard|very hard|hard)?[.!]} {#switch (%1)
  ("into bloody fragments") {#add damagetypes.bloody 1}
  ("extremely hard") {#add damagetypes.extremely 1}
  ("very hard") {#add damagetypes.very 1}
  ("hard") {#add damagetypes.hard 1}
  {#add damagetypes.normal 1}
#alias ResetDamage {#var damagetypes ""}
#alias ShowDamage {#say %expanddb(@damagetypes,%crlf," - ")

Try that. I'm at work (naughty me, I know) so I haven't tested it, but it should at least show you the direction I'm going. If you don't understand some (or any) of it, try looking up the commands and functions in the help. If that still doesn't help, just ask here and I'm sure someone (if not me) will explain.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Fri Apr 25, 2008 2:47 pm   
 
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="dt" type="Record" copy="yes">very hard.=2|into bloody fragments!=3|extremely hard.=2|hard.=2</var>
  <trigger type="Command Input" priority="30" copy="yes">
    <pattern>^list damage$</pattern>
    <value>#noinput
#say Damage summary.
#loopdb @dt {#show {%proper(%key) - %val hits.}}</value>
  </trigger>
  <trigger priority="10" copy="yes">
    <pattern>^You pierce the ancient tree's %w (*)[!.?]</pattern>
    <value>#if (%iskey(@dt,%1)) {#addkey dt {%1} (%db(@dt,%1)+1)} {#addkey dt {%1} 1}</value>
  </trigger>
</cmud>
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Fri Apr 25, 2008 2:47 pm   
 
Ninja'd oh well, try em both if you like.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
guganslof
Beginner


Joined: 05 Apr 2008
Posts: 19

PostPosted: Fri Apr 25, 2008 2:51 pm   
 
Hrmm, you were missing a closing } at the end of {#switch (%1) and {#say %expanddb(@damagetypes,%crlf," - ")

But after adding those in, I could do ShowDamage and it gave me:
very - 0
hard - 0
normal - 0
extremely - 0
bloody - 0

which was after a few rounds of combat.

Also I tried to do a ResetDamage, but after that the ShowDamage wouldn't work anymore :\
Reply with quote
guganslof
Beginner


Joined: 05 Apr 2008
Posts: 19

PostPosted: Fri Apr 25, 2008 2:58 pm   
 
Arminas wrote:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <var name="dt" type="Record" copy="yes">very hard.=2|into bloody fragments!=3|extremely hard.=2|hard.=2</var>
  <trigger type="Command Input" priority="30" copy="yes">
    <pattern>^list damage$</pattern>
    <value>#noinput
#say Damage summary.
#loopdb @dt {#show {%proper(%key) - %val hits.}}</value>
  </trigger>
  <trigger priority="10" copy="yes">
    <pattern>^You pierce the ancient tree's %w (*)[!.?]</pattern>
    <value>#if (%iskey(@dt,%1)) {#addkey dt {%1} (%db(@dt,%1)+1)} {#addkey dt {%1} 1}</value>
  </trigger>
</cmud>


It's telling me theres an extra } bracer at }}</value> but I couldn't spot the error :\
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 25, 2008 3:07 pm   
 
guganslof wrote:
Hrmm, you were missing a closing } at the end of {#switch (%1) and {#say %expanddb(@damagetypes,%crlf," - ")

But after adding those in, I could do ShowDamage and it gave me:
very - 0
hard - 0
normal - 0
extremely - 0
bloody - 0

which was after a few rounds of combat.

Also I tried to do a ResetDamage, but after that the ShowDamage wouldn't work anymore :\

Bumcakes. That probably means that the trigger isn't matching properly, and I don't have the tools to check here.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Apr 25, 2008 3:25 pm   
 
Fang's regex trigger pattern above is:
Code:
You pierce [^.]+(into bloody fragments|extremely hard|very hard|hard)?[.!]

The '[^.]+' is absorbing the whole string up to the period, because the damage type part is optional. So nothing is ever captured into %1.

Try
Code:
You pierce [^.]+?(into bloody fragments|extremely hard|very hard|hard)?[.!]

(Note the additional '?') This should expand the first character class in a lazy way, so that it won't eat the damage section, if one is present.

(Also at work, so I can't test. Embarassed )
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
guganslof
Beginner


Joined: 05 Apr 2008
Posts: 19

PostPosted: Fri Apr 25, 2008 3:39 pm   
 
That didn't help any :\

Still getting 0 0 0 0 for everything
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 25, 2008 3:51 pm   
 
JQuillici - I'm pretty sure that's not true, because the ? after the bracket in that is also greedy. It'll only try matching no string after it's tried all the string options. Which is why it's not helping.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Apr 25, 2008 4:10 pm   
 
Code:
^You pierce .+?((?>into bloody fragments|extremely hard|very hard|hard|))[.!]$


This uses atomic grouping
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
JQuilici
Adept


Joined: 21 Sep 2005
Posts: 250
Location: Austin, TX

PostPosted: Fri Apr 25, 2008 5:10 pm   
 
Fang, the '?' in '[^.]+?' does not make the preceding thing optional (which wouldn't work anyway - it has to match the mob name and hit location at a minimum). It modifies the '+' quantifier to make it lazy, so that it matches the shortest possible string rather than the longest possible string. See this tutorial page and read the sections on laziness for details. Yes, I agree that the '?' character is horribly overloaded in the regex syntax.

I've actually tested it now...and it works.
Code:
#var damagetypes ""
#regex pierceTrig {You pierce [^.]+?(into bloody fragments|extremely hard|very hard|hard)?[.!]} {#switch (%1)
  ("into bloody fragments") {#add damagetypes.bloody 1}
  ("extremely hard") {#add damagetypes.extremely 1}
  ("very hard") {#add damagetypes.very 1}
  ("hard") {#add damagetypes.hard 1}
  {#add damagetypes.normal 1}}
#alias ResetDamage {#var damagetypes ""}
#alias ShowDamage {#say %expanddb(@damagetypes,%crlf," - ")}
#alias test {#show You pierce the ancient tree's trunk into bloody fragments!
#show You pierce the ancient tree's crown extremely hard.
#show You pierce the ancient tree's trunk very hard.
#show You pierce the ancient tree's branch hard.
#show You pierce the ancient tree's trunk.}

Slap that into a blank session, then type
Code:
test
ShowDamage

I get
Code:
You pierce the ancient tree's trunk into bloody fragments!
You pierce the ancient tree's crown extremely hard.
You pierce the ancient tree's trunk very hard.
You pierce the ancient tree's branch hard.
You pierce the ancient tree's trunk.
very - 1
hard - 1
normal - 1
extremely - 1
bloody - 1

Which, I think, is the desired behavior.

FWIW, I did this test on 2.22 beta, so it's possible that this is tickling some bug in 2.18 that I've forgotten.

EDIT: Confirmed that I get the same results on 2.18
_________________
Come visit Mozart Mud...and tell an imm that Aerith sent you!
Reply with quote
guganslof
Beginner


Joined: 05 Apr 2008
Posts: 19

PostPosted: Fri Apr 25, 2008 5:41 pm   
 
Victory! That worked ^_^
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Apr 25, 2008 6:02 pm   
 
JQuilici wrote:
Fang, the '?' in '[^.]+?' does not make the preceding thing optional (which wouldn't work anyway - it has to match the mob name and hit location at a minimum). It modifies the '+' quantifier to make it lazy, so that it matches the shortest possible string rather than the longest possible string. See this tutorial page and read the sections on laziness for details. Yes, I agree that the '?' character is horribly overloaded in the regex syntax.

I was talking about the second ? in my regex. I should've made that clear, sorry.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Fri Apr 25, 2008 9:09 pm   
 
Apologies on not responding sooner.

What I gave you was in XML format. You do not paste XML stuff into the command line.

To try what I gave you you would need to open the package editor and past it into the tree view on the left hand side of the editor window.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net