ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Unload event (https://www.esoui.com/forums/showthread.php?t=4965)

DerBombo 08/02/15 10:38 AM

Unload event
 
Hey guys!

Anyone knows if it's possible to do stuff, when the player logs out or quits the game client? So I could update saved variables when that happens? Basically the direct opposite of EVENT_ADD_ON_LOADED?

Thanks!

Wandamey 08/02/15 10:45 AM

maybe you can hook the click on the OK button from the deconnexion confirmation? or just the "show this control" to leave time to your commands to execute.... but i dunno how to /zgoo mouse this thing, good luck :D

baaah you can /zgoo mouse the "log out" line in the Esc menu for a start.

is it for something you can't do at next startup at all, or update during the session? i can't find any example of it being strictly necessary... do you mind sharing some spoilers please? <-- insert pic of puss in boots


reedit mmmh maybe saving your location for other toons to be able to check it?
re reedit : maybe saving your last bag content without having to use on_single_slot_update?
(can we make a game of this? the one who guesses what you are trying to do get a free copy of your addon... hmm or something like that)

votan 08/02/15 11:18 AM

Quote:

Originally Posted by Wandamey (Post 22465)
maybe you can hook the click on the OK button from the deconnexion confirmation? or just the "show this control" to leave time to your commands to execute.... but i dunno how to /zgoo mouse this thing, good luck :D

baaah you can /zgoo mouse the "log out" line in the Esc menu for a start.

is it for something you can't do at next startup at all, or update during the session? i can't find any example of it being strictly necessary... do you mind sharing some spoilers please? <-- insert pic of puss in boots


reedit mmmh maybe saving your location for other toons to be able to check it?

Wandamey is right, a bit more details would be helpful.
You can:
- Use the EVENT_PLAYER_DEACTIVATED: But it is not called on logout, only.
- Hook Logout (Security allows it?)
- Hook ESO_Dialogs["LOG_OUT"].buttons[1].callback

Ayantir 08/02/15 11:39 AM

You don't have to do this.


When player logout, reloadui, change cvar or get kicked for inactivity, saved variables are automatically saved. there's nothing to do.

You must not prehook or use those events if it's for saved variables usage.


For people who want to to this, here's how I do :


At ADD_ON_LOADED :
- I set a flag, this one goes to saved var. it will be used to guess at next ADD_ON_LOADED what kind of exit user did. If there's nothing to do at next add_on_loaded specifically for this kind of exit, don't do this.

Lua Code:
  1. -- ex: inactivity = 1, reloadui = 2, logout = 3, setCvar = 4, quit = 5
  2. local myaddon.db.exitMethod = 1
  3.  
  4. -- then I prehook :
  5.  
  6.  
  7.     -- PreHook ReloadUI, LogOut & Quit
  8.     ZO_PreHook("ReloadUI", function()
  9.         myaddon.db.exitMethod = 2
  10.         myaddon.doThingsAtReloadUI()
  11.     end)
  12.    
  13.     ZO_PreHook("Logout", function()
  14.         myaddon.db.exitMethod = 3
  15.         myaddon.doThingsAtLogOut()
  16.     end)
  17.    
  18.     ZO_PreHook("SetCVar", function()
  19.         myaddon.db.exitMethod = 4
  20.         myaddon.doThingsAtSetCVar()
  21.     end)
  22.  
  23.     ZO_PreHook("Quit", function()
  24.         myaddon.db.exitMethod = 5
  25.         myaddon.doThingsAtQuit()
  26.     end)
  27.  
  28.  
  29. -- then at ADD_ON_LOADED, just before setting the flag, I read value.
  30.  
  31. if myaddon.db.exitMethod == 1 then
  32.   -- last exit was a reloadui, so I do things specificaly at addon startup after a reload.
  33.   myaddon.reloadThings()
  34. end



But I repeat, if it's just only to save things on SavedVars, do not use this trick.

It's mainly used for addons which store things per session and don't want thoses ones being resetted after a reloadui or a characer change.

typical example : the chatbox being wiped, or stats. (KillCounter is a very good exemple too). some DPS meter could use this too but it's less important.

DerBombo 08/02/15 01:21 PM

That was exactly what I was looking for, albeit you stating several times not to use those hooks.

I've created a small addon which adds an all parameter to the /played command, so you could see the time you played all of your characters. So I needed to save the time played for each character at the latest time possible.

Thanks for your help guys, as always!

Wandamey 08/02/15 01:41 PM

i suppose this would be no big deal to trigger EVENT_PLAYER_DEACTIVATED a few more times during the session for this since it's not the nasa BD you are trying to record here.
seems like the simplest, imo.

good luck anyway you choose.

DerBombo 08/02/15 01:46 PM

Quote:

Originally Posted by Wandamey (Post 22470)
... since it's not the nasa BD you are trying to record here.

Yeah, the amount of data is very small. I had implemented a simple polling solution first because of that, but for now I like the PreHook solution the most, until anyone has very good arguments against that. :)

Wandamey 08/02/15 01:51 PM

the advantage of the hook is that you can count the loading times in your stats. They might be a big % of it when you stay in towns doing some errands :D

other than that i'm sure anyone with a little less concerns than you would have used an update function. So, as far as i'm concerned i'll trust your solution.

(i'm assuming you're using gettimestamp() right ?)

DerBombo 08/02/15 03:07 PM

Quote:

Originally Posted by Wandamey (Post 22472)
i'm assuming you're using gettimestamp() right ?

Actually I'm using GetSecondsPlayed(), as the regular /played command does.

ZOS_DanBatson 08/04/15 08:59 AM

Have you considered just running a simple Update loop that saves GetSecondsPlayed() to the ZO_SavedVars every second, or even every 5 seconds (if margin of error of 5 seconds is pretty reasonable)? It doesn't save to the file until reload / logout, and you can be as confident as anyone else is that it will get saved, so you only need to worry about getting the data to the table. It's simple, reasonably efficient, and doesn't require anything fancy.

DerBombo 08/05/15 12:16 AM

Yeah, I did consider this and that's actually how it was built just before I implemented the PreHook solution. I didn't really like polling the game all the time for a value, I only need right before it is stored to file, so I thought of that solution to be the most efficient.

Akira.Iris 07/02/19 10:04 PM

I know this is an old topic, but I can't seem to find an answer anywhere: when does "SetCVar" happen? "ReloadUI", "Logout" and "Quit" are self-explanatory, but I'm not sure about "SetCVar". If I use ZO_PreHook("SetCVar"..), when will it fire? All I can find it being used with is changing the language... Is that it?

And another quick question - is there a way to ZO_PreHook somehow so that my function happens after the logout/quit countdown? So far for me it's happening right before the counter starts, but then I can just press cancel and stay in-game, which isn't exactly what I'm looking for.

Baertram 07/03/19 12:29 AM

SetCVar is always happening then as you use it to change a setting/variable in-game.
Can be the language but also something like the video settings, audio settings etc.

After the logout countdown the game will log you out and there is no way to run code at this point.
It could happen too fast I guess.
I think as the logout countdown is not always shown the PreHook to Logout() is either as the countdown starts or the game logs you out directly (but you won#t see anything in chat then anymore :-) )


All times are GMT -6. The time now is 10:59 PM.

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