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=459490)



OnPlayerKeyStateChange - audriuxxx - 23.08.2013

Hi,

Why this code doesn't work?

Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if( PRESSED( KEY_UP ) )
	{
	    SendClientMessage(playerid,-1,"ASDASDASD");
	}
return 1;
}
Why when I press ↑ i don't get this message?


Re: OnPlayerKeyStateChange - Konstantinos - 23.08.2013

You cannot check the keys UP/DOWN and LEFT/RIGHT in OnPlayerKeyStateChange. Take a loop at the example Wiki shows: GetPlayerKeys.


Re: OnPlayerKeyStateChange - audriuxxx - 23.08.2013

But how to know when player release ↑ ? Yes, when i use onplayerupdate, then i get message, but i need to know, when player press that arrow, or release.


Re: OnPlayerKeyStateChange - Konstantinos - 23.08.2013

I'm not sure if that would work, checking if the ud is not equal to KEY_UP. I've not used them before, but give a try.


Re: OnPlayerKeyStateChange - Vince - 23.08.2013

You need to store their previous key state and compare it with the new state to figure out whether they pressed or released the key. Values are -128 for down and left, 128 for up and right and 0 for nothing. However, if the player is using a joypad then the value may be anywhere between these limits.


Re: OnPlayerKeyStateChange - Dragonsaurus - 23.08.2013

I believe this should work for releasing KEY_UP:
pawn Код:
if(((newkeys & -128) != -128) && ((oldkeys & -128) == -128))