Thread Tools Display Modes
08/26/21, 07:28 PM   #1
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Having trouble using EVENT_ZONE_CHANGED

Hey all, back again.

My Wardrobe Manager Addon is really coming along, but I've noticed a few bugs, one of which is that when the character is sneaking and then fast travels, they're no longer sneaking but it doesn't trigger EVENT_STEALTH_STATE_CHANGED so the toon stays in the wrong outfit. I've tried forcing an outfit change listening to EVENT_ZONE_UPDATE, but I can't even get my function to call that should be hooked to it.

Any thoughts?

Code:
Lua Code:
  1. function LeonardosWardrobeManager:Initialize()
  2.     LeonardosWardrobeManager.savedVariables = ZO_SavedVars:NewCharacterIdSettings("LeonardosWardrobeManagerVars", LeonardosWardrobeManager.variableVersion, nil, LeonardosWardrobeManager.Default, GetWorldName())
  3.  
  4.     self.inCombat = IsUnitInCombat("player")
  5.     self.inStealth = GetUnitStealthState("player")
  6.  
  7.     for i=1,GetNumUnlockedOutfits() do
  8.         self.allOutfits[i + OUTFIT_OFFSET] = GetOutfitName(0, i)
  9.     end
  10.  
  11.     LAM2:RegisterAddonPanel("LeonardosWardrobeManagerOptions", panelData)
  12.     LAM2:RegisterOptionControls("LeonardosWardrobeManagerOptions", optionsData)
  13.  
  14.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_OUTFIT_RENAME_RESPONSE, self.OnOutfitRenamed)
  15.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_ZONE_UPDATE, self.OnZoneChange)
  16.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  17.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_STEALTH_STATE_CHANGED, self.OnPlayerStealthState)
  18. end

Lua Code:
  1. function LeonardosWardrobeManager.OnZoneChange() -- TODO: Still not working
  2.     d("triggered")
  3.     LeonardosWardrobeManager.ChangeOutfit(LeonardosWardrobeManager.savedVariables.defaultOutfitIndex)
  4. end
  Reply With Quote
08/26/21, 09:18 PM   #2
Calamath
AddOn Author - Click to view addons
Join Date: Aug 2019
Posts: 36
Hey, the code you showed seems to be EVENT_ZONE_UPDATED, not EVENT_ZONE_CHANGED, is this correct for your purpose?
  Reply With Quote
08/26/21, 09:52 PM   #3
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Originally Posted by Calamath View Post
Hey, the code you showed seems to be EVENT_ZONE_UPDATED, not EVENT_ZONE_CHANGED, is this correct for your purpose?
Haha I had tried it both ways and neither worked, I left the wrong one in my example. To be honest, I'm not entirely sure which one I should be using!

When I travel while crouched I uncrouch without triggering the stealth event, so when I do a loading screen travel I want to make sure I'm firing another event to make sure I'm in the correct outfit. Eventually I want to add the option for zone-specific outfits, so getting this to work is high on my todo list. :P
  Reply With Quote
08/26/21, 10:12 PM   #4
Calamath
AddOn Author - Click to view addons
Join Date: Aug 2019
Posts: 36
There are many ways to detect warping between different zones using fast travel, but I use EVENT_PLAYER_ACTIVATED.

Here is a hint.

Lua Code:
  1. local isFirstTimePlayerActivated = true
  2.  
  3. local function OnPlayerActivated(eventCode, initial)
  4.     if initial then
  5.         if isFirstTimePlayerActivated == false then
  6.             -- --------------------------------- after fast travel
  7.             -- do something
  8.         else
  9.             -- --------------------------------- after login
  10.             isFirstTimePlayerActivated = false
  11.         end
  12.     else
  13.         -- ------------------------------------- after reloadui
  14.         isFirstTimePlayerActivated = false
  15.     end
  16. end
  17.  
  18. EVENT_MANAGER:RegisterForEvent("yourAddonName", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)

Last edited by Calamath : 08/26/21 at 10:15 PM.
  Reply With Quote
08/26/21, 11:30 PM   #5
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Originally Posted by Calamath View Post
There are many ways to detect warping between different zones using fast travel, but I use EVENT_PLAYER_ACTIVATED.

Here is a hint.

Lua Code:
  1. local isFirstTimePlayerActivated = true
  2.  
  3. local function OnPlayerActivated(eventCode, initial)
  4.     if initial then
  5.         if isFirstTimePlayerActivated == false then
  6.             -- --------------------------------- after fast travel
  7.             -- do something
  8.         else
  9.             -- --------------------------------- after login
  10.             isFirstTimePlayerActivated = false
  11.         end
  12.     else
  13.         -- ------------------------------------- after reloadui
  14.         isFirstTimePlayerActivated = false
  15.     end
  16. end
  17.  
  18. EVENT_MANAGER:RegisterForEvent("yourAddonName", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
I implemented that and got the following error (I'll keep poking around for a bit but figured I'd reply immediately):

Code:
Checking type on argument callback failed in ScriptEventManagerRegisterForEventLua
stack traceback:
[C]: in function 'RegisterForEvent'
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:181: in function 'LeonardosWardrobeManager:Initialize'
|caaaaaa<Locals> self = [table:1]{variableVersion = 3, inStealth = 0, inCombat = F, name = "LeonardosWardrobeManager"} </Locals>|r
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:188: in function 'LeonardosWardrobeManager.OnAddOnLoaded'
|caaaaaa<Locals> _ = 65536, addonName = "LeonardosWardrobeManager" </Locals>|r
  Reply With Quote
08/26/21, 11:39 PM   #6
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Sorry, jumped the gun, after just a bit of tinkering that worked perfectly! Thank you so much.

Originally Posted by Leonardo1123 View Post
I implemented that and got the following error (I'll keep poking around for a bit but figured I'd reply immediately):

Code:
Checking type on argument callback failed in ScriptEventManagerRegisterForEventLua
stack traceback:
[C]: in function 'RegisterForEvent'
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:181: in function 'LeonardosWardrobeManager:Initialize'
|caaaaaa<Locals> self = [table:1]{variableVersion = 3, inStealth = 0, inCombat = F, name = "LeonardosWardrobeManager"} </Locals>|r
user:/AddOns/LeonardosWardrobeManager/LeonardosWardrobeManager.lua:188: in function 'LeonardosWardrobeManager.OnAddOnLoaded'
|caaaaaa<Locals> _ = 65536, addonName = "LeonardosWardrobeManager" </Locals>|r
Originally Posted by Calamath View Post
There are many ways to detect warping between different zones using fast travel, but I use EVENT_PLAYER_ACTIVATED.

Here is a hint.

Lua Code:
  1. local isFirstTimePlayerActivated = true
  2.  
  3. local function OnPlayerActivated(eventCode, initial)
  4.     if initial then
  5.         if isFirstTimePlayerActivated == false then
  6.             -- --------------------------------- after fast travel
  7.             -- do something
  8.         else
  9.             -- --------------------------------- after login
  10.             isFirstTimePlayerActivated = false
  11.         end
  12.     else
  13.         -- ------------------------------------- after reloadui
  14.         isFirstTimePlayerActivated = false
  15.     end
  16. end
  17.  
  18. EVENT_MANAGER:RegisterForEvent("yourAddonName", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  Reply With Quote
08/27/21, 12:59 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
EVENT_ZONE_UPDATE, but I can't even get my function to call that should be hooked to it.
Just a naming hint: It's called "callback" not "hook".

ZOs provies ZO_PreHook, ZO_PostHook which is a real hook to the functions, so that your code calls before/After the original one.
But normal event functions are considered to be callbacks to that event.

btw event_zone_changed fires too often for you as it will also fire if you change a subzone in a zone, like the map updates to a new area in the zone (a city e.g.).
At least this is what I had found out in the past.
  Reply With Quote
08/27/21, 01:06 AM   #8
Leonardo1123
AddOn Author - Click to view addons
Join Date: Aug 2021
Posts: 19
Thanks so much! I love learning more about this stuff haha.

Originally Posted by Baertram View Post
Just a naming hint: It's called "callback" not "hook".

ZOs provies ZO_PreHook, ZO_PostHook which is a real hook to the functions, so that your code calls before/After the original one.
But normal event functions are considered to be callbacks to that event.

btw event_zone_changed fires too often for you as it will also fire if you change a subzone in a zone, like the map updates to a new area in the zone (a city e.g.).
At least this is what I had found out in the past.
  Reply With Quote
12/27/23, 06:25 AM   #9
SimonIllyan
 
SimonIllyan's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2018
Posts: 1
Sorry to reheat that old thread, but it is the only place I've found in this forum mentioning "initial" parameter to a function handling EVENT_PLAYER_ACTIVATED. What is real meaning of this parameter? https://wiki.esoui.com/EVENT_PLAYER_ACTIVATED says:
boolean initial - whether the user just logged on
but this does not seem to be correct; according to the example code in this thread, "initial" is true not just after logging in, but also after fast travel, and false only after reloadui. Is that right? Is there anything else worth knowing about this parameter?

Originally Posted by Calamath View Post
There are many ways to detect warping between different zones using fast travel, but I use EVENT_PLAYER_ACTIVATED.

Here is a hint.

Lua Code:
  1. local isFirstTimePlayerActivated = true
  2.  
  3. local function OnPlayerActivated(eventCode, initial)
  4.     if initial then
  5.         if isFirstTimePlayerActivated == false then
  6.             -- --------------------------------- after fast travel
  7.             -- do something
  8.         else
  9.             -- --------------------------------- after login
  10.             isFirstTimePlayerActivated = false
  11.         end
  12.     else
  13.         -- ------------------------------------- after reloadui
  14.         isFirstTimePlayerActivated = false
  15.     end
  16. end
  17.  
  18. EVENT_MANAGER:RegisterForEvent("yourAddonName", EVENT_PLAYER_ACTIVATED, OnPlayerActivated)
  Reply With Quote
12/27/23, 08:53 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Yes that's right. false only on reloadui. Else true (login, zoning). No nothing else to say and know

It's there to distinguish the manual reloads from automatic ones, so the initial naming of the param is just bad chosen/wrong named
  Reply With Quote
12/27/23, 10:38 AM   #11
Calamath
AddOn Author - Click to view addons
Join Date: Aug 2019
Posts: 36
I rarely present code examples, and they are based on experiments I have done in the past, so they should present the correct facts.
However, the API changes constantly from quarter to quarter, and the wiki and code become outdated.
So, if you encountered contradictory statements, you should have actually run my code to see.
- Calamath
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Having trouble using EVENT_ZONE_CHANGED

Thread Tools
Display Modes

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