plugins/basecomm.sp
author Borja Ferrer <faluco@alliedmods.net>
Sat Sep 29 22:26:36 2007 +0000 (2007-09-29)
changeset 1504 312c2e8934b1
parent 1475 db8868dbae1b
child 1536 fe2146e4975d
permissions -rw-r--r--
added amb964, DispatchKeyValue natives
     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  * 
    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 
    37 #pragma semicolon 1
    38 
    39 public Plugin:myinfo =
    40 {
    41 	name = "Basic Comm Control",
    42 	author = "AlliedModders LLC",
    43 	description = "Provides methods of controllingg communication.",
    44 	version = SOURCEMOD_VERSION,
    45 	url = "http://www.sourcemod.net/"
    46 };
    47 
    48 new bool:g_Muted[MAXPLAYERS+1];		// Is the player muted?
    49 new bool:g_Gagged[MAXPLAYERS+1];	// Is the player gagged?
    50 
    51 new Handle:g_Cvar_Deadtalk = INVALID_HANDLE;	// Holds the handle for sm_deadtalk
    52 new Handle:g_Cvar_Alltalk = INVALID_HANDLE;	// Holds the handle for sv_alltalk
    53 new bool:g_Hooked = false;			// Tracks if we've hooked events for deadtalk
    54 
    55 public OnPluginStart()
    56 {
    57 	LoadTranslations("common.phrases");
    58 	LoadTranslations("basecomm.phrases");
    59 	
    60 	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);
    61 	g_Cvar_Alltalk = FindConVar("sv_alltalk");
    62 	
    63 	RegConsoleCmd("say", Command_Say);
    64 	RegConsoleCmd("say_team", Command_Say);
    65 	
    66 	RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute <player> - Removes a player's ability to use voice.");
    67 	RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag <player> - Removes a player's ability to use chat.");
    68 	RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence <player> - Removes a player's ability to use voice or chat.");
    69 	
    70 	RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute <player> - Restores a player's ability to use voice.");
    71 	RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag <player> - Restores a player's ability to use chat.");
    72 	RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence <player> - Restores a player's ability to use voice and chat.");	
    73 	
    74 	HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
    75 }
    76 
    77 public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
    78 {
    79 	if (GetConVarInt(g_Cvar_Deadtalk))
    80 	{
    81 		HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
    82 		HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
    83 		g_Hooked = true;
    84 	}
    85 	else if (g_Hooked)
    86 	{
    87 		UnhookEvent("player_spawn", Event_PlayerSpawn);
    88 		UnhookEvent("player_death", Event_PlayerDeath);		
    89 		g_Hooked = false;
    90 	}
    91 }
    92 
    93 
    94 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
    95 {
    96 	g_Gagged[client] = false;
    97 	g_Muted[client] = false;
    98 	
    99 	return true;
   100 }
   101 
   102 public Action:Command_Say(client, args)
   103 {
   104 	if (client)
   105 	{
   106 		if (g_Gagged[client])
   107 		{
   108 			return Plugin_Handled;		
   109 		}
   110 	}
   111 	
   112 	return Plugin_Continue;
   113 }
   114 
   115 public Action:Command_Mute(client, args)
   116 {	
   117 	if (args < 1)
   118 	{
   119 		ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
   120 		return Plugin_Handled;
   121 	}
   122 	
   123 	decl String:arg[64];
   124 	GetCmdArg(1, arg, sizeof(arg));
   125 	
   126 	new target = FindTarget(client, arg);
   127 	if (target == -1)
   128 	{
   129 		return Plugin_Handled;
   130 	}
   131 
   132 	if (g_Muted[target])
   133 	{
   134 		ReplyToCommand(client, "%t", "Already Muted");
   135 		return Plugin_Handled;		
   136 	}
   137 		
   138 	g_Muted[target] = true;
   139 	SetClientListeningFlags(target, VOICE_MUTED);
   140 	
   141 	decl String:name[64];
   142 	GetClientName(target, name, sizeof(name));
   143 
   144 	ShowActivity(client, "%t", "Player Muted", name);
   145 	ReplyToCommand(client, "%t", "Player Muted", name);
   146 	LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   147 	
   148 	return Plugin_Handled;	
   149 }
   150 
   151 public Action:Command_Gag(client, args)
   152 {	
   153 	if (args < 1)
   154 	{
   155 		ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
   156 		return Plugin_Handled;
   157 	}
   158 	
   159 	decl String:arg[64];
   160 	GetCmdArg(1, arg, sizeof(arg));
   161 	
   162 	new target = FindTarget(client, arg);
   163 	if (target == -1)
   164 	{
   165 		return Plugin_Handled;
   166 	}
   167 
   168 	if (g_Gagged[target])
   169 	{
   170 		ReplyToCommand(client, "%t", "Already Gagged");
   171 		return Plugin_Handled;		
   172 	}
   173 		
   174 	g_Gagged[target] = true;
   175 	
   176 	decl String:name[64];
   177 	GetClientName(target, name, sizeof(name));
   178 
   179 	ShowActivity(client, "%t", "Player Gagged", name);
   180 	ReplyToCommand(client, "%t", "Player Gagged", name);
   181 	LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   182 	
   183 	return Plugin_Handled;	
   184 }
   185 
   186 public Action:Command_Silence(client, args)
   187 {	
   188 	if (args < 1)
   189 	{
   190 		ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
   191 		return Plugin_Handled;
   192 	}
   193 	
   194 	decl String:arg[64];
   195 	GetCmdArg(1, arg, sizeof(arg));
   196 	
   197 	new target = FindTarget(client, arg);
   198 	if (target == -1)
   199 	{
   200 		return Plugin_Handled;
   201 	}
   202 
   203 	if (g_Gagged[target] && g_Muted[target])
   204 	{
   205 		ReplyToCommand(client, "%t", "Already Silenced");
   206 		return Plugin_Handled;		
   207 	}
   208 
   209 	decl String:name[64];
   210 	GetClientName(target, name, sizeof(name));
   211 	
   212 	if (!g_Gagged[target])
   213 	{
   214 		g_Gagged[target] = true;
   215 
   216 		ShowActivity(client, "%t", "Player Gagged", name);
   217 		ReplyToCommand(client, "%t", "Player Gagged", name);
   218 		LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   219 	}
   220 	
   221 	if (!g_Muted[target])
   222 	{
   223 		g_Muted[target] = true;
   224 		SetClientListeningFlags(target, VOICE_MUTED);
   225 	
   226 		ShowActivity(client, "%t", "Player Muted", name);
   227 		ReplyToCommand(client, "%t", "Player Muted", name);
   228 		LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   229 	}
   230 	
   231 	return Plugin_Handled;	
   232 }
   233 
   234 public Action:Command_Unmute(client, args)
   235 {	
   236 	if (args < 1)
   237 	{
   238 		ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
   239 		return Plugin_Handled;
   240 	}
   241 	
   242 	decl String:arg[64];
   243 	GetCmdArg(1, arg, sizeof(arg));
   244 	
   245 	new target = FindTarget(client, arg);
   246 	if (target == -1)
   247 	{
   248 		return Plugin_Handled;
   249 	}
   250 
   251 	if (!g_Muted[target])
   252 	{
   253 		ReplyToCommand(client, "%t", "Player Not Muted");
   254 		return Plugin_Handled;		
   255 	}
   256 		
   257 	g_Muted[target] = false;
   258 	if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   259 	{
   260 		SetClientListeningFlags(target, VOICE_LISTENALL);
   261 	}
   262 	else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   263 	{
   264 		SetClientListeningFlags(target, VOICE_TEAM);
   265 	}
   266 	else
   267 	{
   268 		SetClientListeningFlags(target, VOICE_NORMAL);
   269 	}
   270 	
   271 	decl String:name[64];
   272 	GetClientName(target, name, sizeof(name));
   273 
   274 	ShowActivity(client, "%t", "Player Unmuted", name);
   275 	ReplyToCommand(client, "%t", "Player Unmuted", name);
   276 	LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
   277 	
   278 	return Plugin_Handled;	
   279 }
   280 
   281 public Action:Command_Ungag(client, args)
   282 {	
   283 	if (args < 1)
   284 	{
   285 		ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
   286 		return Plugin_Handled;
   287 	}
   288 	
   289 	decl String:arg[64];
   290 	GetCmdArg(1, arg, sizeof(arg));
   291 	
   292 	new target = FindTarget(client, arg);
   293 	if (target == -1)
   294 	{
   295 		return Plugin_Handled;
   296 	}
   297 
   298 	if (!g_Gagged[target])
   299 	{
   300 		ReplyToCommand(client, "%t", "Player Not Gagged");
   301 		return Plugin_Handled;		
   302 	}
   303 		
   304 	g_Gagged[target] = false;
   305 	
   306 	decl String:name[64];
   307 	GetClientName(target, name, sizeof(name));
   308 
   309 	ShowActivity(client, "%t", "Player Ungagged", name);
   310 	ReplyToCommand(client, "%t", "Player Ungagged", name);
   311 	LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   312 	
   313 	return Plugin_Handled;	
   314 }
   315 
   316 public Action:Command_Unsilence(client, args)
   317 {	
   318 	if (args < 1)
   319 	{
   320 		ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
   321 		return Plugin_Handled;
   322 	}
   323 	
   324 	decl String:arg[64];
   325 	GetCmdArg(1, arg, sizeof(arg));
   326 	
   327 	new target = FindTarget(client, arg);
   328 	if (target == -1)
   329 	{
   330 		return Plugin_Handled;
   331 	}
   332 
   333 	if (!g_Gagged[target] && !g_Muted[target])
   334 	{
   335 		ReplyToCommand(client, "%t", "Player Not Silenced");
   336 		return Plugin_Handled;		
   337 	}
   338 	
   339 	decl String:name[64];
   340 	GetClientName(target, name, sizeof(name));
   341 	
   342 	if (g_Gagged[target])
   343 	{
   344 		g_Gagged[target] = false;
   345 		
   346 		ShowActivity(client, "%t", "Player Ungagged", name);
   347 		ReplyToCommand(client, "%t", "Player Ungagged", name);	
   348 		LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   349 	}
   350 	
   351 	if (g_Muted[target])
   352 	{
   353 		g_Muted[target] = false;
   354 		
   355 		if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   356 		{
   357 			SetClientListeningFlags(target, VOICE_LISTENALL);
   358 		}
   359 		else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   360 		{
   361 			SetClientListeningFlags(target, VOICE_TEAM);
   362 		}
   363 		else
   364 		{
   365 			SetClientListeningFlags(target, VOICE_NORMAL);
   366 		}
   367 		
   368 		ShowActivity(client, "%t", "Player Unmuted", name);
   369 		ReplyToCommand(client, "%t", "Player Unmuted", name);
   370 		LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);		
   371 	}
   372 	
   373 	return Plugin_Handled;	
   374 }
   375 
   376 public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
   377 {
   378 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   379 	
   380 	if (g_Muted[client])
   381 	{
   382 		SetClientListeningFlags(client, VOICE_MUTED);
   383 	}
   384 	else
   385 	{
   386 		SetClientListeningFlags(client, VOICE_NORMAL);
   387 	}
   388 }
   389 
   390 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   391 {
   392 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   393 	
   394 	if (g_Muted[client])
   395 	{
   396 		SetClientListeningFlags(client, VOICE_MUTED);
   397 		return;
   398 	}
   399 	
   400 	if (GetConVarBool(g_Cvar_Alltalk))
   401 	{
   402 		SetClientListeningFlags(client, VOICE_NORMAL);
   403 		return;
   404 	}
   405 	
   406 	if (GetConVarInt(g_Cvar_Deadtalk) == 1)
   407 	{
   408 		SetClientListeningFlags(client, VOICE_LISTENALL);
   409 	}
   410 	else if (GetConVarInt(g_Cvar_Deadtalk) == 2)
   411 	{
   412 		SetClientListeningFlags(client, VOICE_TEAM);
   413 	}
   414 }