That's an awful lot of unnecessary event checking.
You don't need to listen for PLAYER_DEAD and PLAYER_ALIVE at all, as UNIT_HEALTH will fire for the player unit at those times anyway. You don't need UNIT_ENTERING_VEHICLE and UNIT_EXITING_VEHICLE, as you only care when those transitions end, not when they begin.
Lua Code:
ht:SetScript("OnEvent", function(self, event, unit)
if UnitIsGhost("player") then
return htt:SetText("|cffb40000Dead")
elseif UnitIsDead("player") then
return htt:SetText("|cffb40000Ghost")
end
local hcur, hmax = UnitHealth(unit or "player"), UnitHealthMax(unit or "player")
if hcur >= 1000000 then
hcur = format("%.1fm", hcur / 1000000)
elseif hcur >= 1000 then
hcur = format("%.0fk", hcur / 1000)
end
if hcur == hmax then
htt:SetFormattedText("|cff00b400%s", hcur)
else
htt:SetFormattedText("|cffbf0000%s", hcur)
end
end)
I'm fairly sure, but not 100% sure, that UNIT_HEALTH will fire anyway when you enter or leave a vehicle, so you don't actually need to register for those events. However, if that's not the case, just register ENTERED and EXITED to tell you when those transitions end, and adjust the event handler as follows:
Code:
+ if event == "UNIT_ENTERED_VEHICLE" then
+ unit = "vehicle"
+ end
local hcur, hmax = UnitHealth(unit or "player"), UnitHealthMax(unit or "player")