06.07.2016, 11:19
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:
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); } }