Stats saving
#1

Right I have a problem with my player stats they save and load when I quit the game but if I restart the server it resets the playersame stats the only thing that stays is the account

So the account is still registered but administration levels and other stuff resets

Any ideas?
Reply
#2

You have to save all the connected players stats in OnGameModeExit.
Reply
#3

So basically adding the same code I have from on player disconnect into ongamemodeexit?
Reply
#4

You'll probably want to make a "SaveEverything" function, that you use prior to shutting down the server. Often when doing this people will freeze players after advising them the server is shutting down.

You'd freeze everyone, SaveEverything, and then GamemodeExit.


SaveEverything would have a for loop of all players online, and doing each OnPlayerDisconnects saves.



You may want to use it in a timer as well, due to if your server crashes without executing the exit, or having players disconnect, you'll face roll-backs.
Reply
#5

Okay would you happen to have a link for some help with making the save everything function? As I am still learning so I don't know that part haha
Reply
#6

You could use a real for loop, or you could use foreach. First link is the for loop, the second has multiples (It is a slight bit out of date, but the information still applies. Projects have shifted hands).

foreach is what everyone uses, yet it's no harm to understand such a basic method.

https://sampwiki.blast.hk/wiki/Loops

https://sampforum.blast.hk/showthread.php?tid=305770
Reply
#7

Now that I think about it, you can just kick every player on the server before the shutdown, that should call OnPlayerDisconnect and would save the stats. Way easier.
Reply
#8

Still better off to have the timer function to save, manually run near to the shutdown. Then at least the server does indeed save even with it being shut down unexpectedly.
Reply
#9

Yea I try that before restarting on home hosted I quit the game to save it then I shut the server and reopen it and log back in and it's still reset the stats
Reply
#10

Show your save function, OnPlayerDisconnect and OnPlayerConnect for the same variables.


(What code have you got currently)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)