I'm writing a simple addon to show current health, percent health, current power, and percent power.
Right now it works fine, on mouseover it shows the data I want.
But I have two things I want it to do.
First, I want the data to display in two lines like so
%health current health
%power current power
also, I would like it to update these in real time (most likely through OnUpdate) so while my mouse is over, it is also updating it.
My code thus far is:
Code:
local playerframe = CreateFrame('Button', 'PlayerFrame', UIParent)
playerframe:SetFrameStrata'BACKGROUND'
playerframe:SetFrameLevel(0)
playerframe:SetWidth(300)
playerframe:SetHeight(20)
playerframe:ClearAllPoints()
playerframe:SetPoint('CENTER', UIParent, 'CENTER', 0, 0)
local health = playerframe:CreateFontString(nil, 'OVERLAY')
health:SetPoint('CENTER', Playerframe, 0, 0)
health:SetHeight(20)
health:SetWidth(300)
health:SetFont([[FONTS\FRIZQT__.ttf]],10, 'NONE')
health:SetJustifyH("CENTER")
playerframe:SetScript('OnEnter', function(self)
local hc = UnitHealth("player")
local hm = UnitHealthMax("player")
local hp = 100*(hc/hm)
local pc = UnitPower("player")
local pm = UnitPowerMax("player")
local pp = 100*(pc/pm)
health:SetText(string.format("%s%% %s %s%% %s",hp,hc,pp,pc))
end)
playerframe:SetScript('OnLeave', function(self)
health:SetText(string.format(""))
end)
I am by no means good at coding, so any advice, including a complete rewrite, is fine by me.