Hi
I wrote a small addon that pretty much works as intended but theres an annoying bug that I can't figure out.
What the addon does is hides the target bar at the top of the screen only for certain creatures. The bug is that when I am looking at one of said creatures (and target bar is hidden correctly) and then look staright at someone else whose targetbar I DO want to see like an enemy or player, then that will be hidden too initially. You have to look away so that the is no target at all first.
Here is my entire code, if I made any daft mistakes pls be gentle I have no idea what I'm doing!
Lua Code:
HideCritterHealthbar = {}
HideCritterHealthbar.name = "HideCritterHealthbar"
function HideCritterHealthbar.OnAddOnLoaded(event, addonName)
if addonName == HideCritterHealthbar.name then
HideCritterHealthbar:Initialize()
end
end
function HideCritterHealthbar:Initialize()
EVENT_MANAGER:RegisterForEvent(self.name, EVENT_RETICLE_TARGET_CHANGED, self.Main)
EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED)
end
-- main function that runs every time target changes
function HideCritterHealthbar.Main(event)
local rName = GetUnitName("reticleover")
local rReaction = GetUnitReaction("reticleover")
local rIsCritter
if (rReaction == 2 or rReaction == 3 or rReaction == 5) then
if (rName == "Beetle" or
rName == "Butterfly" or
rName == "Rat") then
-- ^ I cut down that list so that its neater here, longer in the real code
rIsCritter = true
else
rIsCritter = false
end
else
rIsCritter = false
end
UNIT_FRAMES:SetFrameHiddenForReason("reticleover", "disabled", rIsCritter)
ZO_UnitFrames_UpdateWindow("reticleover", true)
end
EVENT_MANAGER:RegisterForEvent(HideCritterHealthbar.name, EVENT_ADD_ON_LOADED, HideCritterHealthbar.OnAddOnLoaded)