new TextTickOne[MAX_PLAYERS];
new TextTickTwo[MAX_PLAYERS];
#define MAX_WAIT_TIME 500 //max waiting time in MS (half a second here)
public OnPlayerCommandText(playerid, cmdtext[])
{
if(TextTickTwo[playerid] == 0 && TextTickOne[playerid] ==0 ) TextTickOne[playerid] = GetTickCount();//if he hasn't used a cmd for a while
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] == 0) TextTickTwo[playerid] = GetTickCount();//if he used a cmd once
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] != 0 && TextTickTwo[playerid] - TextTickOne[playerid] < MAX_WAIT_TIME) //if he messaged for the 2nd time check if last time was lower than the max time (500 ms)
{
SendClientMessage(playerid, -1, " Hi, stop spamming you asshole");
TextTickOne[playerid] = 0; ///reset
TextTickTwo[playerid] = 0; //Same ^^
return 0;
}
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] != 0 && TextTickTwo[playerid] - TextTickOne[playerid] >= MAX_WAIT_TIME) //if it took him long enough to use a cmd again
{
TextTickOne[playerid] =0; //reset
TextTickTwo[playerid] =0; //Same ^^
}
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
TextTickOne[playerid] =0; //reset in case of disconnection
TextTickTwo[playerid] =0; //Same ^^
return 1;
}
The edit is another thing that i want.
So, when a player spam a command more than 5 times, it will make a 60 seconds delay to use again the command. |
it will send me the message and Unknown Command if i spam, i use ZCMD and the function is not OnPlayerCommandText, is OnPlayerCommandPerformed
|
new TextTickOne[MAX_PLAYERS];
new TextTickTwo[MAX_PLAYERS];
#define MAX_WAIT_TIME 500 //max waiting time in MS (half a second here)
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(TextTickTwo[playerid] == 0 && TextTickOne[playerid] ==0 ) TextTickOne[playerid] = GetTickCount();//if he hasn't used a cmd for a while
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] == 0) TextTickTwo[playerid] = GetTickCount();//if he used a cmd once
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] != 0 && TextTickTwo[playerid] - TextTickOne[playerid] < MAX_WAIT_TIME) //if he messaged for the 2nd time check if last time was lower than the max time (500 ms)
{
SendClientMessage(playerid, -1, " Hi, stop spamming you asshole");
TextTickOne[playerid] = 0; ///reset
TextTickTwo[playerid] = 0; //Same ^^
return 1;
}
else if(TextTickOne[playerid] != 0 && TextTickTwo[playerid] != 0 && TextTickTwo[playerid] - TextTickOne[playerid] >= MAX_WAIT_TIME) //if it took him long enough to use a cmd again
{
TextTickOne[playerid] =0; //reset
TextTickTwo[playerid] =0; //Same ^^
}
if(!success) return 0;
else return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
TextTickOne[playerid] =0; //reset in case of disconnection
TextTickTwo[playerid] =0; //Same ^^
return 1;
}