Uncle
Warcraft Moderator
- Joined
- Aug 10, 2018
- Messages
- 7,866
Hey guys, what's an efficient way for calculating damage over time?
In my map I have a Tower that applies a DoT effect on it's attacks. It has two DoT related stats that can be increased/decreased:
DoT_Damage
DoT_Duration
I have it working using the code below but I'm not a fan of this style since it creates extremely short timer intervals.
Here's the important parts of my code slightly modified for clarity (t = the enemy target):
I'm terrible at even the simplest of math so the answer is probably right in front of me, but any help would be appreciated.
Edit: So I'm now multiplying the interval and dmg by 5 which seems to do the trick. I don't think it will cause any problems but I'm not sure.
In my map I have a Tower that applies a DoT effect on it's attacks. It has two DoT related stats that can be increased/decreased:
DoT_Damage
DoT_Duration
I have it working using the code below but I'm not a fan of this style since it creates extremely short timer intervals.
Here's the important parts of my code slightly modified for clarity (t = the enemy target):
Lua:
-- calculate interval and damage per interval
local duration = tow.dot_duration
local interval = duration / tow.dot_damage
local ticks = tow.dot_damage / duration
local dmg = interval*ticks
local elapsedTime = 0
local ThisTimer = CreateTimer()
TimerStart(ThisTimer, interval, true, function ()
-- increment
elapsedTime = elapsedTime + interval
-- check duration
if elapsedTime < duration and IsAlive(t) then
-- damage
DealDamage(u, t, dmg)
else
-- clean up
DestroyTimer(ThisTimer)
end
end)
Edit: So I'm now multiplying the interval and dmg by 5 which seems to do the trick. I don't think it will cause any problems but I'm not sure.
Last edited: