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



OnPlayerKeyStateChange - Hybris - 11.04.2015

Hello I have a question how could I combine 2 keys to do an action like /wave or something for example C + LALT
I know that C=KEY_CROUCHED and LALT=KEY_WALK but I want to know how to combine the 2 to do 1 thing


AW: OnPlayerKeyStateChange - Mencent - 11.04.2015

Hello!

Try this I found it here:
https://sampwiki.blast.hk/wiki/Keys

PHP код:
#define PRESSED(%0) \
    
(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
    
if(
PRESSED(KEY_CROUCH KEY_WALK)) 
Mencent


Re: OnPlayerKeyStateChange - R0 - 11.04.2015

#define*PRESSED(%0)*\*
****(((newkeys*&*(%0))*==*(%0))*&&*((oldkeys*&*(%0 ))*!=*(%0)))*
if(PRESSED(KEY_CROUCH | KEY_WALK))
{
//animation here
}
By the way i just wanted to explain for him this code up there so i made that other code


Re: OnPlayerKeyStateChange - Crayder - 11.04.2015

Quote:
Originally Posted by R0
Посмотреть сообщение
easy,there you go:
pawn Код:
#define HOLDING(%0) \
        ((newkeys & (%0)) == (%0))

#define RELEASED(%0) (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))

new PressedC[MAX_PLAYERS];
new PressedAlt[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (HOLDING(KEY_CROUCH))
    {
            PressedC[playerid] = 1;
            if(PressedAlt[playerid] == 1)
            {
                LoopingAnim(playerid,"ON_LOOKERS","wave_loop",4.0,1,0,0,0,0);
            }
    }
        if(RELEASED(KEY_CROUCH))
        {
            PressedC[playerid] = 0;
        }
        if(HOLDING(KEY_WALK))
        {
            PressedAlt[playerid] = 1;
            if(PressedC[playerid] == 1)
            {
                LoopingAnim(playerid,"ON_LOOKERS","wave_loop",4.0,1,0,0,0,0);
            }
        }
        if(RELEASED(KEY_WALK))
        {
            PressedAlt[playerid] = 0;
        }
    return 1;
}
Why would you go through this amount of trouble?

Just do what Mencent said, that's how everybody should be doing it because it's correct.