plugins/basecomm.sp
branchrefac-jit
changeset 2284 026da5437111
parent 2192 7602d7fb60d9
child 2288 15c77b21589a
     1.1 --- a/plugins/basecomm.sp	Fri Jul 11 06:51:21 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,230 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Communication Plugin
     1.8 - * Provides fucntionality for controlling communication on the server
     1.9 - *
    1.10 - * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
    1.11 - * =============================================================================
    1.12 - *
    1.13 - * This program is free software; you can redistribute it and/or modify it under
    1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 - * Free Software Foundation.
    1.16 - * 1
    1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 - * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 - * details.
    1.21 - *
    1.22 - * You should have received a copy of the GNU General Public License along with
    1.23 - * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 - *
    1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 - * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 - * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 - * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 - * or <http://www.sourcemod.net/license.php>.
    1.33 - *
    1.34 - * Version: $Id$
    1.35 - */
    1.36 -
    1.37 -#include <sourcemod>
    1.38 -#include <sdktools>
    1.39 -#undef REQUIRE_PLUGIN
    1.40 -#include <adminmenu>
    1.41 -
    1.42 -#pragma semicolon 1
    1.43 -
    1.44 -public Plugin:myinfo =
    1.45 -{
    1.46 -	name = "Basic Comm Control",
    1.47 -	author = "AlliedModders LLC",
    1.48 -	description = "Provides methods of controllingg communication.",
    1.49 -	version = SOURCEMOD_VERSION,
    1.50 -	url = "http://www.sourcemod.net/"
    1.51 -};
    1.52 -
    1.53 -new bool:g_Muted[MAXPLAYERS+1];		// Is the player muted?
    1.54 -new bool:g_Gagged[MAXPLAYERS+1];	// Is the player gagged?
    1.55 -
    1.56 -new Handle:g_Cvar_Deadtalk = INVALID_HANDLE;	// Holds the handle for sm_deadtalk
    1.57 -new Handle:g_Cvar_Alltalk = INVALID_HANDLE;	// Holds the handle for sv_alltalk
    1.58 -new bool:g_Hooked = false;			// Tracks if we've hooked events for deadtalk
    1.59 -
    1.60 -new Handle:hTopMenu = INVALID_HANDLE;
    1.61 -
    1.62 -new g_GagTarget[MAXPLAYERS+1];
    1.63 -
    1.64 -#include "basecomm/gag.sp"
    1.65 -
    1.66 -public OnPluginStart()
    1.67 -{
    1.68 -	LoadTranslations("common.phrases");
    1.69 -	LoadTranslations("basecomm.phrases");
    1.70 -	
    1.71 -	g_Cvar_Deadtalk = CreateConVar("sm_deadtalk", "0", "Controls how dead communicate. 0 - Off. 1 - Dead players ignore teams. 2 - Dead players talk to living teammates.", 0, true, 0.0, true, 2.0);
    1.72 -	g_Cvar_Alltalk = FindConVar("sv_alltalk");
    1.73 -	
    1.74 -	RegConsoleCmd("say", Command_Say);
    1.75 -	RegConsoleCmd("say_team", Command_Say);
    1.76 -	
    1.77 -	RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute <player> - Removes a player's ability to use voice.");
    1.78 -	RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag <player> - Removes a player's ability to use chat.");
    1.79 -	RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence <player> - Removes a player's ability to use voice or chat.");
    1.80 -	
    1.81 -	RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute <player> - Restores a player's ability to use voice.");
    1.82 -	RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag <player> - Restores a player's ability to use chat.");
    1.83 -	RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence <player> - Restores a player's ability to use voice and chat.");	
    1.84 -	
    1.85 -	HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
    1.86 -	HookConVarChange(g_Cvar_Alltalk, ConVarChange_Alltalk);
    1.87 -	
    1.88 -	/* Account for late loading */
    1.89 -	new Handle:topmenu;
    1.90 -	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    1.91 -	{
    1.92 -		OnAdminMenuReady(topmenu);
    1.93 -	}
    1.94 -}
    1.95 -
    1.96 -public OnAdminMenuReady(Handle:topmenu)
    1.97 -{
    1.98 -	/* Block us from being called twice */
    1.99 -	if (topmenu == hTopMenu)
   1.100 -	{
   1.101 -		return;
   1.102 -	}
   1.103 -	
   1.104 -	/* Save the Handle */
   1.105 -	hTopMenu = topmenu;
   1.106 -	
   1.107 -	/* Build the "Player Commands" category */
   1.108 -	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   1.109 -	
   1.110 -	if (player_commands != INVALID_TOPMENUOBJECT)
   1.111 -	{
   1.112 -		AddToTopMenu(hTopMenu, 
   1.113 -			"sm_gag",
   1.114 -			TopMenuObject_Item,
   1.115 -			AdminMenu_Gag,
   1.116 -			player_commands,
   1.117 -			"sm_gag",
   1.118 -			ADMFLAG_CHAT);
   1.119 -	}
   1.120 -}
   1.121 -
   1.122 -public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
   1.123 -{
   1.124 -	if (GetConVarInt(g_Cvar_Deadtalk))
   1.125 -	{
   1.126 -		HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
   1.127 -		HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
   1.128 -		g_Hooked = true;
   1.129 -	}
   1.130 -	else if (g_Hooked)
   1.131 -	{
   1.132 -		UnhookEvent("player_spawn", Event_PlayerSpawn);
   1.133 -		UnhookEvent("player_death", Event_PlayerDeath);		
   1.134 -		g_Hooked = false;
   1.135 -	}
   1.136 -}
   1.137 -
   1.138 -
   1.139 -public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
   1.140 -{
   1.141 -	g_Gagged[client] = false;
   1.142 -	g_Muted[client] = false;
   1.143 -	
   1.144 -	return true;
   1.145 -}
   1.146 -
   1.147 -public Action:Command_Say(client, args)
   1.148 -{
   1.149 -	if (client)
   1.150 -	{
   1.151 -		if (g_Gagged[client])
   1.152 -		{
   1.153 -			return Plugin_Handled;		
   1.154 -		}
   1.155 -	}
   1.156 -	
   1.157 -	return Plugin_Continue;
   1.158 -}
   1.159 -
   1.160 -public ConVarChange_Alltalk(Handle:convar, const String:oldValue[], const String:newValue[])
   1.161 -{
   1.162 -	new mode = GetConVarInt(g_Cvar_Deadtalk);
   1.163 -	new maxClients = GetMaxClients();
   1.164 -	
   1.165 -	for (new i = 1; i <= maxClients; i++)
   1.166 -	{
   1.167 -		if (!IsClientInGame(i))
   1.168 -		{
   1.169 -			continue;
   1.170 -		}
   1.171 -		
   1.172 -		if (g_Muted[i])
   1.173 -		{
   1.174 -			SetClientListeningFlags(i, VOICE_MUTED);
   1.175 -		}
   1.176 -		else if (GetConVarBool(g_Cvar_Alltalk))
   1.177 -		{
   1.178 -			SetClientListeningFlags(i, VOICE_NORMAL);
   1.179 -		}
   1.180 -		else
   1.181 -		{
   1.182 -			if (mode == 1)
   1.183 -			{
   1.184 -				SetClientListeningFlags(i, VOICE_LISTENALL);
   1.185 -			}
   1.186 -			else if (mode == 2)
   1.187 -			{
   1.188 -				SetClientListeningFlags(i, VOICE_TEAM);
   1.189 -			}
   1.190 -		}
   1.191 -	}
   1.192 -}
   1.193 -
   1.194 -public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
   1.195 -{
   1.196 -	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   1.197 -	
   1.198 -	if (g_Muted[client])
   1.199 -	{
   1.200 -		SetClientListeningFlags(client, VOICE_MUTED);
   1.201 -	}
   1.202 -	else
   1.203 -	{
   1.204 -		SetClientListeningFlags(client, VOICE_NORMAL);
   1.205 -	}
   1.206 -}
   1.207 -
   1.208 -public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   1.209 -{
   1.210 -	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   1.211 -	
   1.212 -	if (g_Muted[client])
   1.213 -	{
   1.214 -		SetClientListeningFlags(client, VOICE_MUTED);
   1.215 -		return;
   1.216 -	}
   1.217 -	
   1.218 -	if (GetConVarBool(g_Cvar_Alltalk))
   1.219 -	{
   1.220 -		SetClientListeningFlags(client, VOICE_NORMAL);
   1.221 -		return;
   1.222 -	}
   1.223 -	
   1.224 -	new mode = GetConVarInt(g_Cvar_Deadtalk);
   1.225 -	if (mode == 1)
   1.226 -	{
   1.227 -		SetClientListeningFlags(client, VOICE_LISTENALL);
   1.228 -	}
   1.229 -	else if (mode == 2)
   1.230 -	{
   1.231 -		SetClientListeningFlags(client, VOICE_TEAM);
   1.232 -	}
   1.233 -}