Get id of the vehicle to save position (MySQL)
#1

- I have three vehicle loaded with MySQL:


Image in-game: http://i.imgur.com/SsF02KC.jpg


- And I go to one of the vehicles, (for example NRG) and use the command to save the position
Image in-game: http://i.imgur.com/9VqjHEa.jpg


- When I restart the server, the vehicles are in the same position
Image in-game: http://i.imgur.com/uQkfjud.jpg



The command:

Код:
CMD:aparcaradmin(playerid, params[])
{
    new vehicleid;
    
    if(IsPlayerInAnyVehicle(playerid)) vehicleid = GetPlayerVehicleID(playerid);
    else vehicleid = JugadorCercaVehiculo(playerid);

	new Float:Pos[4];
    GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
    GetVehicleZAngle(vehicleid, Pos[3]);

	Vehiculo[vehicleid][vX] = Pos[0]; Vehiculo[vehicleid][vY] = Pos[1]; Vehiculo[vehicleid][vZ] = Pos[2]; Vehiculo[vehicleid][vA] = Pos[3];
  	
  	new query[128];
	format(query, 128, "UPDATE `vehiculos` SET `PosVehX` = %f, `PosVehY` = %f, `PosVehZ` = %f, `PosVehA` = %f WHERE `IDveh` = %d", Vehiculo[vehicleid][vX], Vehiculo[vehicleid][vY], Vehiculo[vehicleid][vZ], Vehiculo[vehicleid][vA], vehicleid);
	mysql_query(mysql, query);
}
Thanks.
Reply
#2

bump
Reply
#3

Can you save positions from Pos[0] variable? - http://pastebin.com/Sg9CbbhE
and you have to add char ' to your float, For Example - `fPosX` = '%f'
Reply
#4

In-game vehicleids are volatile and subject to change and as such must never be used as a key in SQL. The unique and nonvolatile SQL id must be saved to a variable in order to identify a vehicle. You should create another variable in the enumerated array to store the key. Call it sqlId or something. It is this id that must be used in the where-clause, not the vehicleid retrieved from GetPlayerVehicleID.

Quote:
Originally Posted by 7days7
Посмотреть сообщение
and you have to add char ' to your float, For Example - `fPosX` = '%f'
False. This will slow done processing because the MySQL server must run a conversion to convert it from string to float.
Reply
#5

I do not understand very well English but I think that you are referring to this:

Код:
CMD:aparcaradmin(playerid, params[])
{
    new vehicleid;
    new Sqlid;
    if(IsPlayerInAnyVehicle(playerid)) vehicleid = GetPlayerVehicleID(playerid);
    else vehicleid = JugadorCercaVehiculo(playerid);

	new Float:Pos[4];
    GetVehiclePos(vehicleid, Pos[0], Pos[1], Pos[2]);
    GetVehicleZAngle(vehicleid, Pos[3]);

	Vehiculo[vehicleid][vX] = Pos[0]; Vehiculo[vehicleid][vY] = Pos[1]; Vehiculo[vehicleid][vZ] = Pos[2]; Vehiculo[vehicleid][vA] = Pos[3];
  	
  	new query[128];
	format(query, 128, "UPDATE `vehiculos` SET `PosVehX` = %f, `PosVehY` = %f, `PosVehZ` = %f, `PosVehA` = %f WHERE `IDveh` = %d", Vehiculo[vehicleid][vX], Vehiculo[vehicleid][vY], Vehiculo[vehicleid][vZ], Vehiculo[vehicleid][vA], Sqlid);
	mysql_query(mysql, query);
}
But Sqlid always has a value of 0?
Is it possible that I have to use something like this?: cache_get_field_content_int(0, "IDveh");

Thanks for the help!
Reply
#6

bump
Reply
#7

I cannot fix it
Reply
#8

bump
Reply
#9

bump
Reply
#10

Quote:
Originally Posted by Vince
Посмотреть сообщение
False. This will slow done processing because the MySQL server must run a conversion to convert it from string to float.
Sorry for interrupting but this that vince mentioned about mysql '%f' related was very interesting! Learn something new today
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)