IsPlayerInFrontOfPlayer
#1

hello, can someone make this func (IsPlayerInFrontOfPlayer) for me?
With my friend we try it but it fails.. we dont have brain for this hard math

I have two miniguns on vehicle and I need bool:IsPlayerInFrontOfVehicle to take dmg.. for player front of vehicle
I tried GetXYFrontOfPlayer but it needs distance.. I need just isplayerinfrontofvehicle with some angle and example minigun range 50 meters

Thanks.
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=573961
Code:
native IsPlayerFacingPlayer(playerid, targetid, Float:range = 10.0);
Reply
#3

read my post again pls.. I have two miniguns attached on vehicle I need IsPlayerInFrontOfVehicle..

BTW: I tested this func form playerfuncs but its not what I need..
Reply
#4

Something like that?

Thats what i created.
If it works please +REP me

For me its working fine. It returns the id of the player in front of playerid.


returns
Code:
stock IsPlayerInFrontOfPlayer(playerid)
{
	new Float:x, Float:y,Float:z;
	GetPlayerPos(playerid, x, y, z);
	GetPlayerFacingAngle(playerid, z);
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
	new i;
	for(i; i < MAX_PLAYERS;i++)
	{
	if(i == playerid) continue;
	IsPlayerInRangeOfPoint(i,3.0,x,y,z) return i;
	}
}
You can do the same for IsPlayerInFrontOfVehicle

Code:
stock IsPlayerInFrontOfVehicle(vehicleid)
{
	new Float:x, Float:y,Float:z;
	GetVehiclePos(vehicleid, x, y, z);
	GetVehicleFacingAngle(vehicleid, z);
	x += (distance * floatsin(-a, degrees));
	y += (distance * floatcos(-a, degrees));
	new i;
	for(i; i < MAX_PLAYERS;i++)
	{
	IsPlayerInRangeOfPoint(i,3.0,x,y,z) return i;
	}
}
Reply
#5

You dont understand me guys..
But I figured it out by myself.. so if u want the code.. I can post it there:

Quote:

stock GetXYInFrontOfPlayer(playerid, &Float, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}

bool:IsPlayerFrontOfPlayer(playerid, targetid, Float:max_distance=10.0)
{
new Float[2][3];
new Float:radius = 2.0;
if(IsPlayerInAnyVehicle(targetid)) radius = 5.0;
GetPlayerPos(playerid, p[0][0], p[0][1], p[0][2]);
GetPlayerPos(targetid, p[1][0], p[1][1], p[1][2]);
if(IsPlayerInRangeOfPoint(targetid, radius, p[0][0], p[0][1], p[0][2])) return false;
for(new Float:i = 3.5; i < max_distance; i++)
{
GetXYInfrontOfPlayer(playerid, p[0][0], p[0][1], i);
if(IsPlayerInRangeOfPoint(targetid, radius, p[0][0], p[0][1], p[0][2]))
{
return true;
}
}
return false;
}

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)