I'm also pretty sure (I don't play a DK, but the tooltip wording seems pretty clear, especially considering how other abilities with similar wording work or have worked) that it's a sliding 5-second window. It doesn't reset to zero every 5 seconds. It just keeps a rolling record of all the damage you take, so that at any given moment, it can calculate how much damage you took between "now" and "5 seconds before now".
That said, UNIT_HEALTH isn't what you want here, because not every health change -- not even every health reduction -- is due to taking damage. You'd need to watch
COMBAT_LOG_EVENT_UNFILTERED for all the damage sub-events: SWING_DAMAGE (melee auto attacks), RANGE_DAMAGE (ranged auto attacks), SPELL_DAMAGE (non-dot spells), SPELL_PERIODIC_DAMAGE (dots), and ENVIRONMENTAL_DAMAGE (falling, lava, etc) if that counts. In all of those cases, the target's GUID is arg8 (match it against the player's GUID to detect damage you took) and the amount of damage taken is arg15.
Not tested at all, and not related to WeakAuras, but may give you an idea of what kind of code is needed:
lua Code:
local playerGUID
local damageAmounts, damageTimestamps = {}, {}
local damageInLast5Seconds = 0
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(self, event)
playerGUID = UnitGUID("player")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:SetScript("OnEvent", function(_, _, timestamp, event, _, _, _, _, _, destGUID, _, _, _, ...)
if destGUID ~= playerGUID then return end
local amount
if event == "SPELL_DAMAGE" or event == "SPELL_PERIODIC_DAMAGE" or event == "RANGE_DAMAGE" then
_, _, _, amount = ...
elseif event == "SWING_DAMAGE" then
amount = ...
elseif event == "ENVIRONMENTAL_DAMAGE" then
_, amount = ...
end
if amount then
-- Record new damage at the top of the log:
tinsert(damageAmounts, 1, amount)
tinsert(damageTimestamps, 1, timestamp)
-- Clear out old entries from the bottom, and add up the remaining ones:
local cutoff = timestamp - 5
damageInLast5Seconds = 0
for i = #damageTimestamps, 1, -1 do
local timestamp = damageTimestamps[i]
if timestamp < cutoff then
damageTimestamps[i] = nil
damageAmounts[i] = nil
else
damageInLast5Seconds = damageInLast5Seconds + damageAmounts[i]
end
end
end
end)
end)
Then at any given moment the amount of healing you'll get from Heart Strike can be calculated as:
lua Code:
-- Calculate 20% of damage taken in the last 5 seconds:
local healingFromDamage = damageInLast5Seconds * 0.2
-- Calculate 10% of your maximum health:
local minimumHealing = UnitHealthMax("player") * 0.1
-- Take the larger of the two values:
local actualHealing = math.max(healingFromDamage, minimumHealing)
print("Heart Strike will heal you for " .. actualHealing)