multi line number capturing, adding and displaying

Posted by TheExile on Fri 30 Sep 2011 01:46 PM — 6 posts, 28,018 views.

#0
Alright this is completely beyond my limited abilities and I have no idea where to start with this.

I'm trying to make a trigger that will capture a number from a random amount of lines from 1 all the way upto a max of 10.

All after the initial line all of the lines look the same

You hold up both hands while screaming out in rage, a huge black ball of ki quickly appears above you. The ball continues to expand as red bolts of lightning crackle around 
it, with a sudden jolt you throw the massive Revenge Death Ball at Fire Spirit.
...your revenge death ball pushes Fire Spirit into the ground!
[========]=-=[49824]
...your revenge death ball pushes Fire Spirit into the ground!
[======--]=-=[50034]
...your revenge death ball pushes Fire Spirit into the ground!
[=====---]=-=[50187]
...your revenge death ball pushes Fire Spirit into the ground!
[=====---]=-=[50082]
...your revenge death ball pushes Fire Spirit into the ground!
[====----]=-=[50221]


The bar displayed before =-= is the muds 'health bar' for the mob your fighting. Anyway what I'd like to do is make a trigger that will read the damage done with each hit add them together and display them at the end of the attack as the total damage done.

Someone else on the mud did this with Cmud for his races multihit attack.

#TR {As the ball reaches its full potential, you snap you fingers as the Genocide rains down upon (*).} {genoDmg=0;target=%1}
    #TR {^...your genocide hits {@target}!$} {}
    #COND {=-=~[(%d)~]} {genoDmg=(@genoDmg+%1)}
    #STWIN { Target: @target %cr Genocide hit for a total of @genoDmg}


This is probably a lot to ask and probably more complicated then it already seems but I figured I'd try my luck and ask anyway.

Thanks in advance no matter the results.
Amended on Fri 30 Sep 2011 01:47 PM by TheExile
Australia Forum Administrator #1
Template:faq=37
Please read the MUSHclient FAQ - point 37.


That should get you started, if not please specify what went wrong (and post what you did so far).
#2
Alright, here is what I've come up with so far.

<triggers>

<!-- trigger to match start of inventory -->

  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^\.\.\.your revenge death ball pushes."
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
multihit_table = {}
EnableTrigger ("multihit_line", true)
EnableTrigger ("multihit_stopper", true)
</send>
  </trigger>

<!-- trigger to match an inventory line -->

  <trigger
   keep_evaluating="y"
   match=".[(.*?)]$"
   name="multihit_line"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
  table.insert (multihit_table, "%1")
  </send>
  </trigger>

<!-- trigger to match end of inventory -->
  
  <trigger
   match="(^&lt;)|^$"
   name="multihit_stopper"
   regexp="y"
   send_to="12"
   sequence="40"
  >
  <send>
EnableTrigger ("multihit_line", false)
EnableTrigger ("multihit_stopper", false)

-- in case no table yet
multihit_table = multihit_table or {}

table.sort (multihit_table)

print ("Your Multihit Damage:")

for _, item in ipairs (multihit_table) do
  print (item)
end -- for

  </send>
  </trigger>
</triggers>

</muclient>


It works except what it does is it only picks up and displays the last hit of the attack instead of the whole thing. I thought that the stopper might be ending it to soon but changing what disabled the triggers didn't seem to matter. Is there anyway to fix this and get it to actually add the numbers together?

I tried using a variable setup I'm using in another set of triggers because it adds up numbers but I just cannot get multi-line triggers to work at all.

Thanks.
Australia Forum Administrator #3
I added line colouring to show what was happening. A few minor problems, fixed as so:


<triggers>

  <trigger
   group="battle"
   match="&lt;*"
   name="multihit_stopper"
   send_to="12"
   sequence="40"
  >
  <send>
EnableTrigger ("multihit_line", false)
EnableTrigger ("multihit_stopper", false)

if not multihit_table or next (multihit_table) == nil then
  print ("No damage.")
else
  table.sort (multihit_table)

  print ("Your Multihit Damage:")

  local total = 0

  for _, item in ipairs (multihit_table) do
    print (item)
    total = total + tonumber (item)
  end -- for 

  print ("Total damage =", total)

end -- if some damage


multihit_table = {}  -- for next time
  </send>
  </trigger>

  <trigger
   custom_colour="1"
   group="battle"
   keep_evaluating="y"
   match="\[(\d+)\]$"
   name="multihit_line"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
table.insert (multihit_table, "%1")
  </send>
  </trigger>

  <trigger
   custom_colour="3"
   enabled="y"
   group="battle"
   keep_evaluating="y"
   match="^\.\.\.your revenge death ball pushes."
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
multihit_table = multihit_table or {}
EnableTrigger ("multihit_line", true)
EnableTrigger ("multihit_stopper", true)
</send>
  </trigger>

</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


One problem was that you had "your revenge death ball pushes" resetting the table to empty, so naturally it only remembered the last one.

Now with this test data:



You hold up both hands while screaming out in rage, a huge black ball of ki quickly appears above you. The ball continues to expand as red bolts of lightning crackle around 
it, with a sudden jolt you throw the massive Revenge Death Ball at Fire Spirit.
...your revenge death ball pushes Fire Spirit into the ground!
[========]=-=[49824]
...your revenge death ball pushes Fire Spirit into the ground!
[======--]=-=[50034]
...your revenge death ball pushes Fire Spirit into the ground!
[=====---]=-=[50187]
...your revenge death ball pushes Fire Spirit into the ground!
[=====---]=-=[50082]
...your revenge death ball pushes Fire Spirit into the ground!
[====----]=-=[50221]
<15 hp>


I get:


Your Multihit Damage:
49824
50034
50082
50187
50221
Total damage = 250348

Amended on Tue 04 Oct 2011 10:05 PM by Nick Gammon
#4
Thank you very much for the help, it works perfectly!

match="\[(\d+)\]$"


This somehow eluded me when I was reading through the various help files.

[EDIT] Escaped backslashes to show what there really was there before.
Amended on Mon 03 Oct 2011 05:53 AM by Nick Gammon
#5
wow, i recently had a similar problem but i guess many solutions are universal, lol.