Multiple keys with OnPlayerKeyStateChange
#1

I'm trying to check if a player presses key_fire OR key_action.

I have it like this:

Код:
	if(PRESSED(KEY_FIRE) || PRESSED(KEY_ACTION))
But for some reason, only the first key works when I do it like that. So in other words, if I press key_fire I get the desired outcome but not with key_action. I already tried doing multiple different second keys and still always only the first key works.
Reply
#2

it should work because this does:

pawn Код:
if( newkeys == 1 || newkeys == 9 || newkeys == 33 && oldkeys != 1 || oldkeys != 9 || oldkeys != 33){
            new Car = GetPlayerVehicleID(playerid), Model = GetVehicleModel(Car);
            switch(Model){
                case 446,432,448,452,424,453,454,461,462,463,468,471,430,472,449,473,481,484,493,495,509,510,521,538,522,523,532,537,570,581,586,590,569,595,604,611: return 0;
            }
            AddVehicleComponent(GetPlayerVehicleID(playerid), 1010);
        }
maybe you forgot the oldkeys thingy?
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
gamer_Z: That won't work if you are holding more than one key down, which is why the "PRESSED" etc. macros were created (https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key)

[RVRP]Tyler:

That should be the correct code, could I see the macros you are using to confirm they are correct?
Yeah I'm using:

Код:
#define PRESSED(%0) \
	(((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
And here is what my OnPlayerKeyStateChange looks like:

Код:
if(PRESSED(KEY_FIRE) || PRESSED(KEY_ACTION))
I actually used that page for reference, but still isn't working.
Reply
#4

Bump.
Reply
#5

Quote:
Originally Posted by ******
Посмотреть сообщение
gamer_Z: That won't work if you are holding more than one key down, which is why the "PRESSED" etc. macros were created (https://sampwiki.blast.hk/wiki/OnPlayerK...heck_for_a_key)

[RVRP]Tyler:

That should be the correct code, could I see the macros you are using to confirm they are correct?
Hmm thanks for that <lol>.
Now I know what the & does and I can now use it in other things than just only using it for detecting keys.


@Tyler
Try using the same code in Two if statements but with other if's (one for key 1 and other for key 2) and let us know your results, maybe some other script is called when key_action is called?

Also you see on the wiki:
Quote:

Pressed multiple keys:
if (PRESSED( KEY_FIRE | KEY_CROUCH ))

But I think that is not applicable for you(?)
Reply
#6

Bump: still nothing.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)