31.03.2011, 02:57
Anti-spam 'timers' can be used in many ways, whether it be with a command, a chat, or anything else. The quickest and easiest way to do it, would to be using PVars and GetTickCount. Let's do an example. Let's say you want a player to wait 10 seconds before using the normal chat again.
Now let's break it down.
The purpose of this line, is to check if the amount of time between when you last used the chat, and now is atleast 10 seconds. It does it by getting the tick count (GetTickCount) and subtracting the PVar from it. The tick count is basically like a constantly increasing number, in milliseconds.
The purpose of these lines, are to send the message, and update the PVar. The first line sends the message, and the second one sets the PVar to the current tick count, so it knows when you last used the chat.
The purpose of these lines is to give the player an error message if they haven't waited 10 seconds. This 'else' statement corresponds with the 'if' statement above.
That's basically it. This can be used in many ways, and can prevent you from getting spammed like hell. Good luck.
pawn Code:
public OnPlayerText(playerid, text[])
{
if((GetTickCount() - GetPVarInt(playerid, "AntiSpam")) > 10000)
{
SendClientMessageToAll(-1, text);
SetPVarInt(playerid, "AntiSpam", GetTickCount());
}
else
{
SendClientMessage(playerid, -1, "You must wait atleast 10 seconds before using this chat again.");
}
return 0;
}
pawn Code:
if((GetTickCount() - GetPVarInt(playerid, "AntiSpam")) > 10000)
{
pawn Code:
SendClientMessageToAll(-1, text);
SetPVarInt(playerid, "AntiSpam", GetTickCount());
pawn Code:
else
{
SendClientMessage(playerid, -1, "You must wait atleast 10 seconds before using this chat again.");
}
That's basically it. This can be used in many ways, and can prevent you from getting spammed like hell. Good luck.