Detect Aiming?
#1

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.
Reply
#2

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.
Reply
#3

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);
        }
    }
Reply
#4

Код:
/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.
Reply
#5

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

?
Reply
#6

Ah yes. Thank you.
Reply
#7

Easier:

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

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;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)