Thread Tools Display Modes
07-23-20, 08:20 AM   #1
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
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)
  Reply With Quote
07-23-20, 11:41 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-23-20 at 12:18 PM.
  Reply With Quote
07-24-20, 01:23 AM   #3
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
Thank you...
  Reply With Quote
07-24-20, 09:14 AM   #4
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
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 "".

Last edited by glupikreten : 07-24-20 at 10:47 AM.
  Reply With Quote
07-24-20, 10:48 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-24-20 at 10:55 AM.
  Reply With Quote
07-24-20, 11:07 AM   #6
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
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.
  Reply With Quote
07-24-20, 11:16 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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))
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-24-20, 11:27 AM   #8
glupikreten
A Theradrim Guardian
Join Date: Apr 2009
Posts: 60
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...

Last edited by glupikreten : 07-24-20 at 12:08 PM.
  Reply With Quote
07-24-20, 12:28 PM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-24-20 at 02:32 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » TargetFrameAura manipulation

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off