Originally Posted by nKweo
Substituting the if-statement with a simple UnitExists("target") statement seems to work ok though (although it is not as elegant):
Code:
if (UnitExists("target")) then
|
I wouldn't do it that way because it's possible to have a target while the personal resource display isn't showing which would cause the code to specifically attach it to a wrong nameplate (or perhaps cause the code to panic and return a lua error if no nameplates are in range.)
Code:
local function attach()
if C_NamePlate.GetNamePlateForUnit("player") then
CastingBarFrame:ClearAllPoints()
CastingBarFrame:SetPoint("TOP",C_NamePlate.GetNamePlateForUnit("player"),"BOTTOM",0,-28)
--CastingBarFrame.SetPoint = function() end (seems to break the code)
else
CastingBarFrame:ClearAllPoints()
CastingBarFrame:SetPoint("TOP",UIParent,"BOTTOM",0,160)
--CastingBarFrame.SetPoint = function() end (seems to break the code)
end
end
local f = CreateFrame("frame")
f:RegisterUnitEvent("UNIT_SPELLCAST_START","player")
f:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START","player")
f:SetScript("OnEvent",attach)
Turns out
NamePlatePlayerResourceFrame can't be reliably used, using
C_NamePlate.GetNamePlateForUnit("player") instead gets the desired results (at least from my limited testing it does.)
Works with both default cast bar, and with "Cast Bar Underneath" enabled.
Originally Posted by nKweo
Moreover, there is a new problem I can't seem to solve now. I used CastingBarFrame.SetPoint = function() end to prevent to repositioned cast bar from stretching back to its original position. But entering this statement into the logic seems to break it... Can this be solved without too much hassle?
|
What actions are you doing in-game when this stretching happens? Is it during combat? I can't reproduce it.
Either way it breaks because CastingBarFrame:SetPoint() is calling CastingBarFrame.SetPoint, so if you zero out the latter it prevents the former from working.