safe unit death on UNIT_HEALTH events

This commit is contained in:
Sumsebrum 2021-06-16 14:34:17 +02:00
parent 152573124f
commit 09a07c7201

View File

@ -1,6 +1,6 @@
local pairs = pairs local pairs = pairs
local floor = math.floor local floor = math.floor
local UnitHealth, UnitHealthMax, UnitName, UnitExists = UnitHealth, UnitHealthMax, UnitName, UnitExists local UnitHealth, UnitHealthMax, UnitName, UnitExists, UnitIsDeadOrGhost = UnitHealth, UnitHealthMax, UnitName, UnitExists, UnitIsDeadOrGhost
local CreateFrame = CreateFrame local CreateFrame = CreateFrame
local RAID_CLASS_COLORS = RAID_CLASS_COLORS local RAID_CLASS_COLORS = RAID_CLASS_COLORS
@ -95,13 +95,22 @@ function Healthbar:CreateFrame(unit)
end end
function Healthbar.OnEvent(self, event, unit) function Healthbar.OnEvent(self, event, unit)
local isDead = UnitExists(unit) and UnitIsDeadOrGhost(unit)
if event == "UNIT_HEALTH" then if event == "UNIT_HEALTH" then
if isDead then
Gladdy:SendMessage("UNIT_DEATH", unit)
return
end
local health = UnitHealth(unit) local health = UnitHealth(unit)
local healthMax = UnitHealthMax(unit) local healthMax = UnitHealthMax(unit)
self.hp:SetMinMaxValues(0, healthMax) self.hp:SetMinMaxValues(0, healthMax)
self.hp:SetValue(UnitHealth(unit)) self.hp:SetValue(UnitHealth(unit))
Healthbar:SetHealthText(self, health, healthMax) Healthbar:SetHealthText(self, health, healthMax)
elseif event == "UNIT_MAXHEALTH" then elseif event == "UNIT_MAXHEALTH" then
if isDead then
Gladdy:SendMessage("UNIT_DEATH", unit)
return
end
local health = UnitHealth(unit) local health = UnitHealth(unit)
local healthMax = UnitHealthMax(unit) local healthMax = UnitHealthMax(unit)
self.hp:SetMinMaxValues(0, healthMax) self.hp:SetMinMaxValues(0, healthMax)