Detecting the vehicle
#2

Yes, there is.
Код:
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;
}
If you want to return the closest vehicle-id do:
Код:
return result;
If you want to return the distance do:
Код:
return distance2;
Reply


Messages In This Thread
Detecting the vehicle - by cdoubleoper - 28.05.2016, 18:53
Re: Detecting the vehicle - by Darkwood17 - 28.05.2016, 19:22
Re: Detecting the vehicle - by Konstantinos - 28.05.2016, 19:25
Re: Detecting the vehicle - by PrO.GameR - 28.05.2016, 20:12
Re: Detecting the vehicle - by cdoubleoper - 28.05.2016, 21:17

Forum Jump:


Users browsing this thread: 1 Guest(s)