Something simple:
Lua Code:
local function UpdateHealth(self) -- Update the health text
local health = UnitHealth("player")
self.Text:SetText(health .. '/' .. self.healthMax)
end
local function UpdateHealthMax(self) -- Update max. health value
self.healthMax = UnitHealthMax("player")
UpdateHealth(self)
end
local f = CreateFrame("Frame", "nibsrsHealthText", UIParent)
f:SetSize(5, 4)
f:SetPoint("CENTER")
f.Text = f:CreateFontString()
f.Text:SetFontObject(GameFontNormal)
f.Text:SetPoint("CENTER")
f.Text:SetJustifyH("CENTER")
f.Text:SetJustifyV("CENTER")
f:SetScript("OnEvent", function(self, event, ...) -- when registered events fire.
if event == "UNIT_HEALTH" then -- Fired when health changes
UpdateHealth(self)
elseif event == "UNIT_MAXHEALTH" then -- Fired when max. health changes
UpdateHealthMax(self)
end
end)
f:RegisterEvent("UNIT_HEALTH") -- register the events to be used (when health changes happen)
f:RegisterEvent("UNIT_MAXHEALTH")
UpdateHealthMax(f) -- initialise the health text