3 * =============================================================================
4 * SourceMod Communication Plugin
5 * Provides fucntionality for controlling communication on the server
7 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
8 * =============================================================================
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.
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
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/>.
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>.
39 public Plugin:myinfo =
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/"
48 new bool:g_Muted[MAXPLAYERS+1]; // Is the player muted?
49 new bool:g_Gagged[MAXPLAYERS+1]; // Is the player gagged?
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
55 public OnPluginStart()
57 LoadTranslations("common.phrases");
58 LoadTranslations("basecomm.phrases");
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");
63 RegConsoleCmd("say", Command_Say);
64 RegConsoleCmd("say_team", Command_Say);
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.");
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.");
74 HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
77 public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
79 if (GetConVarInt(g_Cvar_Deadtalk))
81 HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
82 HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
87 UnhookEvent("player_spawn", Event_PlayerSpawn);
88 UnhookEvent("player_death", Event_PlayerDeath);
94 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
96 g_Gagged[client] = false;
97 g_Muted[client] = false;
102 public Action:Command_Say(client, args)
106 if (g_Gagged[client])
108 return Plugin_Handled;
112 return Plugin_Continue;
115 public Action:Command_Mute(client, args)
119 ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
120 return Plugin_Handled;
124 GetCmdArg(1, arg, sizeof(arg));
126 new target = FindTarget(client, arg);
129 return Plugin_Handled;
134 ReplyToCommand(client, "%t", "Already Muted");
135 return Plugin_Handled;
138 g_Muted[target] = true;
139 SetClientListeningFlags(target, VOICE_MUTED);
141 decl String:name[64];
142 GetClientName(target, name, sizeof(name));
144 ShowActivity(client, "%t", "Player Muted", name);
145 ReplyToCommand(client, "%t", "Player Muted", name);
146 LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
148 return Plugin_Handled;
151 public Action:Command_Gag(client, args)
155 ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
156 return Plugin_Handled;
160 GetCmdArg(1, arg, sizeof(arg));
162 new target = FindTarget(client, arg);
165 return Plugin_Handled;
168 if (g_Gagged[target])
170 ReplyToCommand(client, "%t", "Already Gagged");
171 return Plugin_Handled;
174 g_Gagged[target] = true;
176 decl String:name[64];
177 GetClientName(target, name, sizeof(name));
179 ShowActivity(client, "%t", "Player Gagged", name);
180 ReplyToCommand(client, "%t", "Player Gagged", name);
181 LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
183 return Plugin_Handled;
186 public Action:Command_Silence(client, args)
190 ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
191 return Plugin_Handled;
195 GetCmdArg(1, arg, sizeof(arg));
197 new target = FindTarget(client, arg);
200 return Plugin_Handled;
203 if (g_Gagged[target] && g_Muted[target])
205 ReplyToCommand(client, "%t", "Already Silenced");
206 return Plugin_Handled;
209 decl String:name[64];
210 GetClientName(target, name, sizeof(name));
212 if (!g_Gagged[target])
214 g_Gagged[target] = true;
216 ShowActivity(client, "%t", "Player Gagged", name);
217 ReplyToCommand(client, "%t", "Player Gagged", name);
218 LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
221 if (!g_Muted[target])
223 g_Muted[target] = true;
224 SetClientListeningFlags(target, VOICE_MUTED);
226 ShowActivity(client, "%t", "Player Muted", name);
227 ReplyToCommand(client, "%t", "Player Muted", name);
228 LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
231 return Plugin_Handled;
234 public Action:Command_Unmute(client, args)
238 ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
239 return Plugin_Handled;
243 GetCmdArg(1, arg, sizeof(arg));
245 new target = FindTarget(client, arg);
248 return Plugin_Handled;
251 if (!g_Muted[target])
253 ReplyToCommand(client, "%t", "Player Not Muted");
254 return Plugin_Handled;
257 g_Muted[target] = false;
258 if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
260 SetClientListeningFlags(target, VOICE_LISTENALL);
262 else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
264 SetClientListeningFlags(target, VOICE_TEAM);
268 SetClientListeningFlags(target, VOICE_NORMAL);
271 decl String:name[64];
272 GetClientName(target, name, sizeof(name));
274 ShowActivity(client, "%t", "Player Unmuted", name);
275 ReplyToCommand(client, "%t", "Player Unmuted", name);
276 LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
278 return Plugin_Handled;
281 public Action:Command_Ungag(client, args)
285 ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
286 return Plugin_Handled;
290 GetCmdArg(1, arg, sizeof(arg));
292 new target = FindTarget(client, arg);
295 return Plugin_Handled;
298 if (!g_Gagged[target])
300 ReplyToCommand(client, "%t", "Player Not Gagged");
301 return Plugin_Handled;
304 g_Gagged[target] = false;
306 decl String:name[64];
307 GetClientName(target, name, sizeof(name));
309 ShowActivity(client, "%t", "Player Ungagged", name);
310 ReplyToCommand(client, "%t", "Player Ungagged", name);
311 LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
313 return Plugin_Handled;
316 public Action:Command_Unsilence(client, args)
320 ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
321 return Plugin_Handled;
325 GetCmdArg(1, arg, sizeof(arg));
327 new target = FindTarget(client, arg);
330 return Plugin_Handled;
333 if (!g_Gagged[target] && !g_Muted[target])
335 ReplyToCommand(client, "%t", "Player Not Silenced");
336 return Plugin_Handled;
339 decl String:name[64];
340 GetClientName(target, name, sizeof(name));
342 if (g_Gagged[target])
344 g_Gagged[target] = false;
346 ShowActivity(client, "%t", "Player Ungagged", name);
347 ReplyToCommand(client, "%t", "Player Ungagged", name);
348 LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
353 g_Muted[target] = false;
355 if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
357 SetClientListeningFlags(target, VOICE_LISTENALL);
359 else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
361 SetClientListeningFlags(target, VOICE_TEAM);
365 SetClientListeningFlags(target, VOICE_NORMAL);
368 ShowActivity(client, "%t", "Player Unmuted", name);
369 ReplyToCommand(client, "%t", "Player Unmuted", name);
370 LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
373 return Plugin_Handled;
376 public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
378 new client = GetClientOfUserId(GetEventInt(event, "userid"));
382 SetClientListeningFlags(client, VOICE_MUTED);
386 SetClientListeningFlags(client, VOICE_NORMAL);
390 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
392 new client = GetClientOfUserId(GetEventInt(event, "userid"));
396 SetClientListeningFlags(client, VOICE_MUTED);
400 if (GetConVarBool(g_Cvar_Alltalk))
402 SetClientListeningFlags(client, VOICE_NORMAL);
406 if (GetConVarInt(g_Cvar_Deadtalk) == 1)
408 SetClientListeningFlags(client, VOICE_LISTENALL);
410 else if (GetConVarInt(g_Cvar_Deadtalk) == 2)
412 SetClientListeningFlags(client, VOICE_TEAM);