Using GetPlayerKeys()... - 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: Using GetPlayerKeys()... (
/showthread.php?tid=311049)
Using GetPlayerKeys()... -
gamer931215 - 14.01.2012
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 ?
Re: Using GetPlayerKeys()... -
Vince - 14.01.2012
Yes, use the bitwise AND operator '&'.
Re: Using GetPlayerKeys()... -
gamer931215 - 14.01.2012
Quote:
Originally Posted by Vince
Yes, use the bitwise AND operator '&'.
|
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