SA-MP Forums Archive
Multiple keys with 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Multiple keys with OnPlayerKeyStateChange (/showthread.php?tid=260439)



Multiple keys with OnPlayerKeyStateChange - [RVRP]Tyler - 08.06.2011

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.


Re: Multiple keys with OnPlayerKeyStateChange - Gamer_Z - 08.06.2011

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?


Re: Multiple keys with OnPlayerKeyStateChange - [RVRP]Tyler - 09.06.2011

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.


Re: Multiple keys with OnPlayerKeyStateChange - [RVRP]Tyler - 12.06.2011

Bump.


Re: Multiple keys with OnPlayerKeyStateChange - Gamer_Z - 13.06.2011

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(?)


Re: Multiple keys with OnPlayerKeyStateChange - [RVRP]Tyler - 16.06.2011

Bump: still nothing.