Is player holding a key
#1

Hi,

How to check if player is holding a key, for ex spectating player, with a or d and as long he hold key will be changing spectating player
Reply
#2

Figure out the interval you want before changing to the next player. Half a second will do probably. Perhaps a bit less. In OnPlayerKeyStateChange when the key is first PRESSED set a repeating timer and assign it to a variable. When the key is RELEASED use the variable to kill the timer. In the timer itself do the spectate stuff.

Worth noting though that directional keys (WASD) do not trigger OnPlayerKeyStateChange so you will have to resort to OnPlayerUpdate if you want to reliably detect those.
Reply
#3

For A and D you could use the OnPlayerUpdate with leftright
https://sampwiki.blast.hk/wiki/GetPlayerKeys
Like the example on SA-MP Wiki
Код:
public OnPlayerUpdate(playerid)
{
    new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);
    if(lr == KEY_LEFT) 
    {
         //Something here
    }
    else if(lr == KEY_RIGHT) 
    {
         //Something here
    }
 
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)