a /newbie command
#1

Can anyone help me make this newbie command have a cooldown?
I want normal players "if(PlayerInfo[playerid][pHelper] == 0)" to have a 60 secs cooldown.
and helpers "if(PlayerInfo[playerid][pHelper] == 1)" to have no cooldown

Command:
pawn Код:
if(strcmp(cmd, "/newbie", true) == 0 || strcmp(cmd, "/new", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pMuted] == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
                return 1;
            }
            if(nonewbie == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "Newbie chat is off.");
                return 1;
            }
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[128];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/n)ewbie [newbie chat]");
                return 1;
            }
            if(PlayerInfo[playerid][pHelper] == 0)
            {
                format(string, sizeof(string), "[Newbie]: Newbie %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 1)
            {
               format(string, sizeof(string), "[Newbie]: Helper %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 2)
            {
               format(string, sizeof(string), "[Newbie]: Master %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 3)
            {
                format(string, sizeof(string), "[Newbie]: Administrator %s: %s", sendername, result);
            }
            SendClientMessageToAll(0x62B382AA, string);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string, sizeof(string), "[%d/%d/%d](%d:%d:%d) %s (newbie): (%s)",d,m,y,h,mi,s, sendername, result);
            ChatLog(string);
        }
        return 1;
    }
Reply
#2

Quote:
Originally Posted by Magazinez
Посмотреть сообщение
pawn Код:
//top of script

new Cooldown[MAX_PLAYERS];//cooldown is going to be for MAX_PLAYERS

forward CooldownTimer();//forward our new callback

//ongamemodeinit/filterscriptinit

SetTimer("CooldownTimer",1000,true);//timer to check if the player is in cooldown or not

//onplayerconnect/disconnect

Cooldown[playerid] = 0;//sets there cooldown timer to 0

//command..
if(strcmp(cmd, "/newbie", true) == 0 || strcmp(cmd, "/new", true) == 0)
    {
    if(Cooldown[playerid]) return SendClientMessage(playerid,0x0,"Please Wait Before Using This Command Again!");//checks if there done the command in the last 60 secs
        Cooldown[playerid] =60;// Cooldown is for 60 secs, Modify if needed..
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pMuted] == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "You cannot speak, you have been silenced");
                return 1;
            }
            if(nonewbie == 1)
            {
                SendClientMessage(playerid, TEAM_CYAN_COLOR, "Newbie chat is off.");
                return 1;
            }
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[128];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/n)ewbie [newbie chat]");
                return 1;
            }
            if(PlayerInfo[playerid][pHelper] == 0)
            {
                format(string, sizeof(string), "[Newbie]: Newbie %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 1)
            {
               format(string, sizeof(string), "[Newbie]: Helper %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 2)
            {
               format(string, sizeof(string), "[Newbie]: Master %s: %s", sendername, result);
            }
            else if(PlayerInfo[playerid][pHelper] == 3)
            {
                format(string, sizeof(string), "[Newbie]: Administrator %s: %s", sendername, result);
            }
            SendClientMessageToAll(0x62B382AA, string);
            new y, m, d;
            new h,mi,s;
            getdate(y,m,d);
            gettime(h,mi,s);
            format(string, sizeof(string), "[%d/%d/%d](%d:%d:%d) %s (newbie): (%s)",d,m,y,h,mi,s, sendername, result);
            ChatLog(string);
        }
        return 1;
    }

//anywhere in your script

public CooldownTimer()//resets timer
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(Cooldown[i] > 0)
        {
            Cooldown[i] --;
        }
    }
}
Enjoy,

EDIT:

Change 0x0 to your desired colour define..
Thanks man you rock!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)