View Single Post
04-21-09, 03:05 PM   #995
Scound
A Murloc Raider
Join Date: Jan 2009
Posts: 5
Error massage when enabling frequnet power update

Well, I get the following errormassage ingame whenever I enable bar.frequent.updates = true in my unitframe layout:

.../oUF/elements/power.lua:46:attempt to call method 'UNIT_MAXMANA' (a nil value)

I am using the latest version of oUF as far as I know.

As I consider myself rather a noob concerning anything with programming, I wanted to ask you guys for a little help. Maybe someone has an idea how to get the smooth energybar going without changing too much of my precious code

Code:
--[[

oUF_Caith

Custom layout for oUF.
Based on Caith's PitBull layout - http://www.bellum-potentiae.de/forum/viewtopic.php?t=3674

ToDo:
Move DK Rune-Frame (central under Player-Character)!!! At this point they spawn at their original Postition
implementation of Raidframes (low priority)
implementation of CastBars for Player, Target and Focus-Target (medium priority)
implementation of RogueFocusBar / DKFocusBar (medium priority)
introduction of improved options
--]]


-- Custom Settings - Modifiable
-- ----------------------------------------------------------------------------

-- Textures/Fonts
local statusbarTexture = "Interface\\AddOns\\oUF_Caith\\media\\armory"
local borderTexture = "Interface\\AddOns\\oUF_Caith\\media\\border"
local font = "Interface\\AddOns\\oUF_Caith\\media\\font.ttf"
local fontSize = 16

-- Global Frame sizes (including: Healthbar, Mana/Energybar, Infobar)
local width,  height  = 275, 50 -- Player and Target
local pwidth, pheight = 200, 20 -- Focus, Party and Party Pet
local twidth, theight = 200, 20 -- Target of Target

-- Colors
-- ClassColor Support beneficial?!?
oUF.colors.class = {
	["DEATHKNIGHT"] = { 196/255,  30/255,  60/255 },
	["DRUID"]       = { 255/255, 125/255,  10/255 },
	["HUNTER"]      = { 171/255, 214/255, 116/255 },
	["MAGE"]        = { 104/255, 205/255, 255/255 },
	["PALADIN"]     = { 245/255, 140/255, 186/255 },
	["PRIEST"]      = { 212/255, 212/255, 212/255 },
	["ROGUE"]       = { 255/255, 243/255,  82/255 },
	--["SHAMAN"]      = {   0/255, 254/255, 255/255 },	-- Caith's Shaman color
	["SHAMAN"]      = {  11/255, 104/255, 255/255 },	-- More traditional Shaman blue
	["WARLOCK"]     = { 148/255, 130/255, 201/255 },
	["WARRIOR"]     = { 199/255, 156/255, 110/255 },
}

oUF.colors.power = {
	['MANA']            = { 104/255, 155/255, 217/255 }, -- Mana
	['RAGE']            = { 231/255,  81/255,  75/255 }, -- Rage
	['FOCUS']           = { 255/255, 209/255,  71/255 }, -- Focus
	['ENERGY']          = { 255/255, 255/255, 255/255 }, -- Energy
	['RUNIC_POWER']     = {   0/255, 209/255, 255/255 }, -- Runic Power
}

local health = {
	[0] = { r = 255/255, g =   0/255, b =   0/255 }, -- Red
	[1] = { r = 255/255, g = 255/255, b =   0/255 },  -- Yellow-ish
	[2] = { r =   0/255, g = 255/255, b =   0/255 }, -- Green
}

local UnitReactionColor = {
	[1] = { 219/255, 48/255,  41/255 }, -- Hated
	[2] = { 219/255, 48/255,  41/255 }, -- Hostile
	[3] = { 219/255, 48/255,  41/255 }, -- Unfriendly
	[4] = { 218/255, 197/255, 92/255 }, -- Neutral
	[5] = { 75/255,  175/255, 76/255 }, -- Friendly
	[6] = { 75/255,  175/255, 76/255 }, -- Honored
	[7] = { 75/255,  175/255, 76/255 }, -- Revered
	[8] = { 75/255,  175/255, 76/255 }, -- Exalted
}
oUF.colors.reaction = UnitReactionColor

--[[
local grey = {0.5, 0.5, 0.5}
local white = {1, 1, 1}
]]

-- Colors on Infobar for Health, Mana/Energy - at the moment only the first entry is actually used
local verbosehp = "|cff00FF00%d|r |cffFFFFFF|||r |cff395A09%d|r"  -- 1234 | 5678 [colored green]
local verbosepp = "|cff5EAEF7%d|r |cffFFFFFF|||r |cff063C82%d|r"  -- 1234 | 5678 [colored blue]
--local verboseep = "|cff5EAEF7%d|r |cffFFFFFF|||r |cff063C82%d|r"  -- 1234 | 5678 [colored white]
--local verboserp = "|cff5EAEF7%d|r |cffFFFFFF|||r |cff063C82%d|r"  -- 1234 | 5678 [colored red]

-- Color Gradient for Target Health-Text in %
local perhp     = "|cff%02x%02x%02x%s%%|r"						  -- 100% [colored gradient]


-- Custom Variables for the Caith-UI
-- ----------------------------------------------------------------------------

local select = select
--local UnitName = UnitName
local UnitLevel = UnitLevel
local UnitClass = UnitClass
local UnitIsDead = UnitIsDead
local UnitIsGhost = UnitIsGhost
local UnitIsPlayer = UnitIsPlayer
local UnitIsTapped = UnitIsTapped
local UnitRace = UnitRace
local UnitReaction = UnitReaction
local UnitPowerType = UnitPowerType
local UnitIsConnected = UnitIsConnected
local UnitIsTappedByPlayer = UnitIsTappedByPlayer
local UnitClassification = UnitClassification
local UnitCreatureType = UnitCreatureType

local playerClass = select(2, UnitClass("player")) -- combopoints for druid/rogue
local playerName = UnitName("player")


-- Custom tags
-- ----------------------------------------------------------------------------

oUF.TagEvents["[verbosehp]"]   = "UNIT_HEALTH UNIT_MAXHEALTH"
oUF.Tags["[verbosehp]"] = function(unit)
	local c, m = UnitHealth(unit), UnitHealthMax(unit) 
	return (c <= 1 or not UnitIsConnected(unit)) and "" or verbosehp:format(c, m) end

oUF.TagEvents["[perhpgrad]"]   = "UNIT_HEALTH UNIT_MAXHEALTH"
oUF.Tags["[perhpgrad]"] = function(unit)
	local v = oUF.Tags["[perhp]"](unit)

	if v < 100 and v > 0 then
		-- Color health percent value in a gradient
		local r, g, b = oUF.ColorGradient(v / 100.00, -- Function expects a decimal
			health[0].r, health[0].g, health[0].b,
			health[1].r, health[1].g, health[1].b,
			health[2].r, health[2].g, health[2].b
		)
		return perhp:format(r * 255, g * 255, b * 255, v)
	end
	return ""
end

oUF.TagEvents["[verbosepp]"]   = "UNIT_MANA UNIT_RAGE UNIT_FOCUS UNIT_ENERGY UNIT_RUNIC_POWER UNIT_MAXMANA UNIT_MAXRAGE UNIT_MAXFOCUS UNIT_MAXENERGY UNIT_MAXRUNIC_POWER"
oUF.Tags["[verbosepp]"] = function(unit) 
	local c, m = UnitMana(unit), UnitManaMax(unit) 
	return (c <= 1 or not UnitIsConnected(unit)) and "" or verbosepp:format(c, m) end

oUF.TagEvents["[verbosename]"] = "UNIT_NAME_UPDATE UNIT_HEALTH UNIT_TARGET"
oUF.Tags["[verbosename]"] = function(unit)
	if unit == "player" then return "" end
	
	local name = "%s |cff%02x%02x%02x%s|r %s"
	local classifications = {
		["worldboss"] = "??",
		["rareelite"] = "%s*+",
		["rare"] = "%s*",
		["elite"] = "%s+",
		["normal"] = "%s",
		["trivial"] = "%s",
	}
	
	local _, c = UnitClass(unit)
	local color = oUF.colors.class[c] or UnitReactionColor[4]
		
	if unit == "target" then
		local cl = UnitClassification(unit)
		local level = classifications[cl] and classifications[cl]:format(UnitLevel(unit)) or UnitLevel(unit)
		local n = UnitName(unit) or ''
		local race = UnitRace(unit) or UnitCreatureType(unit) or ''
		return name:format(level, color[1] * 255, color[2] * 255, color[3] * 255, n, race)
	elseif unit == "targettarget" then
		local n = UnitName(unit) or ''
		if n == playerName then
			return "|cffFFFFFF<< You >>|r"
		else
			return name:format('', color[1] * 255, color[2] * 255, color[3] * 255, n, '')
		end
	else
		local n = UnitName(unit) or ''
		local level = UnitLevel(unit)
		return name:format(level, color[1] * 255, color[2] * 255, color[3] * 255, n, '')
	end
end


-- General Functions / Triggers for optional Deps
-- ----------------------------------------------------------------------------

local menu = function(self)
	local unit = self.unit:sub(1, -2)
	local cunit = self.unit:gsub("(.)", string.upper, 1)

	if unit == "party" or unit == "partypet" then
		ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..self.id.."DropDown"], "cursor", 0, 0)
	elseif _G[cunit.."FrameDropDown"] then
		ToggleDropDownMenu(1, nil, _G[cunit.."FrameDropDown"], "cursor", 0, 0)
	end
end

local function auraIcon(self, button)
	local t = button:CreateTexture(nil, "OVERLAY")
	t:SetTexture(borderTexture)
	t:SetAllPoints(button)
	t:SetVertexColor(0.25, 0.25, 0.35)
end

local backdrop = {
	bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", 
	insets = {left = -2, right = -2, top = -2, bottom = -2},
}

local function createString(parent, fontSize)
	local fs = parent:CreateFontString(nil, "OVERLAY")
	fs:SetFont(font, fontSize)
	fs:SetShadowColor(0, 0, 0, 0.9)
	fs:SetShadowOffset(1, -1)
	--fs:SetTextColor(1,1,1)
	--fs:SetPoint("RIGHT", -4, 2)
	return fs
end

-- Combat Feedback for Player / Targetframes
local function createCombatFeedback(self, parent)
	if IsAddOnLoaded("oUF_CombatFeedback") then
		local cbft = parent:CreateFontString(nil, "OVERLAY")
		cbft:SetPoint("LEFT", 4, 0)
		cbft:SetFont(font, fontSize + 2)
		cbft:SetShadowColor(0, 0, 0, 0.9)
		cbft:SetShadowOffset(1, -1)
		
		self.CombatFeedbackText = cbft
		self.CombatFeedbackText.maxAlpha = .6
		
		self.CombatFeedbackText.ignoreHeal     = false
		self.CombatFeedbackText.ignoreImmune   = false
		self.CombatFeedbackText.ignoreDamage   = false
		self.CombatFeedbackText.ignoreEnergize = true
		self.CombatFeedbackText.ignoreOther    = true
	end
end

-- Power Spark (Playerframe only)
local function createPowerSpark(parent)
	if IsAddOnLoaded("oUF_PowerSpark") then
		local spark = parent:CreateTexture(nil, "OVERLAY")
		spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
		spark:SetBlendMode("ADD")
		spark:SetVertexColor(1, 1, 1, 0.5)
		spark:SetHeight(parent:GetHeight()*2)
		spark:SetWidth(parent:GetHeight())
		spark.manatick = true
		
		return spark
	end
	
	return nil
end


-- Frame Creation
-- ----------------------------------------------------------------------------

local function createBarFrame(parent, height)
	local bar = CreateFrame("StatusBar")
	bar:SetHeight(height)
	bar:SetStatusBarTexture(statusbarTexture)
	bar:SetParent(parent)
	bar:SetPoint("LEFT")
	bar:SetPoint("RIGHT")
	
	return bar
end
local function createInfoBarFrame(parent)
	local bar = createBarFrame(parent, 20)
	bar:SetStatusBarColor(1, 1, 1, 0.1)
	bar:SetPoint("TOP", parent, "BOTTOM", 0, -10)
	
	return bar
end
local function createHealthBarFrame(parent)
	local bar = createBarFrame(parent, 25)
	--bar:SetStatusBarColor(1, 1, 0)
	bar:SetPoint("TOP", 0, 1)
	bar:SetPoint("LEFT", -1, 0)
	bar:SetPoint("RIGHT", 1, 0)
	
	bar.colorTapping = true
	bar.colorHappiness = true
	bar.colorDisconnected = true
	bar.colorClass = true
	bar.colorClassNPC = false
	bar.colorReaction = true
	bar.frequentUpdates = true
	
	local bg = bar:CreateTexture(nil, "BORDER")
	bg:SetHeight(bar:GetHeight())
	bg:SetWidth(bar:GetWidth())
	bg:SetTexture(0.3, 0.3, 0.3)
	bg:SetPoint("LEFT")
	bg:SetPoint("RIGHT")
	
	bar.bg = bg
	
	return bar
end
local function createPowerBarFrame(parent)
	local bar = createBarFrame(parent, 7)
	--bar:SetStatusBarColor(.25, .25, .35)
	bar:SetPoint("TOP", parent, "BOTTOM", 0, -1)
	bar:SetPoint("LEFT")
	bar:SetPoint("RIGHT")
	
	bar.colorTapping = false
	bar.colorDisconnected = true
	bar.colorPower = true
	bar.frequentUpdates = true
	
	local bg = bar:CreateTexture(nil, "BORDER")
	bg:SetHeight(bar:GetHeight())
	bg:SetWidth(bar:GetWidth())
	bg:SetTexture(0.3, 0.3, 0.3)
	bg:SetPoint("LEFT")
	bg:SetPoint("RIGHT")
	
	bar.bg = bg
	return bar
end

local func = function(settings, self, unit)
	self.unit = unit
	
	self.menu = menu
	self:SetScript("OnEnter", UnitFrame_OnEnter)
	self:SetScript("OnLeave", UnitFrame_OnLeave)
	self:RegisterForClicks("anyup")
	self:SetAttribute("*type2", "menu")
	self:SetBackdrop(backdrop)
	self:SetBackdropColor(0, 0, 0, .9)
	
	-- Player ---------------------------------------------
	if unit == 'player' then
		local ib = createInfoBarFrame(self)		-- Info Bar
		local hp = createHealthBarFrame(self) 	-- Health Bar
		local pp = createPowerBarFrame(hp) 		-- Power Bar
		
		createCombatFeedback(self, hp)			-- Combat Feedback
		
		-- Health Values (Tags)
		local hpv = createString(ib, fontSize)
		hpv:SetPoint("RIGHT", -4, 0)
		hpv.frequentUpdates = 0.1
		self:Tag(hpv, "[status]   [verbosehp]")
		
		-- Power Values (Tags)
		local ppv = createString(ib, fontSize)
		ppv:SetPoint("LEFT", 4, 0)
		ppv.frequentUpdates = 0.1
		self:Tag(ppv, "[verbosepp]")
		
		self.Health = hp
		self.Power = pp
		
		self.Spark = createPowerSpark(pp)
		
		--[[if(class == "DEATHKNIGHT") then
			RuneFrame:SetParent(self)
			RuneFrame:SetScale(0.75)
			RuneFrame:SetPoint("TOPLEFT", self, "BOTTOMLEFT",0 , -3)
		end
		--]]
		
	-- Target ---------------------------------------------
	elseif unit == 'target' then
		local ib = createInfoBarFrame(self)		-- Info Bar
		local hp = createHealthBarFrame(self)	-- Health Bar
		local pp = createPowerBarFrame(hp)		-- Power Bar
		
		createCombatFeedback(self, hp)			-- Combat Feedback
		
		-- Name
		local name = createString(ib, fontSize)
		name:SetPoint("LEFT", 4, 0)
		name:SetJustifyH("LEFT")
		self:Tag(name, "[verbosename]")
		
		-- Health string (absolute)
		local hpv = createString(ib, fontSize)
		hpv:SetPoint("RIGHT", -4, 0)
		hpv.frequentUpdates = 0.1
		self:Tag(hpv, "[status] [verbosehp]")
		
		-- Prevent the name from going through the health values
		name:SetPoint("RIGHT", hpv, "LEFT")
		
		-- Health string (percentage)
		local hpp = createString(hp, fontSize + 2)
		hpp:SetPoint("RIGHT", -4, 0)
		hpp.frequentUpdates = 0.1
		self:Tag(hpp, "[perhpgrad]")
		
		-- Auras
		local auras = CreateFrame("Frame", nil, self)
		auras.size = width / 8
		auras:SetHeight(auras.size * 4)
		auras:SetWidth(width)
		auras:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 2)
		auras.numBuffs = 40
		auras.numDebuffs = 32
		auras.gap = true
		self.Auras = auras
		self.PostCreateAuraIcon = auraIcon
		
		-- Raid Icon TODO: Test
		local ricon = self:CreateTexture(nil, "OVERLAY")
		ricon:SetHeight(24)
		ricon:SetWidth(24)
		ricon:SetPoint("TOPLEFT", self, "TOPRIGHT", 4, 0)
		self.RaidIcon = ricon
		
		-- Combo Points
		--if playerClass == "ROGUE" or playerClass == "DRUID" then
			self.CPoints = createString(self, fontSize + 4)
			self.CPoints:SetPoint("RIGHT", self, "LEFT", -3, 3)
			self.CPoints:SetFont(font, 38, "OUTLINE")
			self.CPoints:SetJustifyH("RIGHT")
		--end
		
		self.Health = hp
		self.Power = pp
	-- TargetTarget ---------------------------------------
	elseif unit == 'targettarget' then
		--local ib = createInfoBarFrame(self)			-- Info Bar
		local hp = createHealthBarFrame(self)		-- Health Bar
		local pp = createPowerBarFrame(hp)			-- Power Bar
		
		--ib:SetHeight(14)
		hp:SetHeight(15)
		hp.bg:SetHeight(15)
		pp:SetHeight(5)
		
		-- Name
		local name = createString(hp, fontSize)
		name:SetPoint("CENTER", 0, 2)
		name:SetJustifyH("CENTER")
		self:Tag(name, "[status] [verbosename]")
		
		self.Health = hp
		self.Power = pp
	-- Pet ---------------------------------------
	elseif unit == 'pet' then --or unit == 'vehicle' then
		--local ib = createInfoBarFrame(self)			-- Info Bar
		local hp = createHealthBarFrame(self)		-- Health Bar
		local pp = createPowerBarFrame(hp)			-- Power Bar
		
		--ib:SetHeight(14)
		hp:SetHeight(15)
		hp.bg:SetHeight(15)
		pp:SetHeight(5)
		
		self.Health = hp
		self.Power = pp
	-- Focus ----------------------------------------------
	elseif unit == "focus" then
		local hp = createHealthBarFrame(self)		-- Health Bar
		local pp = createPowerBarFrame(hp)			-- Power Bar
		
		hp:SetHeight(15)
		hp.bg:SetHeight(15)
		pp:SetHeight(5)
		
		-- Name
		local name = createString(self, fontSize)
		name:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 2)
		self:Tag(name, "[verbosename]")
		
		-- Health Percent
		local hpp = createString(hp, fontSize-2)
		hpp:SetPoint("RIGHT", -4, 2)
		hpp.frequentUpdates = 0.1
		self:Tag(hpp, "[status] [perhpgrad]")
		
		-- Auras
		local auras = CreateFrame("Frame", nil, self)
		local s = pp:GetHeight() + hp:GetHeight()
		auras.size = s
		auras:SetHeight(s)
		auras:SetWidth(s * 4)
		auras:SetPoint("LEFT", self, "RIGHT", 4, 0)
		auras.initialAnchor = "TOPLEFT"
		auras.numBuffs = 1
		auras.numDebuffs = 3
		--self.Auras = auras
		
		self.Health = hp
		self.Power = pp

		self.PostCreateAuraIcon = auraIcon
	-- Party ----------------------------------------------
	elseif not unit then
		local hp = createHealthBarFrame(self)		-- Health Bar
		local pp = createPowerBarFrame(hp)			-- Power Bar
		
		hp:SetHeight(16)
		hp.bg:SetHeight(16)
		pp:SetHeight(4)
		
		-- Name
		local name = createString(self, fontSize)
		name:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 2)
		self:Tag(name, "[verbosename]")
		
		-- Health Deficit
		local hpd = createString(hp, fontSize-2)
		hpd:SetPoint("RIGHT", -4, 2)
		self:Tag(hpd, "[status] [missinghp]")
		
		-- Auras (Debuffs only)
		local debuffs = CreateFrame("Frame", nil, self)
		local s = pp:GetHeight() + hp:GetHeight()
		debuffs.size = s
		debuffs:SetHeight(s)
		debuffs:SetWidth(s * 4)
		debuffs:SetPoint("LEFT", self, "RIGHT", 4, 0)
		debuffs.initialAnchor = "TOPLEFT"
		debuffs.num = 4
		self.Debuffs = debuffs
		self.PostCreateAuraIcon = auraIcon
		
		-- Range Filtering
		self.Range = true
		self.inRangeAlpha = 1
		self.outsideRangeAlpha = .5
		
		self.Health = hp
		self.Power = pp
	end

	--self:SetFrameStrata("BACKGROUND")
	--return self
end

oUF:RegisterStyle("caith", setmetatable({
	["initial-width"] = width,
	["initial-height"] = height,
}, {__call = func}))

oUF:RegisterStyle("caith_ToT", setmetatable({
	["initial-width"] = twidth,
	["initial-height"] = theight,
}, {__call = func}))

oUF:RegisterStyle("caith_Party", setmetatable({
	["initial-width"] = pwidth,
	["initial-height"] = pheight,
}, {__call = func}))

-- ----------------------------------------------------------------------------
-- Player, ToT, Target
-- ----------------------------------------------------------------------------

oUF:SetActiveStyle("caith")

local player = oUF:Spawn("player")
player:SetPoint("BOTTOM", -300, 250)

local target = oUF:Spawn("target")
target:SetPoint("BOTTOM", 300, 250)

oUF:SetActiveStyle("caith_ToT")

local tot = oUF:Spawn("targettarget")
tot:SetPoint("BOTTOM", 0, 250)

local pet = oUF:Spawn("pet")
pet:SetPoint("BOTTOM", tot, "TOP", 0, 5)

--[[
local toggleVehicle = CreateFrame("Frame")
toggleVehicle:RegisterEvent("UNIT_ENTERED_VEHICLE")
toggleVehicle:SetScript("OnEvent", function(self, event, arg1)
	if ( event == "UNIT_ENTERED_VEHICLE" and arg1 == "player" ) then
		local vehicle = oUF:Spawn("vehicle")
		vehicle:SetPoint("BOTTOM", tot, "TOP", 0, 5)
	end
end)
--]]

-- ----------------------------------------------------------------------------
-- Focus, Party, Party Pets
-- ----------------------------------------------------------------------------

oUF:SetActiveStyle("caith_Party")

local focus = oUF:Spawn("focus")
focus:SetPoint("BOTTOMRIGHT", player, "TOPLEFT", -10, 250)

local party = oUF:Spawn("header", "oUF_Party")
party:SetPoint("BOTTOMLEFT", target, "TOPRIGHT", 15, 250)
party:SetAttribute("yOffset", pheight - (pheight * 2)) -- Grow up (does -pheight work?)
party:SetAttribute("showParty", true)

local partypet = oUF:Spawn("header", "oUF_PartyPets", true)
partypet:SetPoint("BOTTOM", party, "TOP", 0, pheight)
partypet:SetAttribute("yOffset", pheight - (pheight * 2)) -- Grow up (does -pheight work?)
partypet:SetAttribute("showParty", true)

local toggleParty = CreateFrame("Frame")
toggleParty:SetScript("OnEvent", function(self)
	if InCombatLockdown() then 
		self:RegisterEvent("PLAYER_REGEN_ENABLED")
	else
		self:UnregisterEvent("PLAYER_REGEN_ENABLED")
		if GetNumRaidMembers() > 0 then
			party:Hide()
			partypet:Hide()
		elseif GetNumPartyMembers() > 0 then
			party:Show()
			partypet:Show()
			
			partypet:SetPoint("BOTTOM", party, "TOP", 0, GetNumPartyMembers() * pheight)
		end
	end
end)
toggleParty:RegisterEvent("PARTY_MEMBERS_CHANGED")
toggleParty:RegisterEvent("PARTY_LEADER_CHANGED")
toggleParty:RegisterEvent("RAID_ROSTER_UPDATE")
toggleParty:RegisterEvent("PLAYER_LOGIN")
I have made the decicive part in the code bold.
Everything is working as intendet as long as the "bar.frequentUpdates" part is not set to true in the powerbar function...

Thanks in advance.