02.03.2018, 10:57
with this you are getting the closest vehicle.
it simply loops trought the vehicles and sees what the nearest vehicle is.
so you can use this in your cmd like
then you need to use
with this useful function
and you need to do another check to see if the car has the model of the fbi rancher.
You have the cars list here :
PHP Code:
GetClosestVehicle(playerid)
{
new closestdist = 999999999, closestvehicle = -1;
new Float:x[2],Float:y[2],Float:z[2],distance;
for(new i; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i,x[0],y[0],z[0]);
//if(x[0] == 0.0 && y[0] == 0.0 && z[0] == 0.0) return -1;
GetPlayerPos(playerid,x[1],y[1],z[1]);
distance = floatround(GetDistanceBetweenPoints(x[0],y[0],z[0],x[1],y[1],z[1]));
if(distance < closestdist) {
closestdist = distance;
closestvehicle = i;
}
}
return closestvehicle;
}
so you can use this in your cmd like
PHP Code:
fbiranger = GetClosestVehicle(playerid);
PHP Code:
IsPlayerNearVehicle(playerid, fbiranger, range)
PHP Code:
IsPlayerNearVehicle(playerid, vehicleid, Float:range)
{
new Float:X, Float:Y, Float:Z;
GetVehiclePos(vehicleid, X, Y, Z);
if(IsPlayerInRangeOfPoint(playerid, range, X, Y, Z))return true;
else return false;
}
PHP Code:
GetVehicleModel