Code:
local frame = CreateFrame("Frame");
frame:RegisterUnitEvent("UNIT_HEALTH", "player");
frame:RegisterUnitEvent("UNIT_MAXHEALTH", "player");
frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player");
frame.Count = 0
frame.Health = 0
frame:SetScript("OnEvent", function(self, event, unit)
if self.Health == 0 then
self.Health = UnitHealth("player")
elseif self.Health ~= UnitHealth("player") then
self:UnregisterAllEvents()
return
end
if event == "UNIT_HEALTH" then
self.Count = self.Count + 1
print(event, self.Count, unit, UnitHealth("player"), UnitHealthMax("player"));
end
end);
Using this, if something attacks me, the printed count is 1. If I /reload, get attacked then the count is 2. /reload again, get attacked the count is 3 etc.
Logout/Login and the count resets.