View Single Post
05-21-21, 05:56 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Something simple:

Lua Code:
  1. local function UpdateHealth(self) -- Update the health text
  2.     local health = UnitHealth("player")
  3.     self.Text:SetText(health .. '/' .. self.healthMax)
  4. end
  5. local function UpdateHealthMax(self) -- Update max. health value
  6.     self.healthMax = UnitHealthMax("player")
  7.     UpdateHealth(self)
  8. end
  9.  
  10. local f = CreateFrame("Frame", "nibsrsHealthText", UIParent)
  11. f:SetSize(5, 4)
  12. f:SetPoint("CENTER")
  13. f.Text = f:CreateFontString()
  14. f.Text:SetFontObject(GameFontNormal)
  15. f.Text:SetPoint("CENTER")
  16. f.Text:SetJustifyH("CENTER")
  17. f.Text:SetJustifyV("CENTER")
  18.  
  19. f:SetScript("OnEvent", function(self, event, ...) -- when registered events fire.
  20.     if event == "UNIT_HEALTH" then -- Fired when health changes
  21.         UpdateHealth(self)
  22.     elseif event == "UNIT_MAXHEALTH" then -- Fired when max. health changes
  23.         UpdateHealthMax(self)
  24.     end
  25. end)
  26. f:RegisterEvent("UNIT_HEALTH") -- register the events to be used (when health changes happen)
  27. f:RegisterEvent("UNIT_MAXHEALTH")
  28. UpdateHealthMax(f) -- initialise the health text
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-21-21 at 06:00 PM.
  Reply With Quote