Cooldown
#1

Hello,

i made a small cooldown for command report (using help from one of samp forum posts), but it doesnt seems to work, players can spam /report without waiting that 1 minute.

PHP код:
COMMAND:report(playeridparams[])
{
    new 
currenttime gettime();
    new 
commandtime[MAX_PLAYERS];
    if(
playerData[playerid][playerLoggedIn])
    {
        if (
playerData[playerid][canReport])
        {
            if(
currenttime >= (commandtime[playerid] + 60))
                {
                new 
input[120], message[250], IDplayerName[30],adminName[30];
            if(
sscanf(params"ds[100]"IDinput ))
            {
                return 
SendClientMessage(playeridCOLOR_WHITE"{B7B7B7}[SERVER] {FFFFFF}Usage: \"report <message>\"");
            }
            else
            {
                foreach(
Playeri)
                {
                    if(
playerData[i][playerLevel] >= 1)
                    {
                        
GetPlayerName(IDplayerNamesizeof(playerName));
                        
GetPlayerName(playeridadminNamesizeof(adminName));
                        
format(messagesizeof(message), "{FF0000}[REPORT] Player %s(%i) has reported{FFFFFF}  %s(%d) - Reason: %s"playerData[playerid][playerNamee], playeridplayerData[ID][playerNamee],IDinput);
                        
SendClientMessage(iCOLOR_WHITEmessage);
                        
commandtime[playerid] = currenttime;
                    }
                }
                return 
SendClientMessage(playeridCOLOR_WHITE"{FF0000}[REPORT] {FFFF00}Your report has been sent to the online administrators.");
                
                   }
                   }
                else
                {
                    new 
str[55];
                    
format(strsizeof(str), "You cannot use this command for another %d seconds.", ((commandtime[playerid] + 60) - currenttime));
                    
SendClientMessage(playerid, -1str);
                }
        }
        else
        {
            return 
SendClientMessage(playeridCOLOR_WHITE"{FF0404}[ERROR] {FFFF00}You have been blocked from using report by an administrator.");
        }
    }
    return 
1;

Reply
#2

You're creating the variable when the player inputs the command, that means it will always be 0 + 60 and gettime() will always input a larger value than that.

pawn Код:
// We just need to create the variable outside the command.
new commandtime[MAX_PLAYERS];

COMMAND:report(playerid, params[])
{
    new currenttime = gettime();  
    if(playerData[playerid][playerLoggedIn])
    {
        if (playerData[playerid][canReport])
        {
            if(currenttime >= (commandtime[playerid] + 60))
                {

                new input[120], message[250], ID, playerName[30],adminName[30];

            if(sscanf(params, "ds[100]", ID, input ))
            {
                return SendClientMessage(playerid, COLOR_WHITE, "{B7B7B7}[SERVER] {FFFFFF}Usage: \"report <message>\"");
            }
            else
            {
                foreach(Player, i)
                {
                    if(playerData[i][playerLevel] >= 1)
                    {
                        GetPlayerName(ID, playerName, sizeof(playerName));
                        GetPlayerName(playerid, adminName, sizeof(adminName));
                        format(message, sizeof(message), "{FF0000}[REPORT] Player %s(%i) has reported{FFFFFF}  %s(%d) - Reason: %s", playerData[playerid][playerNamee], playerid, playerData[ID][playerNamee],ID, input);
                        SendClientMessage(i, COLOR_WHITE, message);
                        commandtime[playerid] = currenttime;

                    }
                }

                return SendClientMessage(playerid, COLOR_WHITE, "{FF0000}[REPORT] {FFFF00}Your report has been sent to the online administrators.");
                 
                   }
                   }
                else
                {
                    new str[55];
                    format(str, sizeof(str), "You cannot use this command for another %d seconds.", ((commandtime[playerid] + 60) - currenttime));
                    SendClientMessage(playerid, -1, str);
                }

        }
        else
        {
            return SendClientMessage(playerid, COLOR_WHITE, "{FF0404}[ERROR] {FFFF00}You have been blocked from using report by an administrator.");
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)