ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Having trouble using EVENT_ZONE_CHANGED (https://www.esoui.com/forums/showthread.php?t=9892)

Leonardo1123 08/26/21 07:28 PM

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

Calamath 08/26/21 09:18 PM

Hey, the code you showed seems to be EVENT_ZONE_UPDATED, not EVENT_ZONE_CHANGED, is this correct for your purpose?

Leonardo1123 08/26/21 09:52 PM

Quote:

Originally Posted by Calamath (Post 44633)
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

Calamath 08/26/21 10:12 PM

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)

Leonardo1123 08/26/21 11:30 PM

Quote:

Originally Posted by Calamath (Post 44635)
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


Leonardo1123 08/26/21 11:39 PM

Sorry, jumped the gun, after just a bit of tinkering that worked perfectly! Thank you so much.

Quote:

Originally Posted by Leonardo1123 (Post 44636)
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


Quote:

Originally Posted by Calamath (Post 44635)
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)


Baertram 08/27/21 12:59 AM

Quote:

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.

Leonardo1123 08/27/21 01:06 AM

Thanks so much! I love learning more about this stuff haha.

Quote:

Originally Posted by Baertram (Post 44638)
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.


SimonIllyan 12/27/23 06:25 AM

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:
Quote:

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?

Quote:

Originally Posted by Calamath (Post 44635)
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)


Baertram 12/27/23 08:53 AM

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

Calamath 12/27/23 10:38 AM

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


All times are GMT -6. The time now is 09:29 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI