[MYSQL] Trouble saving pos into databaste
#1

Hello friends, i am having a trouble while saving the player pos to the mysql database.
I can't figure out what is the problem, the code seems to be right for me.
The script has to store the player pos on floats when he disconnect, then upload it to the database to save it and load on next connection.

The problem with my code is, that it do what it have to do, but some times fail and store the position in database to 0.0 0.0 0.0. I don't know why, 50 percent of times work well, the other 50 fails.

Here is the code of the function that i execute on OnPlayerDisconnect.
I also have a function called "cleanSlot" that cleans the player array for that slot on OnPlayerConnect, maybe here is the trouble?

saveData function:
Код:
public guardarDatos(playerid)
{
	if(estaLogueado[playerid])
	{
	    new consulta[512];
	    new Float:posX, Float:posY, Float:posZ, Float:angle, Float:vida, Float:chaleco;
		GetPlayerPos(playerid, posX, posY, posZ);
		GetPlayerFacingAngle(playerid, angle);
		GetPlayerHealth(playerid, vida);
		GetPlayerArmour(playerid, chaleco);
		new armastr[50], armas[13][2];
		for(new i=0; i<13; i++)
		{
		    GetPlayerWeaponData(playerid, i, armas[i][0], armas[i][1]);
		}
		format(armastr, sizeof(armastr), "%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d",
		armas[0], armas[1], armas[2], armas[3], armas[4], armas[5], armas[6], armas[7],
		armas[8], armas[9], armas[10], armas[11], armas[12]);
		
		new carbuff1[64], carbuff2[64];
		new Float:carX, Float:carY, Float:carZ, Float:carAng;
		if(IsValidVehicle(User[playerid][auto1]))
		{
		    GetVehiclePos(User[playerid][auto1], carX, carY, carZ);
		    GetVehicleZAngle(User[playerid][auto1], carAng);
		    format(carbuff1, sizeof(carbuff1), "%d|%f|%f|%f|%f|22|22",
		    GetVehicleModel(User[playerid][auto1]), carX, carY, carZ, carAng);
		    printf("savestring:%s",carbuff1);
		}
		else
		{
			format(carbuff1, sizeof(carbuff1), "null");
		}
		if(IsValidVehicle(User[playerid][auto2]))
		{
		    GetVehiclePos(User[playerid][auto2], carX, carY, carZ);
		    GetVehicleZAngle(User[playerid][auto2], carAng);
		    format(carbuff2, sizeof(carbuff2), "%d|%f|%f|%f|%f|22|22",
		    GetVehicleModel(User[playerid][auto2]), carX, carY, carZ, carAng);
		    printf("savestring: %s", carbuff2);
		}
		else
		{
		    format(carbuff2, sizeof(carbuff2), "null");
		}
		
		printf(armastr);
	    mysql_format(base_datos, consulta, 512, "UPDATE `usuarios` SET herramientas=%d, mascara=%d, posX=%f, posY=%f, posZ=%f, posAngle=%f, vida=%f, chaleco=%f, skin=%d, nivel=%d, dinero=%d, dineroBanco=%d, faccion=%d, faccionNivel=%d, auto1='%s', auto2='%s', casa1=%d, casa2=%d, armas='%s', interiorid=%d, adminNivel=%d WHERE ID=%d",
		User[playerid][Herramientas], User[playerid][Mascara], posX, posY, posZ, angle, vida, chaleco, GetPlayerSkin(playerid), User[playerid][Nivel], User[playerid][Dinero], User[playerid][DineroBanco], User[playerid][Faccion], User[playerid][FaccionNivel], carbuff1, carbuff2, User[playerid][Casa1], User[playerid][Casa2], armastr, GetPlayerInterior(playerid), User[playerid][NivelAdmin], User[playerid][DBID]);
		printf(consulta);
		mysql_tquery(base_datos, consulta, "", "");printf(consulta);
	}
}
Reply
#2

Post the code of loading of MYSQL data.
Reply
#3

the problem isn't there friend, look at the line before mysql_tquery, "printf(consulta)".
when the positions are saved wrong, i can see in the server log the 0.0 float values.
the problem is when saving data, load data always work well

Код:
[12:07:15] [death] ]Yuta[ died 255
[12:14:35] savestring:402|2033.133666|-1405.223144|17.074518|76.768592|22|22
[12:14:35] 0|0|0|0|0|0|0|0|0|0|0|0
[12:14:35] UPDATE `usuarios` SET herramientas=1, mascara=0, posX=2031.743, posY=-1411.827, posZ=16.999, posAngle=149.133, vida=100.0, chaleco=0.0, skin=0, nivel=10, dinero=8322302, dineroBanco=25000, faccion=0, faccionNivel=1, auto1='402|2033.133666|-1405.223144|17.074518|76.768592|22|22', auto2='null', casa1=0, casa2=0, armas='0|0|0|0|0|0|0|0|0|0|0|0', interiorid=0, adminNivel=5 WHERE ID=26
[12:14:35] UPDATE `usuarios` SET herramientas=1, mascara=0, posX=2031.743, posY=-1411.827, posZ=16.999, posAngle=149.133, vida=100.0, chaleco=0.0, skin=0, nivel=10, dinero=8322302, dineroBanco=25000, faccion=0, faccionNivel=1, auto1='402|2033.133666|-1405.223144|17.074518|76.768592|22|22', auto2='null', casa1=0, casa2=0, armas='0|0|0|0|0|0|0|0|0|0|0|0', interiorid=0, adminNivel=5 WHERE ID=26
[12:14:35] [part] ]Yuta[ has left the server (0:1)
[12:22:17] Actualizando base de datos...

[12:22:17] Guardando propiedades...
[12:22:17] 0|0|0|0|0|0|0|0|0|0|0|0
[12:22:17] UPDATE `usuarios` SET herramientas=1, mascara=0, posX=0.0, posY=0.0, posZ=0.0, posAngle=0.0, vida=0.0, chaleco=0.0, skin=0, nivel=10, dinero=8322302, dineroBanco=25000, faccion=0, faccionNivel=1, auto1='null', auto2='null', casa1=0, casa2=0, armas='0|0|0|0|0|0|0|0|0|0|0|0', interiorid=0, adminNivel=5 WHERE ID=26
[12:22:17] UPDATE `usuarios` SET herramientas=1, mascara=0, posX=0.0, posY=0.0, posZ=0.0, posAngle=0.0, vida=0.0, chaleco=0.0, skin=0, nivel=10, dinero=8322302, dineroBanco=25000, faccion=0, faccionNivel=1, auto1='null', auto2='null', casa1=0, casa2=0, armas='0|0|0|0|0|0|0|0|0|0|0|0', interiorid=0, adminNivel=5 WHERE ID=26
[12:37:39] Actualizando base de datos...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)