Saving Companiondata on user Logout
Hi Guys
I am writing an addon that saves all kinds of character data to SavedVariables on user logout. The data is saved to a SavedVariables block in a function that is called at the EVENT_PLAYER_DEACTIVATED event. All character data is saved as expected, but at the time of the event, the active Companion is already de-activated, so I cannot save Companion data like e.g. rapport. When I /reloadui the companion data is saved as expected, so apparently the Companion is still active at this point, but not at the event as mentioned above. Is there a way to detect that a normal logout is about to happen, and where the currently selected Companion is still active? I tried the EVENT_ACTIVE_COMPANION_STATE_CHANGED but this has the same result: no active Companion on user Logout Many thanks in advance, Cabwav |
Add a ZO_PreHook to the logout and/or quit function instead or in addition.
They will be called as you logout/quit by the menu or /logout slash command or /quit slash command PreHooks will be called before the original functions are called. So you can add your callback function there, like you add it to an event, and it will run your code first, and then the original code. Make sure you DO NOT "return true" in your prehook or it will cancel all following coe, including vanilla game code (like the logout or quit). To find the logout and quit functions to hook into: Search the esoui sources (https://github.com/esoui/esoui/tree/master/esoui) for the quit and/or logout to find the function names. If you search for logout e.g. you'll find ShowLogoutDialog which is local and locals cannot be hooked into! So you need to find the global function (API function) used to call that dialog function ShowLogoutDialog -> OnLogoutDeferred (local too) -> Code:
EVENT_MANAGER:RegisterForEvent("Globals", EVENT_LOGOUT_DEFERRED, OnLogoutDeferred) There does not seem to exist any global variable to hook into, but the dialog names are shown in the code: https://github.com/esoui/esoui/blob/...lobals.lua#L25 LOGOUT_DEFERRED QUIT_DEFERRED If you search for those you'll find the definition of these dialogs and it's "Yes" button's callback function, which should be the logout/quit function then. I did find a function "Logout" and "Quit" e.g. that way, and a preHook would look like this then: Lua Code:
References: https://github.com/esoui/esoui/blob/...logs.lua#L1841 https://github.com/esoui/esoui/blob/...hared.lua#L139 https://github.com/esoui/esoui/blob/...ands_pc.lua#L1 https://github.com/esoui/esoui/blob/...yboard.lua#L37 |
Solved!
That worked, awesome! :D
Many thanks! |
All times are GMT -6. The time now is 05:42 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI