plugins/basecomm.sp
changeset 1475 db8868dbae1b
child 1536 fe2146e4975d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basecomm.sp	Wed Sep 26 01:22:25 2007 +0000
     1.3 @@ -0,0 +1,414 @@
     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-2007 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.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 +
    1.40 +#pragma semicolon 1
    1.41 +
    1.42 +public Plugin:myinfo =
    1.43 +{
    1.44 +	name = "Basic Comm Control",
    1.45 +	author = "AlliedModders LLC",
    1.46 +	description = "Provides methods of controllingg communication.",
    1.47 +	version = SOURCEMOD_VERSION,
    1.48 +	url = "http://www.sourcemod.net/"
    1.49 +};
    1.50 +
    1.51 +new bool:g_Muted[MAXPLAYERS+1];		// Is the player muted?
    1.52 +new bool:g_Gagged[MAXPLAYERS+1];	// Is the player gagged?
    1.53 +
    1.54 +new Handle:g_Cvar_Deadtalk = INVALID_HANDLE;	// Holds the handle for sm_deadtalk
    1.55 +new Handle:g_Cvar_Alltalk = INVALID_HANDLE;	// Holds the handle for sv_alltalk
    1.56 +new bool:g_Hooked = false;			// Tracks if we've hooked events for deadtalk
    1.57 +
    1.58 +public OnPluginStart()
    1.59 +{
    1.60 +	LoadTranslations("common.phrases");
    1.61 +	LoadTranslations("basecomm.phrases");
    1.62 +	
    1.63 +	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.64 +	g_Cvar_Alltalk = FindConVar("sv_alltalk");
    1.65 +	
    1.66 +	RegConsoleCmd("say", Command_Say);
    1.67 +	RegConsoleCmd("say_team", Command_Say);
    1.68 +	
    1.69 +	RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute <player> - Removes a player's ability to use voice.");
    1.70 +	RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag <player> - Removes a player's ability to use chat.");
    1.71 +	RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence <player> - Removes a player's ability to use voice or chat.");
    1.72 +	
    1.73 +	RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute <player> - Restores a player's ability to use voice.");
    1.74 +	RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag <player> - Restores a player's ability to use chat.");
    1.75 +	RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence <player> - Restores a player's ability to use voice and chat.");	
    1.76 +	
    1.77 +	HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
    1.78 +}
    1.79 +
    1.80 +public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
    1.81 +{
    1.82 +	if (GetConVarInt(g_Cvar_Deadtalk))
    1.83 +	{
    1.84 +		HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
    1.85 +		HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
    1.86 +		g_Hooked = true;
    1.87 +	}
    1.88 +	else if (g_Hooked)
    1.89 +	{
    1.90 +		UnhookEvent("player_spawn", Event_PlayerSpawn);
    1.91 +		UnhookEvent("player_death", Event_PlayerDeath);		
    1.92 +		g_Hooked = false;
    1.93 +	}
    1.94 +}
    1.95 +
    1.96 +
    1.97 +public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
    1.98 +{
    1.99 +	g_Gagged[client] = false;
   1.100 +	g_Muted[client] = false;
   1.101 +	
   1.102 +	return true;
   1.103 +}
   1.104 +
   1.105 +public Action:Command_Say(client, args)
   1.106 +{
   1.107 +	if (client)
   1.108 +	{
   1.109 +		if (g_Gagged[client])
   1.110 +		{
   1.111 +			return Plugin_Handled;		
   1.112 +		}
   1.113 +	}
   1.114 +	
   1.115 +	return Plugin_Continue;
   1.116 +}
   1.117 +
   1.118 +public Action:Command_Mute(client, args)
   1.119 +{	
   1.120 +	if (args < 1)
   1.121 +	{
   1.122 +		ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
   1.123 +		return Plugin_Handled;
   1.124 +	}
   1.125 +	
   1.126 +	decl String:arg[64];
   1.127 +	GetCmdArg(1, arg, sizeof(arg));
   1.128 +	
   1.129 +	new target = FindTarget(client, arg);
   1.130 +	if (target == -1)
   1.131 +	{
   1.132 +		return Plugin_Handled;
   1.133 +	}
   1.134 +
   1.135 +	if (g_Muted[target])
   1.136 +	{
   1.137 +		ReplyToCommand(client, "%t", "Already Muted");
   1.138 +		return Plugin_Handled;		
   1.139 +	}
   1.140 +		
   1.141 +	g_Muted[target] = true;
   1.142 +	SetClientListeningFlags(target, VOICE_MUTED);
   1.143 +	
   1.144 +	decl String:name[64];
   1.145 +	GetClientName(target, name, sizeof(name));
   1.146 +
   1.147 +	ShowActivity(client, "%t", "Player Muted", name);
   1.148 +	ReplyToCommand(client, "%t", "Player Muted", name);
   1.149 +	LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   1.150 +	
   1.151 +	return Plugin_Handled;	
   1.152 +}
   1.153 +
   1.154 +public Action:Command_Gag(client, args)
   1.155 +{	
   1.156 +	if (args < 1)
   1.157 +	{
   1.158 +		ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
   1.159 +		return Plugin_Handled;
   1.160 +	}
   1.161 +	
   1.162 +	decl String:arg[64];
   1.163 +	GetCmdArg(1, arg, sizeof(arg));
   1.164 +	
   1.165 +	new target = FindTarget(client, arg);
   1.166 +	if (target == -1)
   1.167 +	{
   1.168 +		return Plugin_Handled;
   1.169 +	}
   1.170 +
   1.171 +	if (g_Gagged[target])
   1.172 +	{
   1.173 +		ReplyToCommand(client, "%t", "Already Gagged");
   1.174 +		return Plugin_Handled;		
   1.175 +	}
   1.176 +		
   1.177 +	g_Gagged[target] = true;
   1.178 +	
   1.179 +	decl String:name[64];
   1.180 +	GetClientName(target, name, sizeof(name));
   1.181 +
   1.182 +	ShowActivity(client, "%t", "Player Gagged", name);
   1.183 +	ReplyToCommand(client, "%t", "Player Gagged", name);
   1.184 +	LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   1.185 +	
   1.186 +	return Plugin_Handled;	
   1.187 +}
   1.188 +
   1.189 +public Action:Command_Silence(client, args)
   1.190 +{	
   1.191 +	if (args < 1)
   1.192 +	{
   1.193 +		ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
   1.194 +		return Plugin_Handled;
   1.195 +	}
   1.196 +	
   1.197 +	decl String:arg[64];
   1.198 +	GetCmdArg(1, arg, sizeof(arg));
   1.199 +	
   1.200 +	new target = FindTarget(client, arg);
   1.201 +	if (target == -1)
   1.202 +	{
   1.203 +		return Plugin_Handled;
   1.204 +	}
   1.205 +
   1.206 +	if (g_Gagged[target] && g_Muted[target])
   1.207 +	{
   1.208 +		ReplyToCommand(client, "%t", "Already Silenced");
   1.209 +		return Plugin_Handled;		
   1.210 +	}
   1.211 +
   1.212 +	decl String:name[64];
   1.213 +	GetClientName(target, name, sizeof(name));
   1.214 +	
   1.215 +	if (!g_Gagged[target])
   1.216 +	{
   1.217 +		g_Gagged[target] = true;
   1.218 +
   1.219 +		ShowActivity(client, "%t", "Player Gagged", name);
   1.220 +		ReplyToCommand(client, "%t", "Player Gagged", name);
   1.221 +		LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   1.222 +	}
   1.223 +	
   1.224 +	if (!g_Muted[target])
   1.225 +	{
   1.226 +		g_Muted[target] = true;
   1.227 +		SetClientListeningFlags(target, VOICE_MUTED);
   1.228 +	
   1.229 +		ShowActivity(client, "%t", "Player Muted", name);
   1.230 +		ReplyToCommand(client, "%t", "Player Muted", name);
   1.231 +		LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   1.232 +	}
   1.233 +	
   1.234 +	return Plugin_Handled;	
   1.235 +}
   1.236 +
   1.237 +public Action:Command_Unmute(client, args)
   1.238 +{	
   1.239 +	if (args < 1)
   1.240 +	{
   1.241 +		ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
   1.242 +		return Plugin_Handled;
   1.243 +	}
   1.244 +	
   1.245 +	decl String:arg[64];
   1.246 +	GetCmdArg(1, arg, sizeof(arg));
   1.247 +	
   1.248 +	new target = FindTarget(client, arg);
   1.249 +	if (target == -1)
   1.250 +	{
   1.251 +		return Plugin_Handled;
   1.252 +	}
   1.253 +
   1.254 +	if (!g_Muted[target])
   1.255 +	{
   1.256 +		ReplyToCommand(client, "%t", "Player Not Muted");
   1.257 +		return Plugin_Handled;		
   1.258 +	}
   1.259 +		
   1.260 +	g_Muted[target] = false;
   1.261 +	if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   1.262 +	{
   1.263 +		SetClientListeningFlags(target, VOICE_LISTENALL);
   1.264 +	}
   1.265 +	else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   1.266 +	{
   1.267 +		SetClientListeningFlags(target, VOICE_TEAM);
   1.268 +	}
   1.269 +	else
   1.270 +	{
   1.271 +		SetClientListeningFlags(target, VOICE_NORMAL);
   1.272 +	}
   1.273 +	
   1.274 +	decl String:name[64];
   1.275 +	GetClientName(target, name, sizeof(name));
   1.276 +
   1.277 +	ShowActivity(client, "%t", "Player Unmuted", name);
   1.278 +	ReplyToCommand(client, "%t", "Player Unmuted", name);
   1.279 +	LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
   1.280 +	
   1.281 +	return Plugin_Handled;	
   1.282 +}
   1.283 +
   1.284 +public Action:Command_Ungag(client, args)
   1.285 +{	
   1.286 +	if (args < 1)
   1.287 +	{
   1.288 +		ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
   1.289 +		return Plugin_Handled;
   1.290 +	}
   1.291 +	
   1.292 +	decl String:arg[64];
   1.293 +	GetCmdArg(1, arg, sizeof(arg));
   1.294 +	
   1.295 +	new target = FindTarget(client, arg);
   1.296 +	if (target == -1)
   1.297 +	{
   1.298 +		return Plugin_Handled;
   1.299 +	}
   1.300 +
   1.301 +	if (!g_Gagged[target])
   1.302 +	{
   1.303 +		ReplyToCommand(client, "%t", "Player Not Gagged");
   1.304 +		return Plugin_Handled;		
   1.305 +	}
   1.306 +		
   1.307 +	g_Gagged[target] = false;
   1.308 +	
   1.309 +	decl String:name[64];
   1.310 +	GetClientName(target, name, sizeof(name));
   1.311 +
   1.312 +	ShowActivity(client, "%t", "Player Ungagged", name);
   1.313 +	ReplyToCommand(client, "%t", "Player Ungagged", name);
   1.314 +	LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   1.315 +	
   1.316 +	return Plugin_Handled;	
   1.317 +}
   1.318 +
   1.319 +public Action:Command_Unsilence(client, args)
   1.320 +{	
   1.321 +	if (args < 1)
   1.322 +	{
   1.323 +		ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
   1.324 +		return Plugin_Handled;
   1.325 +	}
   1.326 +	
   1.327 +	decl String:arg[64];
   1.328 +	GetCmdArg(1, arg, sizeof(arg));
   1.329 +	
   1.330 +	new target = FindTarget(client, arg);
   1.331 +	if (target == -1)
   1.332 +	{
   1.333 +		return Plugin_Handled;
   1.334 +	}
   1.335 +
   1.336 +	if (!g_Gagged[target] && !g_Muted[target])
   1.337 +	{
   1.338 +		ReplyToCommand(client, "%t", "Player Not Silenced");
   1.339 +		return Plugin_Handled;		
   1.340 +	}
   1.341 +	
   1.342 +	decl String:name[64];
   1.343 +	GetClientName(target, name, sizeof(name));
   1.344 +	
   1.345 +	if (g_Gagged[target])
   1.346 +	{
   1.347 +		g_Gagged[target] = false;
   1.348 +		
   1.349 +		ShowActivity(client, "%t", "Player Ungagged", name);
   1.350 +		ReplyToCommand(client, "%t", "Player Ungagged", name);	
   1.351 +		LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   1.352 +	}
   1.353 +	
   1.354 +	if (g_Muted[target])
   1.355 +	{
   1.356 +		g_Muted[target] = false;
   1.357 +		
   1.358 +		if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   1.359 +		{
   1.360 +			SetClientListeningFlags(target, VOICE_LISTENALL);
   1.361 +		}
   1.362 +		else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   1.363 +		{
   1.364 +			SetClientListeningFlags(target, VOICE_TEAM);
   1.365 +		}
   1.366 +		else
   1.367 +		{
   1.368 +			SetClientListeningFlags(target, VOICE_NORMAL);
   1.369 +		}
   1.370 +		
   1.371 +		ShowActivity(client, "%t", "Player Unmuted", name);
   1.372 +		ReplyToCommand(client, "%t", "Player Unmuted", name);
   1.373 +		LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);		
   1.374 +	}
   1.375 +	
   1.376 +	return Plugin_Handled;	
   1.377 +}
   1.378 +
   1.379 +public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
   1.380 +{
   1.381 +	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   1.382 +	
   1.383 +	if (g_Muted[client])
   1.384 +	{
   1.385 +		SetClientListeningFlags(client, VOICE_MUTED);
   1.386 +	}
   1.387 +	else
   1.388 +	{
   1.389 +		SetClientListeningFlags(client, VOICE_NORMAL);
   1.390 +	}
   1.391 +}
   1.392 +
   1.393 +public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   1.394 +{
   1.395 +	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   1.396 +	
   1.397 +	if (g_Muted[client])
   1.398 +	{
   1.399 +		SetClientListeningFlags(client, VOICE_MUTED);
   1.400 +		return;
   1.401 +	}
   1.402 +	
   1.403 +	if (GetConVarBool(g_Cvar_Alltalk))
   1.404 +	{
   1.405 +		SetClientListeningFlags(client, VOICE_NORMAL);
   1.406 +		return;
   1.407 +	}
   1.408 +	
   1.409 +	if (GetConVarInt(g_Cvar_Deadtalk) == 1)
   1.410 +	{
   1.411 +		SetClientListeningFlags(client, VOICE_LISTENALL);
   1.412 +	}
   1.413 +	else if (GetConVarInt(g_Cvar_Deadtalk) == 2)
   1.414 +	{
   1.415 +		SetClientListeningFlags(client, VOICE_TEAM);
   1.416 +	}
   1.417 +}
   1.418 \ No newline at end of file