GetVehicleDistanceFromPoint

From SA-MP Wiki

Jump to: navigation, search


GetVehicleDistanceFromPoint was added in SA-MP 0.3c This function was added in SA-MP 0.3c R3 and will not work in earlier versions!


Description:

This function can be used to calculate the distance (as a float) between a vehicle and another map coordinate. This can be useful to detect how far a vehicle away is from a location.


Parameters:
(vehicleid, Float:X, Float:Y, Float:Z)
vehicleidThe ID of the vehicle to calculate the distance for.
Float:XThe X map coordinate.
Float:YThe Y map coordinate.
Float:ZThe Z map coordinate.

Return Values:

A float containing the distance from the point specified in the coordinates.


Example Usage:

/* when the player types 'vendingmachine' in to the chat box, they'll see this.*/
public OnPlayerText(playerid, text[])
{
	if(strcmp(text, "vendingmachine", true) == 0)
	{
		new
		    Float: fDistance = GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), 237.9, 115.6, 1010.2),
		    szMessage[44];
 
		format(szMessage, sizeof(szMessage), "You're %f away from our vending machine.", fDistance);
		SendClientMessage(playerid, 0xA9C4E4FF, szMessage);
	}
	return 0;
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.

Personal tools
Navigation
Toolbox