SA-MP Forums Archive
Detect Aiming? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect Aiming? (/showthread.php?tid=209691)



Detect Aiming? - PeteShag - 11.01.2011

Hello people, I looked all around wiki, but nothing. Is there any method to detect if a player is aiming? General aiming, not where the player is aiming.


Re: Detect Aiming? - Infamous - 11.01.2011

You want to detect if the player has raised his gun to the aiming position? If so you can detect the aim button being pressed/held.

pawn Код:
KEY_AIM* 128
Edit: Thought I better include this message from the wiki:

pawn Код:
[*] Key not defined in SA:MP includes. You must define this yourself.



Re: Detect Aiming? - PeteShag - 11.01.2011

Quote:
Originally Posted by Infamous
Посмотреть сообщение
You want to detect if the player has raised his gun to the aiming position? If so you can detect the aim button being pressed/held.

pawn Код:
KEY_AIM* 128
Ah, cheers!

Edit after you're edit:

Key 128 is Handbrake.

Something like this?

pawn Код:
#define KEY_AIM 132
#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))
pawn Код:
if(pstate == PLAYER_STATE_ONFOOT)
    {
        if (HOLDING(KEY_AIM))
        {
            SetPlayerDrunkLevel(playerid,50000);
        }
    }



Re: Detect Aiming? - PeteShag - 11.01.2011

Код:
/home/SA-MP/Liberty and Vice City RP/United/gamemodes/LcVcRP2.pwn(1318) : warning 213: tag mismatch
pawn Код:
if (HOLDING(KEY_AIM && PlayerInfo[playerid][pGunSkill] == 1))
Edit: Ooops sorry for double post.


Re: Detect Aiming? - dawidek11 - 11.01.2011

if (HOLDING(KEY_AIM) && PlayerInfo[playerid][pGunSkill] == 1)

?


Re: Detect Aiming? - PeteShag - 11.01.2011

Ah yes. Thank you.


Re: Detect Aiming? - [BEP]AcerPilot - 11.01.2011

Easier:

pawn Код:
stock IsPlayerAiming(playerid)
{
    new anim = GetPlayerAnimationIndex(playerid);
    switch(anim)
    {
        case 1167, 1365, 1643, 1453, 220:
        {
            return 1;
        }
    }
    return 0;
}



Re: Detect Aiming? - [UG]Scripter - 11.01.2011

pawn Код:
stock IsPlayerAiming(playerid, aimid)
{
    // Luby's function.
    new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
    GetPlayerPos(playerid, X1, Y1, Z1);
    GetPlayerPos(aimid, X2, Y2, Z2);
    new Float:Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
    if(Distance < 100)
    {
        new Float:A;
        GetPlayerFacingAngle(playerid, A);
        X1 += (Distance * floatsin(-A, degrees));
        Y1 += (Distance * floatcos(-A, degrees));
        Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
        if(Distance < 0.5)
        {
            return true;
        }
    }
    return false;
}