All pastes #1920395 Raw Edit

Someone

public text v1 · immutable
#1920395 ·published 2010-08-19 23:14 UTC
rendered paste body
#tryinclude "a_samp.inc"
#if !defined _samp_included
	#error Please place a_samp.inc library into your includes folder.
#endif

/*
 *  Version: MPL 1.1
 *
 *  The contents of this file are subject to the Mozilla Public License Version
 *  1.1 (the "License"); you may not use this file except in compliance with
 *  the License. You may obtain a copy of the License at
 *  http://www.mozilla.org/MPL/
 *
 *  Software distributed under the License is distributed on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 *  for the specific language governing rights and limitations under the
 *  License.
 *
 *  The Original Code is the Spam Prevention System (Anti Spam) Version 1
 *
 *  The Initial Developer of the Original Code is Luka Pupak.
 *  Portions created by the Initial Developer are Copyright (C) 2010
 *  the Initial Developer. All Rights Reserved.
*/
 
forward SPS_Remove_Messages_Limit(playerid);
forward SPS_Unmute_Player(playerid);
forward SPS_Reset_PVars();

// Define the mute time expressed in minutes
#define PLAYER_MUTE_TIME_MINUTES (2)

public SPS_Reset_PVars()
{
	for(new i=0; i < MAX_PLAYERS; i++)
	{
	    if(GetPVarType(i, "SPS Muted") != PLAYER_VARTYPE_NONE) {
			SetPVarInt(i, "SPS Muted", 0);
		}
		if(GetPVarType(i, "SPS Messages Sent") != PLAYER_VARTYPE_NONE) {
	    	SetPVarInt(i, "SPS Messages Sent", 0);
	    }
	    if(GetPVarType(i, "SPS Spam Warnings") != PLAYER_VARTYPE_NONE) {
	    	SetPVarInt(i, "SPS Spam Warnings", 0);
	    }
	}
	return 1;
}

public OnFilterScriptInit()
{
	CallLocalFunction("SPS_Reset_PVars", "");
	return 1;
}

public OnFilterScriptExit()
{
	CallLocalFunction("SPS_Reset_PVars", "");
	return 1;
}

public OnPlayerText(playerid, text[])
{
	if(GetPVarInt(playerid, "SPS Muted") == 0)
	{
		SetPVarInt(playerid, "SPS Messages Sent", GetPVarInt(playerid, "SPS Messages Sent") + 1);
		SetTimerEx("SPS_Remove_Messages_Limit", 1500, 0, "i", playerid);

		if(GetPVarInt(playerid, "SPS Messages Sent") >= 4)
		{
		    if(!(((GetPVarInt(playerid, "SPS Spam Warnings") + 2) == 3)))
		    {
			    SendClientMessage(playerid, 0xD00000AA, "SERVER: Please, do not spam.");
		    }
		    SetPVarInt(playerid, "SPS Spam Warnings", GetPVarInt(playerid, "SPS Spam Warnings") + 1);
		}
	}
	else
	{
		SendClientMessage(playerid, 0xD00000AA, "SERVER: You are muted, you can't talk.");
		return 0;
	}
	return 1;
}

public SPS_Remove_Messages_Limit(playerid)
{
	if(GetPVarInt(playerid, "SPS Spam Warnings") >= 2)
	{
	    new string[128], pName[MAX_PLAYER_NAME];
		GetPlayerName(playerid, pName, sizeof(pName));
		
		format(string, sizeof(string), "SERVER: Player %s has been muted for %i minutes because of flooding the chat.", pName, PLAYER_MUTE_TIME_MINUTES);
		for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && i != playerid) SendClientMessage(i, 0xD00000AA, string);
		
		format(string, sizeof(string), "SERVER: You have been muted for %i minutes because of flooding the chat.", PLAYER_MUTE_TIME_MINUTES);
	    SendClientMessage(playerid, 0xD00000AA, string);
	    
		SetTimerEx("SPS_Unmute_Player", (PLAYER_MUTE_TIME_MINUTES * 60000), 0, "i", playerid);
		SetPVarInt(playerid, "SPS Muted", 1);
		
		CallRemoteFunction("OnPlayerGetMuted", "i", playerid);
	}
	SetPVarInt(playerid, "SPS Messages Sent", 0);
	SetPVarInt(playerid, "SPS Spam Warnings", 0);
	return 1;
}

public SPS_Unmute_Player(playerid)
{
	SendClientMessage(playerid, 0x28C900FF, "SERVER: You have been automatically unmuted.");
	SetPVarInt(playerid, "SPS Muted", 0);
	return 1;
}