how do i make a cooldown for anti cmd spam? - 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: how do i make a cooldown for anti cmd spam? (
/showthread.php?tid=655337)
how do i make a cooldown for anti cmd spam? -
div - 19.06.2018
I was wondering how to make a 1 second cooldown before using ANY command again..
For example - I've used a command '/help', and if i input another command before a second passes, it will send me a message "ERROR: You need to wait 1 second before using any command again."
and, a timer of 45 seconds aswell? for a particular command..
I'm new to pawn.. i'm not aware of all the functions.. SA-MP FORUMS is my teacher for now.. THANK YOU.
Re: how do i make a cooldown for anti cmd spam? -
kovac - 19.06.2018
ZCMD example:
PHP код:
new AntiSpam[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[])
{
if(AntiSpam[playerid]-gettime() > 0)
{
SendClientMessage(playerid, COLOR_RED, "ERROR: Don't spam. Wait before using another command.");
return 0;
}
AntiSpam[playerid] = gettime() + 1; // cooldown (in seconds)
return 1;
}
Re: how do i make a cooldown for anti cmd spam? -
Gameluner - 19.06.2018
Hi,
That's one way. Another system is to make a timer for the player, which disables the variable. And of course check if the variable is enabled on the Command start.
Ex. not for copying:
Код:
new bool:AS[MAX_PLAYERS_EX];
forward asas(playerid);
public asas(playerid) {
AS[playerid] = false;
return 1;
}
public OnPlayerCommand(playerid,.......) {
if(!AS[playerid]) {
SCM(playerid,...);
return 0;
}
if(!strcmp,....) {
// Ur codes
AS[playerid] = true;
SetTimer("asas",1500,0);
}
return 0;
}
Hope you understood.
Bye.