SA-MP Forums Archive
So weird..MySql not saving coordinate. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: So weird..MySql not saving coordinate. (/showthread.php?tid=624121)



So weird..MySql not saving coordinate. - SkyFlare - 11.12.2016

Hey guys, I have a very weird problem with my script..
X Float, Z Float & A Float Coordinates are saving perfectly fine.
Y Float is like "Nah too mainstream" and saves as 0.

Any ideas on why guys?

(OnPlayerDisconnect)
Code:
calling UpdateUserPosition(playerid);
(UpdateUserPosition(playerid))
Code:
UpdateUserPosition(playerid)
{
	GetUserPosition(playerid);
    new query[654];
    mysql_format(g_SQL, query, sizeof query, "UPDATE `accounts` SET `posX` =%f, `posY` =%f, `posZ` =%f, `posA` =%f WHERE `id` = %d LIMIT 1", Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], Player[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
(GetUserPosition(playerid))
Code:
stock GetUserPosition(playerid)
{
	new Float: pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    Player[playerid][X_Pos] = pos[0];
    Player[playerid][Y_Pos] = pos[1];
    Player[playerid][Z_Pos] = pos[2];
    Player[playerid][A_Pos] = pos[3];
	return 1;
}



Re: So weird..MySql not saving coordinate. - amirm3hdi - 11.12.2016

Don't give bullshit, try printing the query and give it to me.


Re: So weird..MySql not saving coordinate. - BiosMarcel - 11.12.2016

Even tho this is theoretically working (and not a fix to your problem):

PHP Code:
new Float:angleposition[1]; 
it is stupid to make an array with the size of 1, just make a normal Float variable.

And about your problem: print X, Y and Z before saving it, to see what it is, since the variables are at the top of your script (why ever that is so), they might be overwritten from somehwere else.


Re: So weird..MySql not saving coordinate. - SkyFlare - 11.12.2016

Quote:
Originally Posted by [Bios]Marcel
View Post
Even tho this is theoretically working (and not a fix to your problem):

PHP Code:
new Float:angleposition[1]; 
it is stupid to make an array with the size of 1, just make a normal Float variable.

And about your problem: print X, Y and Z before saving it, to see what it is, since the variables are at the top of your script (why ever that is so), they might be overwritten from somehwere else.
Found the problem, Sql does not like Capital letters when saving.... so I changed it in the Database and in the script to lowercase
Code:
UpdateUserPosition(playerid)
{
	GetUserPosition(playerid);
    new query[512];
    mysql_format(g_SQL, query, sizeof query, "UPDATE `accounts` SET `posx` = %f, `posy` = %f, `posz` = %f, `posa` = %f WHERE `id` = %d LIMIT 1", Player[playerid][X_Pos], Player[playerid][Y_Pos], Player[playerid][Z_Pos], Player[playerid][A_Pos], Player[playerid][ID]);
	mysql_tquery(g_SQL, query);
	return 1;
}
Also i fixed my array mess ( I fixed this first, still was showing 0 by the way)
Code:
stock GetUserPosition(playerid)
{
	new Float: pos[4];
    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
    GetPlayerFacingAngle(playerid, pos[3]);
    Player[playerid][X_Pos] = pos[0];
    Player[playerid][Y_Pos] = pos[1];
    Player[playerid][Z_Pos] = pos[2];
    Player[playerid][A_Pos] = pos[3];
	return 1;
}



Re: So weird..MySql not saving coordinate. - amirm3hdi - 12.12.2016

If you're not experienced with SQL, you'll have more errors on the way, always print them and if you still don't get whats the problem, run the in PhpMyAdmin or something.