Have a variable that indicates the player's owned vehicle ID, check the example below. If a player buys a vehicle, the variable would be changed to the vehicle's ID.
For example:
pawn Код:
// place this under OnPlayerConnect()
PlayerStats[playerid][VehicleKey] = INVALID_VEHICLE_ID // alternatively, you can set it to -1
After buying a vehicle, set this variable to the vehicle's ID, in this case, the player needs to be on the driver's seat for him/her to be able to buy it.
pawn Код:
// this would be under the command for buying a vehicle
new vehicle = GetPlayerVehicleID(playerid);
PlayerStats[playerid][VehicleKey] = vehicle;
Now, for the lock, you'll have to get the player's vehicle position to determine whether it's within range or not.
pawn Код:
new Float:vPos[3];
GetVehiclePos(PlayerStats[playerid][VehicleKey], vPos[0], vPos[1], vPos[2]);
Checking if it's within range:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0, vPos[0], vPos[1], vPos[2]))
{
}
The code for locking/unlocking your vehicle:
pawn Код:
new engine, lights, alarm, doors, hood, trunk, objective;
SetVehicleParamsEx(PlayerStats[playerid][VehicleKey], engine, lights, alarm, VEHICLE_PARAMS_ON, hood, trunk, objective);
The code above would lock the vehicle, you can change the "doors" parameter to VEHICLE_PARAMS_OFF for unlocking it.