how do i make a cooldown for anti cmd spam?
#1

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.
Reply
#2

ZCMD example:

PHP код:
new AntiSpam[MAX_PLAYERS];
public 
OnPlayerCommandReceived(playeridcmdtext[])
{
    if(
AntiSpam[playerid]-gettime() > 0)
    {
        
SendClientMessage(playeridCOLOR_RED"ERROR: Don't spam. Wait before using another command.");
        return 
0;
    }
    
AntiSpam[playerid] = gettime() + 1// cooldown (in seconds)
    
return 1;

Reply
#3

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)