31.01.2014, 00:04
pawn Код:
stock GetNearestVehicle(playerid, Float:max_range = 99999.0)
{
new Float:closestDist = max_range;
new closestVehicle = 0;
new Float:thisDist;
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
for(new i=1; i<=MAX_VEHICLES; i++)
{
thisDist = GetVehicleDistanceFromPoint(i, x, y, z);
if(thisDist < max_range && thisDist < closestDist)
{
closestDist = thisDist;
closestVehicle = i;
}
}
return closestVehicle;
}
If it returns 0 (invalid vehicle ID as they start at 1) it means there's no vehicles within range.