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



Timer - bartje01 - 15.06.2011

Hey all. I want that you can't spam a command. How to check if this is still running?

Plant[playerid] = SetTimerEx("PlantTimer",10000,false,"i",playerid);


Re: Timer - Benjo - 15.06.2011

Try adding this at the beginning of your PlantTimer function:
pawn Код:
Plant[playerid] = -1; // -1 means that the timer is not running for playerid
Then, when you want to check to see if the timer is running (in OnPlayerCommandText I assume), you can put this at the top:
pawn Код:
if(Plant[playerid] != -1) // Check to see if the timer is running for playerid
    return 1; // + SendClientMessage here if you want to tell the player "Do not spam commands" or w/e!
}

// Your code continues here
I don't know what timerids start at, so you might be able to set Plant[playerid] to 0 if they timerids start at 1. This would make the check to see if the timer is running prettier! Anyway...

Hope this helps!


Re: Timer - bartje01 - 15.06.2011

Quote:
Originally Posted by Benjo
Посмотреть сообщение
Try adding this at the beginning of your PlantTimer function:
pawn Код:
Plant[playerid] = -1; // -1 means that the timer is not running for playerid
Then, when you want to check to see if the timer is running (in OnPlayerCommandText I assume), you can put this at the top:
pawn Код:
if(Plant[playerid] != -1) // Check to see if the timer is running for playerid
    return 1; // + SendClientMessage here if you want to tell the player "Do not spam commands" or w/e!
}

// Your code continues here
I don't know what timerids start at, so you might be able to set Plant[playerid] to 0 if they timerids start at 1. This would make the check to see if the timer is running prettier! Anyway...

Hope this helps!
Haha. That I didn't think of this earlier :P Thanks mate


Re: Timer - bartje01 - 15.06.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
Why not just use GetTickCount and check the time elapsed since the last use?
I will look at that later. Thankyou. I now have another problem. You might want to read my thread about it.