Using GetPlayerKeys()...
#1

Hey everyone... i need to detect a few keys at OnPlayerUpdate for a new epic script i'm working on, only im having a kind of a problem...

I need to get the keys at OnPlayerUpdate, because i need to keep the player from updating when the player is pressing a special key, so i cannot use OnPlayerKeyStateChange because this one is called AFTER the player is being updated!

Now lets say i want to detect the Crouch key at OnPlayerUpdate, i would use this code:
pawn Код:
public OnPlayerUpdate(playerid)
{
    new keys,updown,leftright;
    GetPlayerKeys(playerid,keys,updown,leftright);
    printf("Key pressed: %i",keys);
}
Now i can detect the keys by using the "keys" variable, BUT when you press 2 keys at the same time, as example KEY_ACTION (value 1) and KEY_CROUCH (value 2) together it will output 3 instead of an array as example with [1][2].

Is there any option to get the keycode per key ?
Reply
#2

Yes, use the bitwise AND operator '&'.

pawn Код:
if(keys & KEY_CROUCH)
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Yes, use the bitwise AND operator '&'.

pawn Код:
if(keys & KEY_CROUCH)
I've read about it at OnPlayerKeyStateChange() but never thought about using that here (cessil pointed it out for me on IRC)!

Still thanks for the help though
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)