Quantcast Unload event - ESOUI
Thread Tools Display Modes
08/02/15, 10:38 AM   #1
DerBombo
 
DerBombo's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 24
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!
  Reply With Quote
08/02/15, 10:45 AM   #2
Wandamey
Guest
Posts: n/a
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

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)

Last edited by Wandamey : 08/02/15 at 11:50 AM.
  Reply With Quote
08/02/15, 11:18 AM   #3
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 492
Originally Posted by Wandamey View Post
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

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
__________________
@votan73 (EU - megaserver)
  Reply With Quote
08/02/15, 11:39 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,022
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.
__________________
Obsessive Compulsive Coder

My little french Guild: Cercle de l'Eveil
  Reply With Quote
08/02/15, 01:21 PM   #5
DerBombo
 
DerBombo's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 24
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!
  Reply With Quote
08/02/15, 01:41 PM   #6
Wandamey
Guest
Posts: n/a
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.
  Reply With Quote
08/02/15, 01:46 PM   #7
DerBombo
 
DerBombo's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 24
Originally Posted by Wandamey View Post
... 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.
  Reply With Quote
08/02/15, 01:51 PM   #8
Wandamey
Guest
Posts: n/a
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

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 ?)

Last edited by Wandamey : 08/02/15 at 01:57 PM.
  Reply With Quote
08/02/15, 03:07 PM   #9
DerBombo
 
DerBombo's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 24
Originally Posted by Wandamey View Post
i'm assuming you're using gettimestamp() right ?
Actually I'm using GetSecondsPlayed(), as the regular /played command does.
  Reply With Quote
08/04/15, 08:59 AM   #10
ZOS_DanBatson
ZOS Staff!
 
ZOS_DanBatson's Avatar
Yes this person is from ZeniMax!
Join Date: Jul 2015
Posts: 31
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.
  Reply With Quote
08/05/15, 12:16 AM   #11
DerBombo
 
DerBombo's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 24
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.
  Reply With Quote
07/02/19, 10:04 PM   #12
Akira.Iris
Join Date: Jun 2018
Posts: 4
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.

Last edited by Akira.Iris : 07/02/19 at 10:31 PM.
  Reply With Quote
07/03/19, 12:29 AM   #13
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,293
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 :-) )

Last edited by Baertram : 07/03/19 at 12:32 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Unload event

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