WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   TargetFrameAura manipulation (https://www.wowinterface.com/forums/showthread.php?t=58119)

glupikreten 07-23-20 08:20 AM

TargetFrameAura manipulation
 
Hi,

I have this piece of code... it works in 99.99% of the cases... Can anyone tell me why it wouldn't be doing in 100% of them? :)

Ignore the double for loops... I tried different stuff and this was the last iteration... I know it should be only one :)

Code:

local function SkinTarget()
        if TargetFrame:IsShown() then
                TargetFrameHealthBarText:ClearAllPoints()
                TargetFrameHealthBarText:SetPoint("CENTER", TargetFrame, "CENTER", -50, 7)
                TargetFrameManaBarText:SetScale(0.8)

                for i = 1, 32 do
                        _, spellId, _, _, _, _, unitCaster = UnitBuff("target", i)
                        if (spellId) then
                                frame = _G["TargetFrameBuff" .. i]
                                frameBorder = _G["TargetFrameBuff" .. i .. "Border"]
                                frameCount = _G["TargetFrameBuff" .. i .. "Count"]

                                if (frameBorder ~= nil) then
                                        frameBorder:Hide()
                                end

                                if (frameCount ~= nil) then
                                        frameCount:SetFont(config.font.atari, config.buff.fontsize, config.buff.outline)
                                        frameCount:SetPoint(unpack(config.buff.position))
                                end

                                if (frame ~= nil) then
                                        frame:CreateBeautyBorder(config.buff.bordersize)
                                        frame:SetBeautyBorderTexture(config.border.default)
                                        frame:SetScale(config.buff.scale)
                                end
                        end
                end

                for i = 1, 32 do
                        _, spellId, _, _, _, _, unitCaster = UnitDebuff("target", i)
                        if (spellId) then
                                frame = _G["TargetFrameDebuff" .. i]
                                frameBorder = _G["TargetFrameDebuff" .. i .. "Border"]
                                frameCount = _G["TargetFrameDebuff" .. i .. "Count"]

                                if (frameBorder ~= nil) then
                                        frameBorder:Hide()
                                end

                                if (frameCount ~= nil) then
                                        frameCount:SetFont(config.font.atari, config.debuff.fontsize, config.debuff.outline)
                                        frameCount:SetPoint(unpack(config.debuff.position))
                                end

                                if (select(4, UnitDebuff("target", i))) then
                                        color = config.ReplacedDebuffTypeColor[select(4, UnitDebuff("target", i))]
                                else
                                        color = config.ReplacedDebuffTypeColor["none"]
                                end

                                if (frame ~= nil) then
                                        frame:CreateBeautyBorder(config.debuff.bordersize)
                                        frame:SetBeautyBorderTexture(config.border.colorize)
                                        frame:SetBeautyBorderColor(color.r, color.g, color.b)
                                        frame:SetScale(config.buff.scale)
                                end
                        end
                end
        end
end

hooksecurefunc("TargetFrame_UpdateAuras", SkinTarget)


Fizzlemizz 07-23-20 11:41 AM

The function is called only when the frames .threatNumericIndicator shows/hides. Try running the function after hooking it to set an initial state.

Slight change to SkinTarget:
Code:

local function SkinTarget(init)
        if init or TargetFrame:IsShown() then
...

Code:

hooksecurefunc("TargetFrame_UpdateAuras", SkinTarget)
SkinTarget(true)


glupikreten 07-24-20 01:23 AM

Thank you...

glupikreten 07-24-20 09:14 AM

The issue I'm having is that when I try to /run print(UnitBuff("target",1)) on target that is mob or enemy I get nil. On friendly players, it works as it should.

https://freeimage.host/i/dICNOG


i guess my problem then is in comparing frame with ~=nil instead of just saying if(frame).... if only indicator that there is a frame is when i get nil instead of "".

Fizzlemizz 07-24-20 10:48 AM

Do you need to check for a buff? It seems you could alter the frames regardless of buff so long as you only do it once for each (assuming frame:CreateBeautyBorder creates a new frame each time)

Something more like:
Lua Code:
  1. -- This probalby only needs to run once at startup
  2. TargetFrameHealthBarText:ClearAllPoints()
  3. TargetFrameHealthBarText:SetPoint("CENTER", TargetFrame, "CENTER", -50, 7)
  4. TargetFrameManaBarText:SetScale(0.8)
  5.  
  6. local MaxReached
  7. local function SkinTarget()
  8.     if MaxReached then return end -- Why keep doing it
  9.     if TargetFrame:IsShown() then
  10.         for i = 1, MAX_TARGET_BUFFS do
  11.             frame = _G["TargetFrameBuff" .. i]
  12.             if not frame then break end
  13.             if not frame.BeautyBorder then -- Have we adjusted this frame before?
  14.                 frame:CreateBeautyBorder(config.buff.bordersize)
  15.                 frame:SetBeautyBorderTexture(config.border.default)
  16.                 frame:SetScale(config.buff.scale)
  17.                 frame.BeautyBorder = true
  18.                 frameBorder = _G["TargetFrameBuff" .. i .. "Border"]
  19.                 frameCount = _G["TargetFrameBuff" .. i .. "Count"]
  20.                 frameBorder:Hide()
  21.                 frameCount:SetFont(config.font.atari, config.buff.fontsize, config.buff.outline)
  22.                 frameCount:SetPoint(unpack(config.buff.position))
  23.                 if i == MAX_TARGET_BUFFS then
  24.                     MaxReached = true
  25.                 end
  26.             end
  27.         end
  28.     end
  29. end

glupikreten 07-24-20 11:07 AM

CreateBeautyBorder api has check and returns if alreadz created.

what puzzles me is /run print(UnitBuff("target",1)) on enemy returns nil for existing frame.

Fizzlemizz 07-24-20 11:16 AM

Does the target have a buff or is it a debuff (something bad you applied)?
Code:

/run print("UnitBuff", UnitBuff("target",1), "UnitDebuff", UnitDebuff("target",1))

glupikreten 07-24-20 11:27 AM

https://ibb.co/nsT6sB3

https://ibb.co/0yZ7QHp


And i get im noob... wow lua is not my area... still this eludes me:


Code:

local function test(init)  -- init no init its the same
        if init then
                print("target show")
                TargetFrameHealthBarText:ClearAllPoints()
                TargetFrameHealthBarText:SetPoint("CENTER", TargetFrame, "CENTER", -50, 7)
                TargetFrameManaBarText:SetScale(0.8)
        end
end

TargetFrame:SetScript("OnShow", test)
TargetFrame:SetScript("OnLoad", test)
TargetFrame:SetScript("WHATEVER", test)
test(true)

aint working.. echo works fine tho.

update: i found something called TargetFrame_CheckClassification... now it works...

Fizzlemizz 07-24-20 12:28 PM

Code:

TargetFrame:SetScript("OnLoad", test)
Given this is a Blizzard frame and non "load-on-demand" Blizzard code loads before 3rd party addons, by the time your code tries to set the TargetFrame OnLoad script, it is well past having done its thing.
Code:

TargetFrame:SetScript("WHATEVER", test)
This should give an error saying the frame has no WHATEVER script (assuming that's actual code) so the following line (test(true)) won't run because the error would have stopped execution.

Using a SetScript on someone else's frame is not a good idea as it overrides the original.
Code:

TargetFrame:HookScript("OnShow", function(self)  "do whatever" end)
Runs your code after the original script has run.


All times are GMT -6. The time now is 06:20 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI