Sign in to follow this  
mouse

Saving player data via onsave/onload?

Recommended Posts

mouse    53

I'm trying to save one variable and the usual DS inst.OnSave/inst.OnLoad method isn't working for disconnects/reconnects.

Is there some special function or method I need to know about saving data in DST?

Edited by mouse

Share this post


Link to post
Share on other sites
Seiai    56

@mouse,

they work, but some things like follower will already have been removed at that point. u can use OnDespawn then. just be aware that OnDespawn doesnt have access to the savedata yet, so u will have to save whatever u need into a variable on your character, and then save it via the savefunction. my mod kerrigan makes use of that to save her followers.

Share this post


Link to post
Share on other sites
mouse    53

@mouse,

they work, but some things like follower will already have been removed at that point. u can use OnDespawn then. just be aware that OnDespawn doesnt have access to the savedata yet, so u will have to save whatever u need into a variable on your character, and then save it via the savefunction. my mod kerrigan makes use of that to save her followers.

And they work within AddPlayerPostInit?

Like:

AddPlayerPostInit(function(inst)    inst.OnSave=somefn1    inst.OnLoad=somefn2end)

Share this post


Link to post
Share on other sites
mouse    53

Nevermind, I found a solution. I made the player perform a dotaskintime function for one second after joining the server while all of the data finishes arm wrestling with each other.

I noticed something though. The inst.OnSave function runs when the player joins the server. Any idea if that's a bug, temporary(until OnDespawn is finished), or permanent?

Anyways, thank you very much for your help.

Share this post


Link to post
Share on other sites
Amalleus    13

I used load and save functions for my character and they work fine. Save - only when you come out of server. Load - only when you join the server. So, save doesn't work on joining for me, probably you have bug

Share this post


Link to post
Share on other sites
Seiai    56

And they work within AddPlayerPostInit?

Like:

AddPlayerPostInit(function(inst)    inst.OnSave=somefn1    inst.OnLoad=somefn2end)
if u do this, make sure to save the previous function of thoses players, and call them within your savefunction, or u will just overwrite existing savefunction, and for instance delete wendies sister like that^^

 

The inst.OnSave function runs when the player joins the server.

i hope u are aware that the function gets called everytime the server saves, for instance each new day. so the function u make, has to work correctly even while gameplay, so it should'nt matter anyway, when it's being called when u join the game. so i would rather call it a feature than a bug^^ Edited by Seiai

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this