• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] How to save the position of a car?
#1
Hello everyone :'D?



Would anyone know how to make a system to save the position of a car? where the player leaves his car somewhere and when he connects again the car is there, basically how is the saving of the player's position. Obviously I'm not asking for any of you to write that code, just an idea of where I should start if I wanted to do it. Greetings to all.
  Reply
#2
In the most basic explanation possible: create the variable to save the vehicle's position, when the player disconnects you set the vehicle's position in these variables and save it in the database. Then when the player logs in you create the vehicle with the coordinates retrieved from the database.

Basically, the logic would start like this:

PHP Code:
new playerVehicle[MAX_PLAYERS];
new 
Float:carPos[MAX_PLAYERS][3];

public 
OnPlayerLogin(playerid)
{
    
// Retrieves the coordinates saved in the database 
    
....
    
carPos[playerid][0] = X;
    
carPos[playerid][1] = Y;
    
carPos[playerid][2] = Z;
    
// Creates the vehicle with the coordinates retrieved
    
playerVehicle[playerid] = CreateVehicle(modelidcarPos[playerid][0], carPos[playerid][1], carPos[playerid][2]);
}

public 
OnPlayerDisconnect(playeridreason)
{
    
// Sets the vehicle's position in the variable
    
GetVehiclePos(playerVehicle[playerid], carPos[playerid][0], carPos[playerid][1], carPos[playerid][2]);
    
// Saves the position of the variable in the database
    
Save System...

  Reply


Forum Jump: