SA-MP Forums Archive
Problem with keys - 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: Problem with keys (/showthread.php?tid=294973)



Problem with keys - [IL]HeHu - 04.11.2011

PHP код:
    if(IsKeyJustDown(KEY_UP,newkeys,oldkeys) && Viewing[playerid] != && ViewingCar[playerid] != 0)
    { 
and
PHP код:
    if(IsKeyJustDown(KEY_DOWN,newkeys,oldkeys) && Viewing[playerid] != && ViewingCar[playerid] != 0)
    { 
Both of them start operating when I click CAPSLOCK/the right button on my mouse but they won't work when I actually use the keys, I already tried with KEY_LEFT & KEY_RIGHT...


Re: Problem with keys - Simon - 04.11.2011

You need to post more code. What is the IsKeyJustDown() method?


Re: Problem with keys - [IL]HeHu - 04.11.2011

PHP код:
IsKeyJustDown(keynewkeysoldkeys)
{
    if((
newkeys key) && !(oldkeys key)) return 1;
    return 
0;

It wasn't made by me.


Re: Problem with keys - Simon - 04.11.2011

Oh, looks like you're passing in the keys from OnPlayerKeyStateChange. Those keys are different keys to the direction keys.

The KEY_DOWN, KEY_UP, KEY_LEFT and KEY_RIGHT don't work in OnPlayerKeyStateChange. You're required to use GetPlayerKeys(...). Maybe on a timer or OnPlayerUpdate, whichever suits your needs. If you wanted to detect direction keys, you would be required to do something like this:

pawn Код:
new keys, updown, leftright;

GetPlayerKeys(playerid, keys, updown, leftright);

if (updown > 0)  {
    // key_up
} else if (leftright < 0) {
    // key_down
}

if (leftright > 0) {
    // key_right
} else if (leftright < 0) {
    // key_left
}
https://sampwiki.blast.hk/wiki/GetPlayerKeys