29.07.2011, 14:31
Hi peoples.I need some help with anti-command text.I want to that when player use any command he can use again after 3 sec.
new cSpam[MAX_PLAYERS];
forward AntiSpam(playerid);
public AntiSpam(playerid)
{
if(cSpam(playerid) == 1)
{
cSpam[playerid] = 0;
}
return 1;
}
cSpam[playerid] = 1;
SetTimerEx("AntiSpam", 3000, 0, "i", playerid);
if(cSpam[playerid] == 1) return SendClientMessage(playerid, color, "Error message here");
I'll say this here, like I say it every time someone gives that as a solution to this issue - you're wrong (I've given up being nice on this point). The VASTLY simpler way of doing this is just compare "GetTickCount"s.
|
"GetTickCount will cause problems on servers with uptime of over 24 days (physical server, not SA:MP server) as GetTickCount will eventually warp past the integer size constraints"
gettime()
new x[MAX_PLAYERS]; //A global variable
//In the command:
if(x[playerid] != 0 && x[playerid] < gettime()) return SendClientMessage(playerid, 0xFFFFFFAA, "Wait ! :D");
x[playerid] = gettime()+3;
new
g_iCmdTickCount[MAX_PLAYERS];
public OnPlayerCommandText(playerid, cmdtext[]) {
if(g_iCmdTickCount[playerid] + 3000 > GetTickCount() && g_iCmdTickCount[playerid] > 0) { // GetTickCount returns the uptime of the actual server in milliseconds. 1 second = 1000 MS.
SendClientMessage(playerid, 0, "[error message]");
return 1;
}
g_iCmdTickCount[playerid] = GetTickCount();
/* Your commands.... */
return 1;
}
public OnPlayerCommandReceived(playerid, cmdtext[])