Thread Tools Display Modes
01/04/23, 06:34 AM   #1
wido1234
Join Date: Dec 2022
Posts: 2
Combat Text shows when reloading UI or starting the game

Hey. i yesterday tried to, create my first addon, with the esoui tutorial. But somehow my "fighting" text always shows when i reloadui or log into the game. when i then fight it works like intended. what did i wrong.
i named my addon "Avatar", but the code is copied from the tut. also i changed it to be account wide. with the NewAccountWide thing






Here my lua code:

-- First, we create a namespace for our addon by declaring a top-level table that will hold everything else.
Avatar = {}

-- This isn't strictly necessary, but we'll use this string later when registering events.
-- Better to define it in a single place rather than retyping the same string.
Avatar.name = "Avatar"

-- Next we create a function that will initialize our addon
function Avatar.Initialize()
Avatar.inCombat = IsUnitInCombat("player")

EVENT_MANAGER:RegisterForEvent(Avatar.name, EVENT_PLAYER_COMBAT_STATE, Avatar.OnPlayerCombatState)

Avatar.savedVariables = ZO_SavedVars:NewAccountWide("AvatarSavedVariables", 1, nil, {})
end
-- ...but we don't have anything to initialize yet. We'll come back to this.
function Avatar.OnPlayerCombatState(event, inCombat)
-- The ~= operator is "not equal to" in Lua.
if inCombat ~= Avatar.inCombat then
-- The player's state has changed. Update the stored state...
Avatar.inCombat = inCombat

-- ...and then update the control.
AvatarIndicator:SetHidden(not inCombat)
end
end

function Avatar.OnIndicatorMoveStop()
Avatar.savedVariables.left = AvatarIndicator:GetLeft()
Avatar.savedVariables.top = AvatarIndicator:GetTop()
end

function Avatar.RestorePosition()
local left = Avatar.savedVariables.left
local top = Avatar.savedVariables.top

AvatarIndicator:ClearAnchors()
AvatarIndicator:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
end

function Avatar.Initialize()
Avatar.inCombat = IsUnitInCombat("player")

EVENT_MANAGER:RegisterForEvent(Avatar.name, EVENT_PLAYER_COMBAT_STATE, Avatar.OnPlayerCombatState)

Avatar.savedVariables = ZO_SavedVars:NewCharacterIdSettings("AvatarSavedVariables", 1, nil, {})

Avatar.RestorePosition()
end

-- Then we create an event handler function which will be called when the "addon loaded" event
-- occurs. We'll use this to initialize our addon after all of its resources are fully loaded.
function Avatar.OnAddOnLoaded(event, addonName)
-- The event fires each time *any* addon loads - but we only care about when our own addon loads.
if addonName == Avatar.name then
Avatar.Initialize()
--unregister the event again as our addon was loaded now and we do not need it anymore to be run for each other addon that will load
EVENT_MANAGER:UnregisterForEvent(Avatar.name, EVENT_ADD_ON_LOADED)
end
end

-- Finally, we'll register our event handler function to be called when the proper event occurs.
-->This event EVENT_ADD_ON_LOADED will be called for EACH of the addns/libraries enabled, this is why there needs to be a check against the addon name
-->within your callback function! Else the very first addon loaded would run your code + all following addons too.
EVENT_MANAGER:RegisterForEvent(Avatar.name, EVENT_ADD_ON_LOADED, Avatar.OnAddOnLoaded)

Last edited by wido1234 : 01/04/23 at 06:36 AM.
  Reply With Quote
01/04/23, 06:47 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,971
If it shows upon loading into the game you have forgotten to set your fighting text control invisible at the start (OnAddOnLoaded)

AvatarIndicator:SetHidden(true)

You currently do this only in your InCombat callback function which is not fired until you first get into combat.
AvatarIndicator:SetHidden(not inCombat)


e.g.
Lua Code:
  1. function Avatar.Initialize()
  2.     AvatarIndicator:SetHidden(true) --add this
  3.  
  4.     Avatar.inCombat = IsUnitInCombat("player")
  5.  
  6.     EVENT_MANAGER:RegisterForEvent(Avatar.name, EVENT_PLAYER_COMBAT_STATE, Avatar.OnPlayerCombatState)
  7.  
  8.     Avatar.savedVariables = ZO_SavedVars:NewAccountWide("AvatarSavedVariables", 1, nil, {})
  9. end
  Reply With Quote
01/10/23, 03:03 AM   #3
wido1234
Join Date: Dec 2022
Posts: 2
Originally Posted by Baertram View Post
If it shows upon loading into the game you have forgotten to set your fighting text control invisible at the start (OnAddOnLoaded)

AvatarIndicator:SetHidden(true)

You currently do this only in your InCombat callback function which is not fired until you first get into combat.
AvatarIndicator:SetHidden(not inCombat)


e.g.
Lua Code:
  1. function Avatar.Initialize()
  2.     AvatarIndicator:SetHidden(true) --add this
  3.  
  4.     Avatar.inCombat = IsUnitInCombat("player")
  5.  
  6.     EVENT_MANAGER:RegisterForEvent(Avatar.name, EVENT_PLAYER_COMBAT_STATE, Avatar.OnPlayerCombatState)
  7.  
  8.     Avatar.savedVariables = ZO_SavedVars:NewAccountWide("AvatarSavedVariables", 1, nil, {})
  9. end
Thank you
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Combat Text shows when reloading UI or starting the game


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