Delaying newbie chat
#1

I made a simple newbie chat command which works fine, but I was wondering how I would make a delay so players could only use it every 30 seconds? Here is my command:

Код:
CMD:n(playerid,params[])
{
	if(PlayerInfo[playerid][pToggleNewbie] == 1) return SendClientMessage(playerid,-1,"{AA3333}ERROR:{FFFFFF} You currently have newbie chat toggled off.");
	if(PlayerInfo[playerid][pNewbieMuted] == 1) return SendClientMessage(playerid,-1,"{AA3333}ERROR:{FFFFFF} You are currently muted from using the newbie chat.");
	if(ToggleNewbie == 1) return SendClientMessage(playerid,-1,"{AA3333}ERROR:{FFFFFF} The newbie chat is currently disabled by an administrator.");
	{
	    new question[128];
		if(sscanf(params,"s[128]",question)) return SendClientMessage(playerid,-1,"{AA3333}USAGE:{FFFFFF} /n(ewbie) (question)");
		{
            for(new i = 0; i < MAX_PLAYERS; i++)
    		{
	        	if(IsPlayerConnected(i))
	        	{
	            	if(PlayerInfo[i][pToggleNewbie] == 0)
	            	{
	            	    new newbie[128];
		    			format(newbie,128,"[NewbieChat] Player %s [%i]: %s",RemoveUnderScore(playerid),playerid,question);
						SendClientMessage(i,COLOR_NEWBIE,newbie);
					}
				}
			}
		}
	}
	return 1;
}
Reply
#2

pawn Код:
// Outside any callback
new bool: NewbieChatCooldown[MAX_PLAYERS];

// Top of your command or wherever, anywhere but before the actual code
if(NewbieChatCooldown[playerid]) return SendClientMessage(playerid, -1, "You can't talk in newbie chat yet!");

// After they have sent a message, do this:
NewbieChatCooldown[playerid] = true;
SetTimerEx("NewbieChatCDExpire", 30000, false, "i", playerid);

// Anywhere outside of a callback
forward NewbieChatCDExpire(playerid);
public NewbieChatCDExpire(playerid);
{
    NewbieChatCooldown[playerid] = false;

    return true;
}
EDIT: Make sure to NOT place the timer inside of the loop.
Reply
#3

Thanks for your help!
Reply
#4

otherwise your server will freeze.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)