Quote:
Originally Posted by MP2
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; }
Not tested, but it compiles, and it should work.
If it returns 0 (invalid vehicle ID as they start at 1) it means there's no vehicles within range.
|
It give's me an invalid vehicle ID (28 in my case) but there are over 10 vehicles in range of it.