plugins/basecomm.sp
author Michael McKoy <ferret99gt@gmail.com>
Wed Dec 19 01:16:15 2007 +0000 (2007-12-19)
changeset 1801 06ff8ce94b2b
parent 1660 85a79eaece9e
child 1818 1c712b03a024
permissions -rw-r--r--
Large additions to basefuncommands. Moved slay and slap to a new plugin.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Communication Plugin
     5  * Provides fucntionality for controlling communication on the server
     6  *
     7  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    10  * This program is free software; you can redistribute it and/or modify it under
    11  * the terms of the GNU General Public License, version 3.0, as published by the
    12  * Free Software Foundation.
    13  * 1
    14  * This program is distributed in the hope that it will be useful, but WITHOUT
    15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    17  * details.
    18  *
    19  * You should have received a copy of the GNU General Public License along with
    20  * this program.  If not, see <http://www.gnu.org/licenses/>.
    21  *
    22  * As a special exception, AlliedModders LLC gives you permission to link the
    23  * code of this program (as well as its derivative works) to "Half-Life 2," the
    24  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    25  * by the Valve Corporation.  You must obey the GNU General Public License in
    26  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    27  * this exception to all derivative works.  AlliedModders LLC defines further
    28  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    29  * or <http://www.sourcemod.net/license.php>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 #include <sourcemod>
    35 #include <sdktools>
    36 #undef REQUIRE_PLUGIN
    37 #include <adminmenu>
    38 
    39 #pragma semicolon 1
    40 
    41 public Plugin:myinfo =
    42 {
    43 	name = "Basic Comm Control",
    44 	author = "AlliedModders LLC",
    45 	description = "Provides methods of controllingg communication.",
    46 	version = SOURCEMOD_VERSION,
    47 	url = "http://www.sourcemod.net/"
    48 };
    49 
    50 new bool:g_Muted[MAXPLAYERS+1];		// Is the player muted?
    51 new bool:g_Gagged[MAXPLAYERS+1];	// Is the player gagged?
    52 
    53 new Handle:g_Cvar_Deadtalk = INVALID_HANDLE;	// Holds the handle for sm_deadtalk
    54 new Handle:g_Cvar_Alltalk = INVALID_HANDLE;	// Holds the handle for sv_alltalk
    55 new bool:g_Hooked = false;			// Tracks if we've hooked events for deadtalk
    56 
    57 new Handle:hTopMenu = INVALID_HANDLE;
    58 
    59 new g_GagTarget[MAXPLAYERS+1];
    60 
    61 #include "basecomm/gag.sp"
    62 
    63 public OnPluginStart()
    64 {
    65 	LoadTranslations("common.phrases");
    66 	LoadTranslations("basecomm.phrases");
    67 	
    68 	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);
    69 	g_Cvar_Alltalk = FindConVar("sv_alltalk");
    70 	
    71 	RegConsoleCmd("say", Command_Say);
    72 	RegConsoleCmd("say_team", Command_Say);
    73 	
    74 	RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute <player> - Removes a player's ability to use voice.");
    75 	RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag <player> - Removes a player's ability to use chat.");
    76 	RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence <player> - Removes a player's ability to use voice or chat.");
    77 	
    78 	RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute <player> - Restores a player's ability to use voice.");
    79 	RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag <player> - Restores a player's ability to use chat.");
    80 	RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence <player> - Restores a player's ability to use voice and chat.");	
    81 	
    82 	HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
    83 	HookConVarChange(g_Cvar_Alltalk, ConVarChange_Alltalk);
    84 	
    85 	/* Account for late loading */
    86 	new Handle:topmenu;
    87 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    88 	{
    89 		OnAdminMenuReady(topmenu);
    90 	}
    91 }
    92 
    93 public OnAdminMenuReady(Handle:topmenu)
    94 {
    95 	/* Block us from being called twice */
    96 	if (topmenu == hTopMenu)
    97 	{
    98 		return;
    99 	}
   100 	
   101 	/* Save the Handle */
   102 	hTopMenu = topmenu;
   103 	
   104 	/* Build the "Player Commands" category */
   105 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   106 	
   107 	if (player_commands != INVALID_TOPMENUOBJECT)
   108 	{
   109 		AddToTopMenu(hTopMenu, 
   110 			"sm_gag",
   111 			TopMenuObject_Item,
   112 			AdminMenu_Gag,
   113 			player_commands,
   114 			"sm_gag",
   115 			ADMFLAG_CHAT);
   116 	}
   117 }
   118 
   119 public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
   120 {
   121 	if (GetConVarInt(g_Cvar_Deadtalk))
   122 	{
   123 		HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
   124 		HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
   125 		g_Hooked = true;
   126 	}
   127 	else if (g_Hooked)
   128 	{
   129 		UnhookEvent("player_spawn", Event_PlayerSpawn);
   130 		UnhookEvent("player_death", Event_PlayerDeath);		
   131 		g_Hooked = false;
   132 	}
   133 }
   134 
   135 
   136 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
   137 {
   138 	g_Gagged[client] = false;
   139 	g_Muted[client] = false;
   140 	
   141 	return true;
   142 }
   143 
   144 public Action:Command_Say(client, args)
   145 {
   146 	if (client)
   147 	{
   148 		if (g_Gagged[client])
   149 		{
   150 			return Plugin_Handled;		
   151 		}
   152 	}
   153 	
   154 	return Plugin_Continue;
   155 }
   156 
   157 public ConVarChange_Alltalk(Handle:convar, const String:oldValue[], const String:newValue[])
   158 {
   159 	if (StringToInt(newValue) != 0
   160 		|| StringToInt(oldValue) == 0)
   161 	{
   162 		return;
   163 	}
   164 	
   165 	new dt_val = GetConVarInt(g_Cvar_Deadtalk);
   166 	new max_clients = GetMaxClients();
   167 	
   168 	for (new i = 1; i <= max_clients; i++)
   169 	{
   170 		if (!IsClientInGame(i))
   171 		{
   172 			continue;
   173 		}
   174 		
   175 		PrintToServer("STAT (i %d) (g_Muted[%d] %d) (dt_val %d)", i, i, g_Muted[i], dt_val);
   176 		
   177 		if (IsPlayerAlive(i))
   178 		{
   179 			if (g_Muted[i])
   180 			{
   181 				SetClientListeningFlags(i, VOICE_MUTED);
   182 			}
   183 			else
   184 			{
   185 				SetClientListeningFlags(i, VOICE_NORMAL);
   186 			}
   187 		}
   188 		else
   189 		{
   190 			if (g_Muted[i])
   191 			{
   192 				SetClientListeningFlags(i, VOICE_MUTED);
   193 			}
   194 			else if (dt_val == 1)
   195 			{
   196 				SetClientListeningFlags(i, VOICE_LISTENALL);
   197 			}
   198 			else if (dt_val == 2)
   199 			{
   200 				SetClientListeningFlags(i, VOICE_TEAM);
   201 			}
   202 		}
   203 	}
   204 }
   205 
   206 public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
   207 {
   208 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   209 	
   210 	if (g_Muted[client])
   211 	{
   212 		SetClientListeningFlags(client, VOICE_MUTED);
   213 	}
   214 	else
   215 	{
   216 		SetClientListeningFlags(client, VOICE_NORMAL);
   217 	}
   218 }
   219 
   220 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   221 {
   222 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   223 	
   224 	if (g_Muted[client])
   225 	{
   226 		SetClientListeningFlags(client, VOICE_MUTED);
   227 		return;
   228 	}
   229 	
   230 	if (GetConVarBool(g_Cvar_Alltalk))
   231 	{
   232 		SetClientListeningFlags(client, VOICE_NORMAL);
   233 		return;
   234 	}
   235 	
   236 	new dt_val = GetConVarInt(g_Cvar_Deadtalk);
   237 	if (dt_val == 1)
   238 	{
   239 		SetClientListeningFlags(client, VOICE_LISTENALL);
   240 	}
   241 	else if (dt_val == 2)
   242 	{
   243 		SetClientListeningFlags(client, VOICE_TEAM);
   244 	}
   245 }