OnPlayerKeyStateChange
#1

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?
Reply
#2

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

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.
Reply
#4

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.
Reply
#5

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.
Reply
#6

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


Forum Jump:


Users browsing this thread: 1 Guest(s)