[Tutorial] Adding quick anti-spam timers
#1

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.

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;
}
Now let's break it down.

pawn Code:
if((GetTickCount() - GetPVarInt(playerid, "AntiSpam")) > 10000)
    {
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.

pawn Code:
SendClientMessageToAll(-1, text);
        SetPVarInt(playerid, "AntiSpam", GetTickCount());
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.

pawn Code:
else
    {
        SendClientMessage(playerid, -1, "You must wait atleast 10 seconds before using this chat again.");
    }
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.
Reply
#2

You Didn't explain good
Please explain more
Why it is used?
What is advantages of Anti-Spam?
Reply
#3

I explained perfectly fine, and I already included why it's used and what are some advantages. Go troll somewhere else, kid.
Reply
#4

Quote:
Originally Posted by BASITJALIL
View Post
You Didn't explain good
Please explain more
Why it is used?
What is advantages of Anti-Spam?
He explained it Great, He put advantages. And why it is being used.

Nice job Ant-man.
Reply
#5

very nice tutorial!
Reply
#6

very good, i understand it very good
Reply
#7

You obviously didn't test it. You want to know how I did see that? This:
pawn Code:
SendClientMessageToAll(-1, text);
How should the players ever know who sent that particular text? No name is sent.
Using Pvars is also almost never the quickest way to do something. Ordinary variables are a lot faster.
Reply
#8

Quote:
Originally Posted by Vince
View Post
You obviously didn't test it. You want to know how I did see that? This:
pawn Code:
SendClientMessageToAll(-1, text);
How should the players ever know who sent that particular text? No name is sent.
Using Pvars is also almost never the quickest way to do something. Ordinary variables are a lot faster.
1. That doesn't necessarily matter, this was to show how to do it.
2. Same as #1, I was just using this example to show to players how to use the Anti-Spam
3. I wasn't going by efficiency, I was going on time and effort to create it. I know PVars are slower, however sometimes people don't like scrolling to the top of their script, creating a new variable, scrolling down to OnPlayerConnect, zero'ing the variable, and then using it. For time, it's easier to use PVars.
Reply
#9

Quote:
Originally Posted by Antonio [G-RP]
View Post
1. That doesn't necessarily matter, this was to show how to do it.
2. Same as #1, I was just using this example to show to players how to use the Anti-Spam
3. I wasn't going by efficiency, I was going on time and effort to create it. I know PVars are slower, however sometimes people don't like scrolling to the top of their script, creating a new variable, scrolling down to OnPlayerConnect, zero'ing the variable, and then using it. For time, it's easier to use PVars.
..+1
Reply
#10

heres a better version. i will maybe edit it later to make it use a variable instead of pvars.

pawn Code:
public OnPlayerText(playerid, text[])
{
    if((GetTickCount() - GetPVarInt(playerid, "AntiSpam")) > 1000)
    {
        new string[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s (%i): %s", name, playerid, text);
        SendClientMessageToAll(GetPlayerColor(playerid), string);
        SetPVarInt(playerid, "AntiSpam", GetTickCount());
    }
    else
    {
        SendClientMessage(playerid, 0xFF000FF, "You must wait atleast 1 second before using the chat again.");
    }
    return 0;
}
Reply
#11

Tnx Im Understand Good TUT
Reply
#12

Quote:
Originally Posted by sciman001
Посмотреть сообщение
heres a better version. i will maybe edit it later to make it use a variable instead of pvars.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if((GetTickCount() - GetPVarInt(playerid, "AntiSpam")) > 1000)
    {
        new string[128], name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "%s (%i): %s", name, playerid, text);
        SendClientMessageToAll(GetPlayerColor(playerid), string);
        SetPVarInt(playerid, "AntiSpam", GetTickCount());
    }
    else
    {
        SendClientMessage(playerid, 0xFF000FF, "You must wait atleast 1 second before using the chat again.");
    }
    return 0;
}
Sendclientmessagetoall(Getplayercolor...

How do i use it in tdm where i don't want the player text to be in color of player ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)