28.05.2016, 19:22
Yes, there is.
If you want to return the closest vehicle-id do:
If you want to return the distance do:
Код:
GetClosestVehicle(playerid) { new Float:pX, Float:pY, Float:pZ, Float:cX, Float:cY, Float:cZ, Float:distance = 99999.0, Float:distance2, result = -1; for(new i = 0; i < MAX_VEHICLES; i++) { if (GetPlayerVehicleID(playerid) != i) { GetPlayerPos(playerid, pX, pY, pZ); GetVehiclePos(i, cX, cY, cZ); distance = floatsqroot(floatpower(floatabs(floatsub(cX, pX)), 2) + floatpower(floatabs(floatsub(cY, pY)), 2) + floatpower(floatabs(floatsub(cZ, pZ)), 2)); distance2 = floatround(distance); if(distance2 < distance) { distance = distance2; result = i; } } } return result; }
Код:
return result;
Код:
return distance2;