SA-MP Forums Archive
IsPlayerLookingAtPlayer problem - 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: IsPlayerLookingAtPlayer problem (/showthread.php?tid=335959)



IsPlayerLookingAtPlayer problem - legodude - 20.04.2012

i ******d some, and they dont seem to work, because they all miss the function GetPlayerCameraUpVector

does anybody know how to create such a function? my math isn't what it should be
rep+ will be given to the ones that helped me


Re: IsPlayerLookingAtPlayer problem - MP2 - 20.04.2012

This may help:

pawn Код:
stock SetPlayerFacePlayer(playerid, faceplayerid)
{
    new Float:Px, Float:Py, Float: Pa;
    GetPlayerPos(playerid, Px, Py, Pa);
    new Float:fpX, Float:fpY, Float: fpZ;
    GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
    Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
    if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
    else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
    else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
    else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
}
However that works on angles, if you want to know if they are in the player's line of sight, you will have to use some maths with GetPlayerCameraPos and GetPlayerCameraFrontVector..


Re: IsPlayerLookingAtPlayer problem - legodude - 20.04.2012

nope, it is only 2d it does the x and the y. i need z too.
lets say the aiming with the sniper should activate a textdraw if someones aiming on somebody else


Re: IsPlayerLookingAtPlayer problem - Ainseri - 20.04.2012

It's not possible.


Re: IsPlayerLookingAtPlayer problem - MP2 - 20.04.2012

If you want to detect aiming, use GetPlayerTargetPlayer. This has three drawbacks however: it must be checked often (OnPlayerUpdate?), it does not work far away or with joypads.

It's the little green arrow above players' heads when you aim at them.


Re: IsPlayerLookingAtPlayer problem - Ainseri - 20.04.2012

Actually, it might be possible using GetPlayerTargetPlayer as MP2 said or GetPlayerCameraFrontVector.