Delayed saving?
#1

Hey Guys,
I was just wondering about something I just scripted. I wanted to make a delayed saveaccount (don't ask why) which saved 250 ms after player disconnected from server. But somehow, it didn't save any of the player stats even when the timer was called in OnPlayerDisconnect.

Anyhow, then I moved the saveaccount feature to onplayerdisconnect, and now it does save.

My question: How come, I can't save accounts with a delay on disconnect, but only when player disconnected without any delays.
Reply
#2

It's probably because you're trying to save for a specific playerid, and because you're waiting, by the time you run the saveaccount code, the player has already left the game, OnPlayerDisconnect is called just as they leave the server, if you have it wait, it the player has already gone, and thus, you can't really save his stats that way.
Reply
#3

Quote:
Originally Posted by Zonoya
Посмотреть сообщение
It's probably because you're trying to save for a specific playerid, and because you're waiting, by the time you run the saveaccount code, the player has already left the game, OnPlayerDisconnect is called just as they leave the server, if you have it wait, it the player has already gone, and thus, you can't really save his stats that way.
If you have everything you're saving stored it should work(assuming you are attempting to save using variables and not functions relying on the player being connected). You may have a IsPlayerConnected or such type check in the delayed timer, if so try removing it - though you need to make sure you aren't saving anything using function values(such as the player's position in the timer).
Reply
#4

So i'm just wondering, IF i wanted to make a delayed saving (for no reason) how should I then do it?

Well my saving function:
Код HTML:
stock SaveUserAccount(playerid)
{
	new query[256];
	format(query, sizeof(query), "UPDATE `Accounts` SET Adminlevel = %d, Viplevel = %d, Class = %d WHERE `Username` = '%s'",
	UserAccount[playerid][Adminlevel], UserAccount[playerid][Viplevel], UserAccount[playerid][Class], GetName(playerid));
	mysql_function_query(MySQL, query, false, "Query", "");
	return true;
}
Reply
#5

Quote:
Originally Posted by Abagail
Посмотреть сообщение
If you have everything you're saving stored it should work(assuming you are attempting to save using variables and not functions relying on the player being connected). You may have a IsPlayerConnected or such type check in the delayed timer, if so try removing it - though you need to make sure you aren't saving anything using function values(such as the player's position in the timer).
True. Look at Abagail's post, Choco, make sure all that applies, as they have said, it should work assuming you're not saving information that uses function values (position, money, score) unless you keep it all in variables, which for position is fairly unlikely.

EDIT: Hmm... I don't see anything wrong in that code. I'm going to have to pass the torch here to Abagail, it seems odd that it doesn't work.
Reply
#6

It doesnt save because GetName(playerid) is called after player is disconnected
Reply
#7

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
It doesnt save because GetName(playerid) is called after player is disconnected
So you are saying, that I should getname before disconnnect, and store it in a variable?
Reply
#8

Yes, but why you want to delay player stats saving,because there isnt any point for that.
and also i suggest
mysql_function_query(MySQL, query, false, "Query", ""); change to
mysql_tquery(MySQL, query);
Reply
#9

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
Yes, but why you want to delay player stats saving,because there isnt any point for that.
and also i suggest
mysql_function_query(MySQL, query, false, "Query", ""); change to
mysql_tquery(MySQL, query);
I just want to experiment with it, for fun. "You never learn, if you don't try it"

-Thanks for pointing it out. I've changed it immediately.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)