SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 11/01/2011, 06:18 AM   #1
PeteShag
Huge Clucker
 
PeteShag's Avatar
 
Join Date: Jan 2011
Location: Melbourne, Australia
Posts: 215
Reputation: 3
Default Detect Aiming?

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.
PeteShag is offline  
Old 11/01/2011, 06:21 AM   #2
Infamous
Gangsta
 
Infamous's Avatar
 
Join Date: May 2009
Location: Essex, England
Posts: 663
Reputation: 65
Default Re: Detect Aiming?

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 Code:
KEY_AIM* 128

Edit: Thought I better include this message from the wiki:

pawn Code:
[*] Key not defined in SA:MP includes. You must define this yourself.
Infamous is offline  
Old 11/01/2011, 06:24 AM   #3
PeteShag
Huge Clucker
 
PeteShag's Avatar
 
Join Date: Jan 2011
Location: Melbourne, Australia
Posts: 215
Reputation: 3
Default Re: Detect Aiming?

Quote:
Originally Posted by Infamous View Post
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 Code:
KEY_AIM* 128
Ah, cheers!

Edit after you're edit:

Key 128 is Handbrake.

Something like this?

pawn Code:
#define KEY_AIM 132
#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))

pawn Code:
if(pstate == PLAYER_STATE_ONFOOT)
    {
        if (HOLDING(KEY_AIM))
        {
            SetPlayerDrunkLevel(playerid,50000);
        }
    }

Last edited by PeteShag; 11/01/2011 at 07:08 AM.
PeteShag is offline  
Old 11/01/2011, 07:31 AM   #4
PeteShag
Huge Clucker
 
PeteShag's Avatar
 
Join Date: Jan 2011
Location: Melbourne, Australia
Posts: 215
Reputation: 3
Default Re: Detect Aiming?

Code:
/home/SA-MP/Liberty and Vice City RP/United/gamemodes/LcVcRP2.pwn(1318) : warning 213: tag mismatch
pawn Code:
if (HOLDING(KEY_AIM && PlayerInfo[playerid][pGunSkill] == 1))

Edit: Ooops sorry for double post.
PeteShag is offline  
Old 11/01/2011, 07:37 AM   #5
dawidek11
Big Clucker
 
Join Date: Mar 2008
Posts: 93
Reputation: 0
Default Re: Detect Aiming?

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

?
dawidek11 is offline  
Old 11/01/2011, 07:47 AM   #6
PeteShag
Huge Clucker
 
PeteShag's Avatar
 
Join Date: Jan 2011
Location: Melbourne, Australia
Posts: 215
Reputation: 3
Default Re: Detect Aiming?

Ah yes. Thank you.
PeteShag is offline  
Old 11/01/2011, 09:19 AM   #7
[BEP]AcerPilot
Guest
 
Posts: n/a
Default Re: Detect Aiming?

Easier:

pawn Code:
stock IsPlayerAiming(playerid)
{
    new anim = GetPlayerAnimationIndex(playerid);
    switch(anim)
    {
        case 1167, 1365, 1643, 1453, 220:
        {
            return 1;
        }
    }
    return 0;
}
 
Old 11/01/2011, 10:05 AM   #8
[UG]Scripter
Huge Clucker
 
[UG]Scripter's Avatar
 
Join Date: Aug 2010
Location: Perth, Western Australia
Posts: 370
Reputation: 5
Default Re: Detect Aiming?

pawn Code:
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;
}
__________________
UG Scripter ( Formerly State_Trooper ).

" ...To Protect & Serve..." Proud Supporter of Law Enforcement

[UG]Scripter is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Aiming problem. chutem101 Client Support 2 06/03/2011 04:52 AM
Aiming key with no gun GaGlets(R) Bug Reports 4 20/12/2010 11:49 AM
Key for Aiming? (.Aztec); Help Archive 1 05/08/2010 11:26 PM
Aiming Bug Juan_Hernandez Client Support 1 24/12/2009 10:20 PM


All times are GMT. The time now is 03:20 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.