Coords not saving right
#1

Saving function
Код:
stock SavePlayerAccount(playerid)
{
	new DB_Query[1024];
	
	new
		   	Float:x,
		    Float:y,
			Float:z
		;
		
		
	if(PlayerInfo[playerid][LoggedIn] == 1)
	{
	    GetPlayerPos(playerid,x,y,z);
		PlayerInfo[playerid][pPos_x] = x;
		PlayerInfo[playerid][pPos_y] = y;
		PlayerInfo[playerid][pPos_z] = z;
	
	    mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `PASSWORD` = '%s', `SCORE` = %d, `KILLS` = %d, `CASH` = %d, `DEATHS` = %d, `Admin` = %d WHERE `ID` = %d"
		, PlayerInfo[playerid][pPass], PlayerInfo[playerid][Score], PlayerInfo[playerid][Kills], PlayerInfo[playerid][pCash], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][ID]);
		mysql_tquery(Database, DB_Query);
		
		mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = %d, `Age` = %d, `Pos_x` = %f, `Pos_y` = %f, `Pos_z` = %f, `Skin` = %d, `Job` = %d, `AccLock` = %d WHERE `ID` = %d"
		, PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccLock], PlayerInfo[playerid][ID]);
	    mysql_tquery(Database, DB_Query);
        PlayerInfo[playerid][LoggedIn] = 0;
	}

	return 1;
}
The player coords are not saved right when the player leaves the server, when he comes back he will get spawned near the area where he left but not right in the place where he was when he left the server.

I the enum I have FloatPos_x, FloatPos_y, FloatPos_z

And in mysql table I set them as Float and length to 16.
This is how I load them:
Код:
cache_get_value_float(0, "Pos_x", PlayerInfo[playerid][pPos_x]);
        		cache_get_value_float(0, "Pos_y", PlayerInfo[playerid][pPos_y]);
        		cache_get_value_float(0, "Pos_z", PlayerInfo[playerid][pPos_z]);
After few more logins I got spawned somewhere in San Fierro...

This is how they saved...
Код:
 
-2382.02 Pos_x
-582.044 Pos_y
132.617 Pos_z
When I register a new account they save right for the first few logins and quits, but after that the problems starts coming, sometimes it doesn't save or it doesn't save the right location, now I got spawned in SF..
Reply
#2

pawn Код:
GetPlayerPos(playerid,x,y,z);
PlayerInfo[playerid][pPos_x] = x;
PlayerInfo[playerid][pPos_y] = y;
PlayerInfo[playerid][pPos_z] = z;

What's the point of this? Local variables are much faster than global arrays.

Just use x, y, z instead hence you already created them localy.


And by the way if you are doing a script from scratch that's an awful way to save your stuff like that.

Lets make a reference here:

Imagine yourself eating something, would it be better if you stuff your whole sandwich in your mouth or piece by piece while eating it?

Or if you didn't understand that one:

Imagine someone ddosing your server so one player gets a million $ on his account the info doesn't get updated until the player disconnects the server but after receiving a milion $ on his account the server gets ddosed and the mysql server shuts down unexpectedly the player leaves the server in hope that his money gets saved but it really doesn't.

His money turns into dust in other words but why you may ask? Cause you tried to fit a whole sandwich in your mouth.
Reply
#3

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
pawn Код:
GetPlayerPos(playerid,x,y,z);
PlayerInfo[playerid][pPos_x] = x;
PlayerInfo[playerid][pPos_y] = y;
PlayerInfo[playerid][pPos_z] = z;

What's the point of this? Local variables are much faster than global arrays.

Just use x, y, z instead hence you already created them localy.


And by the way if you are doing a script from scratch that's an awful way to save your stuff like that.

Lets make a reference here:

Imagine yourself eating something, would it be better if you stuff your whole sandwich in your mouth or piece by piece while eating it?
Uh... give me an example of how I should save them then?
I shouldn't have a global save function? And call every thing where it is needed? Like, save the money when they update, save the location when the player quit, save the skin when it changed, things like this?


Also I used x,y,z instead of global but coords still save wrong sometimes..
Reply
#4

SetPlayerScore(playerid, value);
query to save player score


The only thing i would save when player disconnects is his position.

And also you don't need to save the players password everytime he logs out but only when he changes it.
Reply
#5

I only left the position save when the player disconnect.. still... it doesnt work, the coords save wrong or don't save at all..
Reply
#6

Remove the length (16) in the phpmyadmin on those floats if you want it to really be accurate use double instead.
Reply
#7

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
Remove the length (16) in the phpmyadmin on those floats if you want it to really be accurate use double instead.
It was due to the stock, it doesn't work if I use the stock and call it as SavePlayerAccount(playerid); at on player disconnect, why?


I added the save function under onplayerdisconnect instead of the stock and it worked, why it doesn't work well in the stock?
Reply
#8

Still trying to figure it out that where was others when I asked the same question I think yesterday and it wasn't solved at all...I created a thread and no-one replied if someone does he just told me to show code and after that nothing...Got to know that they help on people with a lot of shitty reputation only -.-
Reply
#9

Quote:
Originally Posted by princejeet1510
Посмотреть сообщение
Still trying to figure it out that where was others when I asked the same question I think yesterday and it wasn't solved at all...I created a thread and no-one replied if someone does he just told me to show code and after that nothing...Got to know that they help on people with a lot of shitty reputation only -.-
I also got help when I had no reputation too.. so I don't think so, but if your problem is the same then here is the answer to it
Reply
#10

Why are you even using a stock?

Do you know it's purpose?


Suggest you read this topic from Vince:
https://sampforum.blast.hk/showthread.php?tid=570635
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)