[NEED] IsVehicleNearToPos
#1

is there someone got that function? or something similar.... i know that there was something similar about the player but i need one with vehicles.
Reply
#2

This will only work for 0.3:

pawn Код:
public IsPlayerInRangeOfVehicle(playerid, vehicleid, radius)
{
    new Float: CarX, Float: CarY, Float: CarZ;
    GetVehiclePos(playerid, CarX, CarY, CarZ);
    if(IsPlayerInRangeOfPoint(playerid, radius, CarX, CarY, CarZ))
    {
      return 1;
    }
    else
    {
        return 0;
    }
}
Reply
#3

i said its for vehicles NOT for ppl, thanks anyways
Reply
#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
#5

Quote:
Originally Posted by virspector
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....

Oh, sorry, u mean is Vehicle is near to somewhere (coordinate)? Ok, sorry, i thought if a vehicle near to a player.
Ok, let's just change some of the things...

Add these forwards:

Код:
forward VehicleToPoint(Float:radi, vehicleid, Float:x, Float:y, Float:z);
forward IsVehicleNearToPos(vehicleid, x, y, z);
And, we should change PlayerToPoint into VehicleToPoint and little bit code change:

Код:
public VehicleToPoint(Float:radi, vehicleid, Float:x, Float:y, Float:z)
{
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		GetVehiclePos(vehicleid, 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, let's change the IsVehicleNearToPos.

Код:
public IsVehicleNearToPos(vehicleid, x, y, z)
{
	if(VehicleToPoint(10, vehicleid, x, y, z); //Change the 10 into the radius between the coordinate and vehicle
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
Ok, for the usage? SIMPLE:

Код:
IsVehicleNearToPos(vehicleid, x, y, z);
and, if it is near to the position, it will return value 1 and if it's not, it will return value 0

Sorry, i didn't test it yet, but i am sure 95% it works correctly
Reply
#6

ok, i'll try thanks for your work

Edit:

This work perfectly, thanks virspector and thanks to Calgon too for trying to help me
Reply
#7

Isn't easier just return your VehicleToPos value instead of using separated if for it?

pawn Код:
//...
return VehicleToPoint(10, vehicleid, x, y, z);
Reply
#8

All above versions sux, not because they are wrong but because they are damn slow...
You better use this:
Код:
#define IsToPoint(%0,%1,%2,%3,%4,%5,%6) \
((((%0) - (%3)) * ((%0) - (%3))) + (((%1) - (%4)) * ((%1) - (%4))) + (((%2) - (%5)) * ((%2) - (%5))) <= ((%6) * (%6))) // ******'s macro for distance checking

stock IsVehicleNearPos(weed, Float: x, Float: y, Float: z, Float: dist)
{
	new
	  Float: vX,
	  Float: vY,
	  Float: vZ;
	GetVehiclePos(weed, vX, vY, vZ);
	return IsToPoint(x,y,z,vX,vY,vZ,dist);
}
Usage: IsVehicleToPos(veh, x, y, z, dist)

Have fun
Reply
#9

Well the function name is IsVehicleNearToPos not ReturnVehicleDistance.

Bro, you stupid?

@i said its for vehicles NOT for ppl, thanks anyways

Use GetVehiclePos() then.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)