IsPlayerFacingPlayer
#1

Hello, I tried to do that:

pawn Code:
for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerFacingPlayer(playerid, i, 7.0))
            {
                SendClientMessage(playerid,COLOR_WHITE,"There is a player in front of you!");
            }
        }
     }
It didn't work, what is the problem?
Reply
#2

And what
Reply
#3

Quote:
Originally Posted by ¤Adas¤
And what
Oh sorry, it didn't work ;d
I edited my message.
Reply
#4

Okay, what about these?

pawn Code:
stock Float:PlayerAngle(playerid)
{
new Float:Angle;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
else GetPlayerFacingAngle(playerid, Angle);
return Angle;
}

stock bool:IsPlayerFacingPoint(playerid, Float:PointX, Float:PointY, Float:Range = 10.0)
{
new Float:FacingAngle = PlayerAngle(playerid), Float:Angle;
new Float:X, Float:Y, Float:Z;
GetPlayerPos(playerid, X, Y, Z);
if(X > PointX && Y > PointY) Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
if(X > PointX && Y <= PointY) Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
if(X <= PointX && Y > PointY) Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
if(X <= PointX && Y <= PointY) Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
Range /= 2.0;
return floatabs(floatsub(FacingAngle, Angle)) <= floatabs(Range) || floatabs(floatsub(floatadd(FacingAngle, 360.0), Angle)) <= floatabs(Range);
}

stock bool:IsPlayerFacingPlayer(playerid, faceplayerid, Float:Range = 10.0)
{
if(playerid == faceplayerid) return false;
new Float:X, Float:Y, Float:Z;
GetPlayerPos(faceplayerid, X, Y, Z);
return IsPlayerFacingPoint(playerid, X, Y, Range);
}

stock Float:SetPlayerFaceToPoint(playerid, Float:PointX, Float:PointY)
{
new Float:X, Float:Y, Float:Z;
new Float:Angle;
GetPlayerPos(playerid, X, Y, Z);
if(X > PointX && Y > PointY) Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
if(X > PointX && Y <= PointY) Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
if(X <= PointX && Y > PointY) Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
if(X <= PointX && Y <= PointY) Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
else SetPlayerFacingAngle(playerid, Angle);
return Angle;
}

stock Float:SetPlayerFaceFromPoint(playerid, Float:PointX, Float:PointY)
{
new Float:Angle = floatadd(SetPlayerFaceToPoint(playerid, PointX, PointY), 180.0);
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) SetVehicleZAngle(GetPlayerVehicleID(playerid), Angle);
else SetPlayerFacingAngle(playerid, Angle);
return Angle;
}

stock Float:SetPlayerFaceToPlayer(playerid, faceplayerid)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(faceplayerid, X, Y, Z);
return SetPlayerFaceToPoint(playerid, X, Y);
}

stock Float:SetPlayerFaceFromPlayer(playerid, faceplayerid)
{
new Float:X, Float:Y, Float:Z;
GetPlayerPos(faceplayerid, X, Y, Z);
return SetPlayerFaceFromPoint(playerid, X, Y);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)