Help: OnEvent Script

Trying to use KGpanels to load the gold dragon badge on an elite target frame…only it keeps loading for all targets:

OnLoad

self:RegisterEvent(“UNIT_TARGET”)
self:Hide()

OnEvent

if UnitExists(“target”) == nil then
self:Hide()
return
end
local cl = UnitClassification(“target”)
if (cl == “elite”) or (cl == “worldboss”) or (cl == “rareelite”) then
self:SetBackdropColor(0.1, 0.1, 0.1, 0.1)
self:Show()
else
self:SetBackdropColor(1, 1, 1, 1)
self:Show()
end

Anyone have a clue where this is breaking down?

if (cl == “elite”) or (cl == “worldboss”) or (cl == “rareelite”) then
	self:SetBackdropColor(0.1, 0.1, 0.1, 0.1)
	self:Show()
else
	self:SetBackdropColor(1, 1, 1, 1)
	self:Show()
end
if this or that or something else
   show
else
  show
end

The second show should probably be a hide as the rest just changes the backdrop (which shouldn’t be required if you’re just showing/hiding the frame).

You might want to use the PLAYER_TARGET_CHANGED event as that only fires when you (the player) change target.

1 Like

To add to what Fizzlemizz said, UnitExists(“target”) will never equal nil. It’s either true or false.

I recommend using

if not UnitExists("target") then
  etc...

Also /dump is a useful command when debugging/working on stuff if you’re unsure of results.

/dump UnitExists("target")
1 Like

Awesome places to start, thanks guys!!