SA-MP Forums Archive
PlayerLookingAt? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: PlayerLookingAt? (/showthread.php?tid=540889)



PlayerLookingAt? - Meisternuke - 08.10.2014

How can i define where the Player is currently looking?

I want to make a antimod sa filterscript.
I freeze the player and if he have mod sa installed his head will look downwards.

So how can i check where the Player is looking?


Re: PlayerLookingAt? - Josh_Main - 08.10.2014

pawn Код:
stock GetPlayerCameraFacingAngle(playerid, &Float:Angle)
{
        new Float:X, Float:Y;
    new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz;
    new Float:XP,Float:YP,Float:ZP;
    if(!IsPlayerInAnyVehicle(playerid))
    {
                GetPlayerPos(playerid,XP ,YP ,ZP);
            GetPlayerCameraPos(playerid, cx, cy, cz);
            GetPlayerCameraFrontVector(playerid, fx, fy, fz);
            X = fx * 999 + cx;
            Y = fy * 999 + cy;
                if(Y > YP) Angle = (-acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP)))-90.0);
                if(Y < YP && X < XP) Angle = (acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP))) - 450.0);
                else if(Y < YP) Angle = (acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP)))-90.0);
                if(X > XP) Angle = (floatabs(floatabs(Angle) + 180.0));
                else Angle = (floatabs(Angle) - 180.0);
        }
        else if(IsPlayerInAnyVehicle(playerid))
    {
                GetVehiclePos(GetPlayerVehicleID(playerid),XP ,YP ,ZP);
            GetPlayerCameraPos(playerid, cx, cy, cz);
            GetPlayerCameraFrontVector(playerid, fx, fy, fz);
            X = fx * 999 + cx;
            Y = fy * 999 + cy;
                if(Y > YP) Angle = (-acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP)))-90.0);
                if(Y < YP && X < XP) Angle = (acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP))) - 450.0);
                else if(Y < YP) Angle = (acos((X - XP) / floatsqroot((X - XP)*(X - XP) + (Y - YP)*(Y - YP)))-90.0);
                if(X > XP) Angle = (floatabs(floatabs(Angle) + 180.0));
                else Angle = (floatabs(Angle) - 180.0);
        }
}
Try this. Not tested


Re: PlayerLookingAt? - Meisternuke - 13.10.2014

hello.. how do i now test with this iff the player is facing left / downwards?


Re: PlayerLookingAt? - Abagail - 13.10.2014

This is done by freezing the player when they spawn, - and getting their camera vectors and then comparing them upon completion. This doesn't always work and I believe it's best used after they connect/while they(are) spawn(ing).