All pastes #884642 Raw Edit

damo

public text v1 · immutable
#884642 ·published 2008-01-30 14:34 UTC
rendered paste body
stock GetClosestPlayerToCar( vehicleId )
{
	new Float:px,
		Float:py,
		Float:pz,
		Float:vx,
		Float:vy,
		Float:vz,
		Float:pdist = -1.0,
		Float:cdist,
		playerid = -1;
	GetVehiclePos( vehicleId, vx, vy, vz );
	
	for( new i = 0; i < MAX_PLAYERS; i++ )
	{
		if( IsPlayerConnected( i ))
		{
			GetPlayerPos( i, px, py, pz );
			cdist = (((px-vx)*(px-vx))+((py-vy)*(py-vy))+((pz-vz)*(pz-vz)));

			new string[100];
			format( string, sizeof( string ), "Dist = %f Player = %d", cdist, i );

			SendClientMessageToAll( 0x22FF00FF, string );
			
			if( pdist != -1.0 )
			{
				if( cdist < pdist )
				{
					pdist = cdist;
					playerid = i;
				}
			}
			else {
				pdist = cdist;
				playerid = i;
			}
		}
	}
	return playerid;
}