15.01.2010, 20:37
To make a command only usable after a set amount of time you need to capture the current tick time and add to it 5 minutes and compare once the player types in the command again.
Example:
Example:
pawn Code:
#define DELAY_TIME 5000 //5 seconds in millseconds
#define DELAY_COMMANDS 2 //2 different commands are delayed
#define DELAY_ADVERT 0 //first command is 0
#define DELAY_HEAL 1 //second command is 1 and so on...
new pDelayCommands[MAX_PLAYERS][DELAY_COMMANDS];
public OnPlayerCommandText(playerid,cmdtext)
{
if(!strcmp(cmdtext[1],"advert",true,6))
{
if(pDelayCommands[playerid][DELAY_ADVERT]>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"You cannot do that yet!");
pDelayCommands[playerid][DELAY_ADVERT]=GetTickCount()+DELAY_TIME;
new string[200];
format(string,sizeof(string),"Advertisement: %s",cmdtext[8]);
SendClientMessageToAll(0xAAAA00FF,string);
return 1;
}
if(!strcmp(cmdtext[1],"heal",true,6))
{
if(pDelayCommands[playerid][DELAY_HEAL]>GetTickCount())return SendClientMessage(playerid,0xFF0000FF,"You cannot do that yet!");
pDelayCommands[playerid][DELAY_HEAL]=GetTickCount()+DELAY_TIME;
SetPlayerHealth(playerid,100.0);
new string[128];
GetPlayerName(playerid,string,sizeof(string));
format(string,sizeof(string),"%s healed himself.",string);
SendClientMessageToAll(0xAAAA00FF,string);
return 1;
}
return 0;
}