DPS meter

Posted by Green on Wed 15 Aug 2018 07:10 PM — 4 posts, 16,593 views.

#0
Looking for a little help making a simple dps meter.
my basic understanding is something like...

Start a timer on the first attack message only
** set a flag to zero

>You deal 10 damage!
** if flag == 0, set the flag to 1 and run timer

Add the damage amount to a variable


wait for a death message
> A stalker just died!

zero the Dmg variable and display the ttl damage divided by time
> DPS: 12

I can't figure out timers, etc and my Dmg variable is not
updating the display :(

Thanx for any help :)


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="DPSmeter"
   keep_evaluating="y"
   match="^You deal (.*?) damage\!$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>Note("curr hit:  %1 ")
SetVariable("Dmg",(GetVariable("Dmg") + %1))
Note(" curr dmg: @Dmg ")</send>
  </trigger>
</triggers>


this is from 2 consecutive swings...

You attack a hideous mud stalker!
You deal 15 damage!
curr hit: 15
curr dmg: 0

You attack a hideous mud stalker!
You deal 9 damage!
curr hit: 9
curr dmg: 15
Amended on Wed 15 Aug 2018 09:15 PM by Nick Gammon
Australia Forum Administrator #1
Quote:

I can't figure out timers, etc and my Dmg variable is not updating the display



Note(" curr dmg: @Dmg ")


Variables like @Dmg are evaluated before the script runs, so it will show the old value. You could use:


Note(" curr dmg: ",  GetVariable ('Dmg'))


You will notice that the correct value (after the first hit) is shown after the second hit. That is the result of this.
Australia Forum Administrator #2
It is easier to use Lua variables for something which changes frequently, and you don't care about the amount of damage from one session to the next.


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   group="DPSmeter"
   keep_evaluating="y"
   match="^You deal ([0-9]+) damage\!$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>

Note("curr hit:  %1 ")

if not tonumber ('%1') then
  ColourNote ("Red", "", "Damage '%1' is not a number")
  return
end -- if

-- reset damage and timer on new fight
if DamageTimer == nil then
  DamageTimer = utils.timer ()  -- get current time
  Dmg = 0
end -- if

Dmg = Dmg + %1

Note(" curr dmg: ", Dmg)

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


All you need for timing is to note when the fight starts and store that in a variable, like above.

Then at the end of the fight you calculate the elapsed time to give you the DPS:


<triggers>
  <trigger
   enabled="y"
   group="DPSmeter"
   match="* just died!"
   send_to="12"
   sequence="100"
  >
  <send>

if DamageTimer then
  local TimeTaken = utils.timer () - DamageTimer
  local DPS = Dmg / TimeTaken
  ColourNote ("Orange", "", "Total damage: " .. Dmg)
  ColourNote ("Orange", "", string.format ("Time taken: %%0.2f seconds", TimeTaken))
  ColourNote ("Orange", "", string.format ("DPS: %%0.2f", DPS))
  DamageTimer = nil
end -- if

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


This code sets DamageTimer to nil when it is done, so that the other trigger can detect that a new fight has started.

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