[NEED] IsVehicleNearToPos
#4

First, put this forward:

Код:
forward PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z);
forward IsVehicleNearToPos(vehicleid, playerid);
Now, add this public function:

Код:
public PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
  if(IsPlayerConnected(playerid))
	{
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetPlayerPos(playerid, oldposx, oldposy, oldposz);
		tempposx = (oldposx -x);
		tempposy = (oldposy -y);
		tempposz = (oldposz -z);
		//printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
		if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
		{
			return 1;
		}
	}
	return 0;
}
And for the "IsVehicleNearToPos" thing, we add another Public Function:

Код:
public IsVehicleNearToPos(vehicleid, playerid)
{
	new Float:x, Float:y, Float:z;
	GetVehiclePos(vehicleid, x, y, z);
	if(PlayerToPoint(20, playerid, x, y, z); //Change the 20 into the radius beetween player and vehicle
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
Now, for the usage is this:

Код:
IsVehicleNearToPos(<vehicleid>, <playerid>);
And for the example, here it is:

Код:
OnPlayerCommandText(playerid, cmdtext[])
{
	if(!strcmp("/isplanenearpos", cmdtext, true))
	{
		if(IsVehicleNearToPos(2, playerid)) //Let's just say the "PLANE" id is 2
		{
			SendClientMessage(playerid, COLOR_SYSTEM, "Yes, it is");
		}
		else
		{
			SendClientMessage(playerid, COLOR_SYSTEM, "No, it is not");
		}
	}
}
Try it out! Hope it helps....

Reply


Messages In This Thread
[NEED] IsVehicleNearToPos - by silvan - 25.09.2009, 10:47
Re: [NEED] IsVehicleNearToPos - by Calgon - 25.09.2009, 10:50
Re: [NEED] IsVehicleNearToPos - by silvan - 25.09.2009, 11:08
Re: [NEED] IsVehicleNearToPos - by virspector - 25.09.2009, 12:43
Re: [NEED] IsVehicleNearToPos - by virspector - 25.09.2009, 12:51
Re: [NEED] IsVehicleNearToPos - by silvan - 25.09.2009, 12:52
Re: [NEED] IsVehicleNearToPos - by Sergei - 25.09.2009, 13:20
Re: [NEED] IsVehicleNearToPos - by Google63 - 25.09.2009, 13:48
Re: [NEED] IsVehicleNearToPos - by Calgon - 25.09.2009, 14:07

Forum Jump:


Users browsing this thread: 2 Guest(s)