An effective way to know "damage hero have sustained during the preceding X sec" ?

Tom_Kazansky

--- wraith it ! ---
Reaction score
157
I only think of this:

A variable is attached to hero, let name it: damageSustained
Each time the hero takes damage: damageSustained = damageSustained + Damage Taken
create a timer that expires in X sec, when it does: damageSustained = damageSustained - Damage Taken

I guess this will have a problem if there are too many instances of damage taken, yes, biggest problem: too many used timers :(

I only plan to use this for one hero with fixed "X" but in the future, I may use for all heroes (maximum of 10, I think)

so, what do you think about this?

thank you for reading!
 

luorax

Invasion in Duskwood
Reaction score
67
If you're familiar with vJASS, then you could create a private struct, and add a constant timer to it with a 0.3125 second timeout. Every time a unit in, let's say, a constant group takes damage, a new instance is created and linked into a linked list. The timer enumerates the instances (increases the private member "time" by 0.3125), and checks whether it's old enough or not to be destroyed.

The "damageSustained" variable should be a global array, using a unit indexer you can use the unit's user data as array index.
 

Tabris

New Member
Reaction score
0
Sounds like a very ineffective way of doing it.
Why not just creating a new timer every time damage is done to an unit that expires after the amount of seconds the ability records that, when expired, removes the damage taken from a [ljass]real[/ljass] stack each unit has?
Would require 1 timer per damage given, but that's not so bad... specially if you're planning to do this with only one unit. Otherwise it would be an excellent moment to start using TimerTools

EDIT: real life example
JASS:
real amount
integer cv
static real array damageSustained

static method onExpire takes nothing returns nothing
	local thistype this = GetTimerData(GetExpiredTimer())
	set damageSustained[cv] = damageSustained[cv] - amount
	call ReleaseTimer(GetExpiredTimer())
endmethod

static method UnitTakesDamage takes nothing returns nothing
	local thistype this = create()
	local timer t = NewTimer()
	local real d = GetDamageTaken();
	set amount = d
	set cv = GetUnitCustomValue(GetTriggerUnit()]
	set damageSustained[cv] = damageSustained[cv] + d
	call SetTimerData(t,this)
	call TimerStart(t,5,false,function thistype.onExpire)
endmethod
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top