12.04.2012, 01:10
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:
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.
Now, for the lock, you'll have to get the player's vehicle position to determine whether it's within range or not.
Checking if it's within range:
The code for locking/unlocking your vehicle:
The code above would lock the vehicle, you can change the "doors" parameter to VEHICLE_PARAMS_OFF for unlocking it.
For example:
pawn Код:
// place this under OnPlayerConnect()
PlayerStats[playerid][VehicleKey] = INVALID_VEHICLE_ID // alternatively, you can set it to -1
pawn Код:
// this would be under the command for buying a vehicle
new vehicle = GetPlayerVehicleID(playerid);
PlayerStats[playerid][VehicleKey] = vehicle;
pawn Код:
new Float:vPos[3];
GetVehiclePos(PlayerStats[playerid][VehicleKey], vPos[0], vPos[1], vPos[2]);
pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 5.0, vPos[0], vPos[1], vPos[2]))
{
}
pawn Код:
new engine, lights, alarm, doors, hood, trunk, objective;
SetVehicleParamsEx(PlayerStats[playerid][VehicleKey], engine, lights, alarm, VEHICLE_PARAMS_ON, hood, trunk, objective);