Hey everyone i have a little problem with my exp bar code
It works fine but everytime it updates it creates a new frame
If someone can help me fix this i would be very happy!
Lua Code:
local Experience = CreateFrame("Frame", nil, UIParent)
local function UpdateExp()
local CurXP = UnitXP("player")
local XPMax = UnitXPMax("player")
local CurLvl = UnitLevel("player")
local RestXP = GetXPExhaustion()
local ExperienceBar = CreateFrame('StatusBar', nil, UIParent)
ExperienceBar:SetPoint('LEFT', oUF_AftermathhPlayer, -67, 52)
ExperienceBar:SetStatusBarTexture(AftermathhUI.media.texture)
ExperienceBar:SetSize(235, 18)
ExperienceBar:SetStatusBarColor(0.6, 0, 0.6)
ExperienceBar:SetBackdrop({
bgFile = AftermathhUI.media.blank,
insets = {top = -1, left = -1, bottom = -1, right = -1},
})
ExperienceBar:SetBackdropColor(unpack(AftermathhUI.media.backdropcolor))
CreateBorderLight(ExperienceBar, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 3)
ExperienceBar:EnableMouse()
ExperienceBar:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:AddLine("|cffffd200Experience|r")
GameTooltip:AddDoubleLine("Current EXP", CurXP, 1, 1, 1, 1, 1, 1)
GameTooltip:AddDoubleLine("Remaining EXP", XPMax - CurXP, 1, 1, 1, 1, 1, 1)
if RestXP == nil then
GameTooltip:AddDoubleLine("Rested EXP", "0", 1, 1, 1, 1, 1, 1)
else
GameTooltip:AddDoubleLine("Rested EXP", RestXP, 1, 1, 1, 1, 1, 1)
end
GameTooltip:Show()
end)
ExperienceBar:SetScript("OnLeave", function()
if GameTooltip:IsShown() then
GameTooltip:Hide()
end
end)
local Current, Max = UnitXP("player"), UnitXPMax("player")
local Rested = GetXPExhaustion()
local IsRested = GetRestState()
ExperienceBar:SetMinMaxValues(0, Max)
ExperienceBar:SetValue(Current)
if (IsRested == 1 and Rested) then
ExperienceBar:SetMinMaxValues(0, Max)
ExperienceBar:SetValue(Rested + Current)
ExperienceBar:SetStatusBarColor(0, 144/255, 1)
else
ExperienceBar:SetValue(0)
end
local ExperienceFont = ExperienceBar:CreateFontString(nil, 'OVERLAY')
ExperienceFont:SetPoint('CENTER', ExperienceBar)
ExperienceFont:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)
ExperienceFont:SetText(""..CurXP.." / "..XPMax.."")
if AftermathhUI.media.shadowoffset == true then
ExperienceFont:SetShadowOffset(1, -1)
ExperienceFont:SetShadowColor(0,0,0)
end
end
Experience:RegisterEvent("PLAYER_XP_UPDATE")
Experience:RegisterEvent("PLAYER_LEVEL_UP")
Experience:RegisterEvent("UPDATE_EXHAUSTION")
Experience:RegisterEvent("PLAYER_ENTERING_WORLD")
Experience:RegisterEvent("PLAYER_UPDATE_RESTING")
Experience:SetScript("OnEvent", UpdateExp)