SA-MP Forums Archive
Delaying newbie chat - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Server (https://sampforum.blast.hk/forumdisplay.php?fid=6)
+--- Forum: Server Support (https://sampforum.blast.hk/forumdisplay.php?fid=19)
+--- Thread: Delaying newbie chat (/showthread.php?tid=529176)



Delaying newbie chat - jackx3rx - 31.07.2014

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;
}



Re: Delaying newbie chat - Dignity - 31.07.2014

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.


Re: Delaying newbie chat - jackx3rx - 31.07.2014

Thanks for your help!


Re: Delaying newbie chat - driftpower - 01.08.2014

otherwise your server will freeze.