Thread Tools Display Modes
Prev Previous Post   Next Post Next
07/30/21, 08:35 AM   #1
rosalith
Join Date: Jun 2021
Posts: 3
Help with first addon!

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:
  1. HideCritterHealthbar = {}
  2.  
  3. HideCritterHealthbar.name = "HideCritterHealthbar"
  4.  
  5. function HideCritterHealthbar.OnAddOnLoaded(event, addonName)
  6.     if addonName == HideCritterHealthbar.name then
  7.         HideCritterHealthbar:Initialize()
  8.     end
  9. end
  10.  
  11. function HideCritterHealthbar:Initialize()
  12.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_RETICLE_TARGET_CHANGED, self.Main)
  13.     EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED)
  14. end
  15.  
  16. -- main function that runs every time target changes
  17. function HideCritterHealthbar.Main(event)
  18.     local rName = GetUnitName("reticleover")
  19.     local rReaction = GetUnitReaction("reticleover")
  20.     local rIsCritter
  21.  
  22.     if (rReaction == 2 or rReaction == 3 or rReaction == 5) then
  23.         if (rName == "Beetle" or
  24.         rName == "Butterfly" or
  25.         rName == "Rat") then
  26. -- ^ I cut down that list so that its neater here, longer in the real code
  27.  
  28.             rIsCritter = true
  29.         else
  30.             rIsCritter = false
  31.         end
  32.     else
  33.         rIsCritter = false
  34.     end
  35.  
  36.     UNIT_FRAMES:SetFrameHiddenForReason("reticleover", "disabled", rIsCritter)
  37.     ZO_UnitFrames_UpdateWindow("reticleover", true)
  38. end
  39.  
  40. EVENT_MANAGER:RegisterForEvent(HideCritterHealthbar.name, EVENT_ADD_ON_LOADED, HideCritterHealthbar.OnAddOnLoaded)
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » Help with first addon!


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