Originally Posted by Phanx
Your code is creating a new copy of a function every time any unit frame is updated, which is really bad. It's also hardcoding the unit to "target" which is probably not what you want, unless you only want your code to work on the target frame, in which case it's still the wrong way to go about it; if you want to limit it to the target frame, you need to check the actual unit and return out if it's not "target", as the current method will color every unit frame according to the properties of your current target.
The code I posted has nothing to do with oUF or tags, but after looking at it again, I see I forgot to define the "unit" variable. You should really have some kind of error display turned on. It will make things so much easier for you (and anyone else who tries to help you) while you're working with code. If you already have one (I recommend BugSack) then you should really post the error message when you report that something "doesn't work".
Anyway, here is a fixed version:
Code:
hooksecurefunc("UnitFrame_Update", function(self)
if not self.name then return end
local unit = self.unit -- THIS WAS MISSING
local color
if UnitIsPlayer(unit) then
local _, class = UnitClass(unit)
color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
elseif UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
color = GRAY_FONT_COLOR
elseif UnitIsEnemy(unit, "player") then
color = FACTION_BAR_COLORS[1]
else
local reaction = UnitReaction(unit, "player")
color = reaction and FACTION_BAR_COLORS[reaction] or FACTION_BAR_COLORS[5]
end
if not color then
color = NORMAL_FONT_COLOR
end
self.name:SetTextColor(color.r, color.g, color.b)
end)
Edit: And for your "hide text on dead units" just do this:
Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax)
if value == 0 then
return fontString:SetText("")
end
local style = GetCVar("statusTextDisplay")
if style == "PERCENT" then
|
Thank You for the updates they work perfectly.
Also installed bugsack as suggested. Right now no errors.
Thanks again for all your help.
Coke