Is player holding a key - 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: Is player holding a key (
/showthread.php?tid=626303)
Is player holding a key -
MerryDeer - 13.01.2017
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
Re: Is player holding a key -
Vince - 13.01.2017
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.
Re: Is player holding a key -
darkdrago - 13.01.2017
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;
}