View Single Post
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 11-20-2020 , 10:11   Re: Temporarily saving a player's message (Anti-Spam plugin)
Reply With Quote #2

The solution was to index both playermessage and samemessage per client.

Here is the fixed code:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

char spamcount[MAXPLAYERS 1] =  { 0, ... };
char playermessage[MAXPLAYERS 1][128];
char samemessage[MAXPLAYERS 1][128];

public 
Plugin myinfo 
{
    
name "Anti-Spam",
    
author "FAQU"
    
//description = "Gags the player for sending the same message 3 times in less than 10 seconds."
};

public 
void OnPluginStart()
{
    
HookEvent("player_say"OnPlayerSay);
}

public 
void OnClientPutInServer(int client)
{
    
ResetSpamCount(client);
}

public 
void OnClientDisconnect(int client)
{
    
ResetSpamCount(client);
}

public 
Action OnPlayerSay(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
GetEventString(event"text"playermessage[client], sizeof(playermessage));
    
    if (
spamcount[client] == 0)
    {
        
strcopy(samemessage[client], sizeof(samemessage), playermessage[client]);
        
spamcount[client]++;
        
CreateTimer(10.0Timer_ResetSpamcountclient);
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 1)
    {
        if (
StrEqual(playermessage[client], samemessage[client]))
        {
            
spamcount[client]++;
        }
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 2)
    {
        if (
StrEqual(playermessage[client], samemessage[client]))
        {
            
int userid GetClientUserId(client);
            
ServerCommand("sm_gag #%d"userid);
            
ResetSpamCount(client);
        }
        return 
Plugin_Handled;
    }
    else
    return 
Plugin_Handled;
}

public 
Action Timer_ResetSpamcount(Handle timerint client)
{
    
ResetSpamCount(client);
}

void ResetSpamCount(int client)
{
    
spamcount[client] = 0;


Last edited by FAQU; 11-22-2020 at 00:05. Reason: "The Almighty Goat; quit"
FAQU is offline