SA-MP Forums Archive
Counter - 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: Counter (/showthread.php?tid=369609)



Counter - CoDeZ - 17.08.2012

Hello , is it possible to count how many times has the CTRL button has been pressed in 5 seconds for example?
Please if someone knows how to do this kindly post the code here and no need to explain if your lazy i'll understand it.
Thanks.


Re: Counter - park4bmx - 17.08.2012

Took some of my spear time

pawn Код:
new MTimer[MAX_PLAYERS];
new TimesPressed[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
if(MTimer!= -1) return KillTimer(MTimer[playerid]);
MTimer[playerid] = SetTimerEx("AfterTimer", 5000, false, "i", playerid);
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if (newkeys & KEY_FIRE && MTimer[playerid] != -1)
      {
            TimesPressed[playerid]++;
      }
}


forward AfterTimer(playerid);
public AfterTimer(playerid){
new Str[128];format(Str,sizeof(Str),"You Press Key 'FIRE' %d times In 5 seconds",TimesPressed[playerid]);
SendClientMessage(playerid,-1,Str);
KillTimer(AfterTimer[playerid]);
TimesPressed[playerid]=0;
return 1;
}
UNTESTED CODE



Re: Counter - CoDeZ - 17.08.2012

DUDE
You rock!
+RP
Thanks <3 ( No Homo ).