SA-MP Forums Archive
[Tutorial] Adding quick anti-spam timers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Adding quick anti-spam timers (/showthread.php?tid=245358)



Adding quick anti-spam timers - Antonio [G-RP] - 31.03.2011

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.


Re: Adding quick anti-spam timers - BASITJALIL - 31.03.2011

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


Re: Adding quick anti-spam timers - Antonio [G-RP] - 31.03.2011

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


Re: Adding quick anti-spam timers - -Rebel Son- - 31.03.2011

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.


Re: Adding quick anti-spam timers - Medal Of Honor team - 31.03.2011

very nice tutorial!


Re: Adding quick anti-spam timers - Scratch - 31.03.2011

very good, i understand it very good


Re: Adding quick anti-spam timers - Vince - 31.03.2011

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.


Re: Adding quick anti-spam timers - Antonio [G-RP] - 31.03.2011

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.


Re: Adding quick anti-spam timers - -Rebel Son- - 01.04.2011

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


Re: Adding quick anti-spam timers - sciman001 - 02.04.2011

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;
}



Re: Adding quick anti-spam timers - Venice - 03.04.2011

Tnx Im Understand Good TUT


Re: Adding quick anti-spam timers - Champ - 21.08.2012

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 ?