plugins/basecomm/gag.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3887 3e8a8d9903ce
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basecomm
     5  * Part of Basecomm plugin, menu and other functionality.
     6  *
     7  * SourceMod (C)2004-2008 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 enum CommType
    35 {
    36 	CommType_Mute,
    37 	CommType_UnMute,
    38 	CommType_Gag,
    39 	CommType_UnGag,
    40 	CommType_Silence,
    41 	CommType_UnSilence
    42 };
    43 
    44 DisplayGagTypesMenu(client)
    45 {
    46 	new Handle:menu = CreateMenu(MenuHandler_GagTypes);
    47 	
    48 	decl String:title[100];
    49 	Format(title, sizeof(title), "%T: %N", "Choose Type", client, g_GagTarget[client]);
    50 	SetMenuTitle(menu, title);
    51 	SetMenuExitBackButton(menu, true);
    52 	
    53 	new target = g_GagTarget[client];
    54 	
    55 	if (!g_Muted[target])
    56 	{
    57 		AddTranslatedMenuItem(menu, "0", "Mute Player", client);
    58 	}
    59 	else
    60 	{
    61 		AddTranslatedMenuItem(menu, "1", "UnMute Player", client);
    62 	}
    63 	
    64 	if (!g_Gagged[target])
    65 	{
    66 		AddTranslatedMenuItem(menu, "2", "Gag Player", client);
    67 	}
    68 	else
    69 	{
    70 		AddTranslatedMenuItem(menu, "3", "UnGag Player", client);
    71 	}
    72 	
    73 	if (!g_Muted[target] || !g_Gagged[target])
    74 	{
    75 		AddTranslatedMenuItem(menu, "4", "Silence Player", client);
    76 	}
    77 	else
    78 	{
    79 		AddTranslatedMenuItem(menu, "5", "UnSilence Player", client);
    80 	}
    81 		
    82 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    83 }
    84 
    85 AddTranslatedMenuItem(Handle:menu, const String:opt[], const String:phrase[], client)
    86 {
    87 	decl String:buffer[128];
    88 	Format(buffer, sizeof(buffer), "%T", phrase, client);
    89 	AddMenuItem(menu, opt, buffer);
    90 }
    91 
    92 DisplayGagPlayerMenu(client)
    93 {
    94 	new Handle:menu = CreateMenu(MenuHandler_GagPlayer);
    95 	
    96 	decl String:title[100];
    97 	Format(title, sizeof(title), "%T:", "Gag/Mute player", client);
    98 	SetMenuTitle(menu, title);
    99 	SetMenuExitBackButton(menu, true);
   100 	
   101 	AddTargetsToMenu(menu, client, true, false);
   102 	
   103 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   104 }
   105 
   106 public AdminMenu_Gag(Handle:topmenu, 
   107 					  TopMenuAction:action,
   108 					  TopMenuObject:object_id,
   109 					  param,
   110 					  String:buffer[],
   111 					  maxlength)
   112 {
   113 	if (action == TopMenuAction_DisplayOption)
   114 	{
   115 		Format(buffer, maxlength, "%T", "Gag/Mute player", param);
   116 	}
   117 	else if (action == TopMenuAction_SelectOption)
   118 	{
   119 		DisplayGagPlayerMenu(param);
   120 	}
   121 }
   122 
   123 public MenuHandler_GagPlayer(Handle:menu, MenuAction:action, param1, param2)
   124 {
   125 	if (action == MenuAction_End)
   126 	{
   127 		CloseHandle(menu);
   128 	}
   129 	else if (action == MenuAction_Cancel)
   130 	{
   131 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   132 		{
   133 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   134 		}
   135 	}
   136 	else if (action == MenuAction_Select)
   137 	{
   138 		decl String:info[32];
   139 		new userid, target;
   140 		
   141 		GetMenuItem(menu, param2, info, sizeof(info));
   142 		userid = StringToInt(info);
   143 
   144 		if ((target = GetClientOfUserId(userid)) == 0)
   145 		{
   146 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   147 		}
   148 		else if (!CanUserTarget(param1, target))
   149 		{
   150 			PrintToChat(param1, "[SM] %t", "Unable to target");
   151 		}
   152 		else
   153 		{
   154 			g_GagTarget[param1] = GetClientOfUserId(userid);
   155 			DisplayGagTypesMenu(param1);
   156 		}
   157 	}
   158 }
   159 
   160 public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2)
   161 {
   162 	if (action == MenuAction_End)
   163 	{
   164 		CloseHandle(menu);
   165 	}
   166 	else if (action == MenuAction_Cancel)
   167 	{
   168 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   169 		{
   170 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   171 		}
   172 	}
   173 	else if (action == MenuAction_Select)
   174 	{
   175 		decl String:info[32];
   176 		new CommType:type;
   177 		
   178 		GetMenuItem(menu, param2, info, sizeof(info));
   179 		type = CommType:StringToInt(info);
   180 		
   181 		decl String:name[MAX_NAME_LENGTH];
   182 		GetClientName(g_GagTarget[param1], name, sizeof(name));
   183 
   184 		switch (type)
   185 		{
   186 			case CommType_Mute:
   187 			{
   188 				PerformMute(param1, g_GagTarget[param1]);
   189 				ShowActivity2(param1, "[SM] ", "%t", "Muted target", "_s", name);
   190 			}
   191 			case CommType_UnMute:
   192 			{
   193 				PerformUnMute(param1, g_GagTarget[param1]);
   194 				ShowActivity2(param1, "[SM] ", "%t", "Unmuted target", "_s", name);
   195 			}
   196 			case CommType_Gag:
   197 			{
   198 				PerformGag(param1, g_GagTarget[param1]);
   199 				ShowActivity2(param1, "[SM] ", "%t", "Gagged target", "_s", name);
   200 			}
   201 			case CommType_UnGag:
   202 			{
   203 				PerformUnGag(param1, g_GagTarget[param1]);
   204 				ShowActivity2(param1, "[SM] ", "%t", "Ungagged target", "_s", name);
   205 			}
   206 			case CommType_Silence:
   207 			{
   208 				PerformSilence(param1, g_GagTarget[param1]);
   209 				ShowActivity2(param1, "[SM] ", "%t", "Silenced target", "_s", name);
   210 			}
   211 			case CommType_UnSilence:
   212 			{
   213 				PerformUnSilence(param1, g_GagTarget[param1]);
   214 				ShowActivity2(param1, "[SM] ", "%t", "Unsilenced target", "_s", name);
   215 			}
   216 		}
   217 	}
   218 }
   219 
   220 PerformMute(client, target, bool:silent=false)
   221 {
   222 	g_Muted[target] = true;
   223 	SetClientListeningFlags(target, VOICE_MUTED);
   224 	
   225 	FireOnClientMute(target, true);
   226 	
   227 	if (!silent)
   228 	{
   229 		LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   230 	}
   231 }
   232 
   233 PerformUnMute(client, target, bool:silent=false)
   234 {
   235 	g_Muted[target] = false;
   236 	if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   237 	{
   238 		SetClientListeningFlags(target, VOICE_LISTENALL);
   239 	}
   240 	else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   241 	{
   242 		SetClientListeningFlags(target, VOICE_TEAM);
   243 	}
   244 	else
   245 	{
   246 		SetClientListeningFlags(target, VOICE_NORMAL);
   247 	}
   248 	
   249 	FireOnClientMute(target, false);
   250 	
   251 	if (!silent)
   252 	{
   253 		LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
   254 	}
   255 }
   256 
   257 PerformGag(client, target, bool:silent=false)
   258 {
   259 	g_Gagged[target] = true;
   260 	FireOnClientGag(target, true);
   261 	
   262 	if (!silent)
   263 	{
   264 		LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   265 	}
   266 }
   267 
   268 PerformUnGag(client, target, bool:silent=false)
   269 {
   270 	g_Gagged[target] = false;
   271 	FireOnClientGag(target, false);
   272 	
   273 	if (!silent)
   274 	{
   275 		LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   276 	}
   277 }
   278 
   279 PerformSilence(client, target)
   280 {
   281 	if (!g_Gagged[target])
   282 	{
   283 		g_Gagged[target] = true;
   284 		FireOnClientGag(target, true);
   285 	}
   286 	
   287 	if (!g_Muted[target])
   288 	{
   289 		g_Muted[target] = true;
   290 		SetClientListeningFlags(target, VOICE_MUTED);
   291 		FireOnClientMute(target, true);
   292 	}
   293 	
   294 	LogAction(client, target, "\"%L\" silenced \"%L\"", client, target);
   295 }
   296 
   297 PerformUnSilence(client, target)
   298 {
   299 	if (g_Gagged[target])
   300 	{
   301 		g_Gagged[target] = false;
   302 		FireOnClientGag(target, false);
   303 	}
   304 	
   305 	if (g_Muted[target])
   306 	{
   307 		g_Muted[target] = false;
   308 		
   309 		if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   310 		{
   311 			SetClientListeningFlags(target, VOICE_LISTENALL);
   312 		}
   313 		else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   314 		{
   315 			SetClientListeningFlags(target, VOICE_TEAM);
   316 		}
   317 		else
   318 		{
   319 			SetClientListeningFlags(target, VOICE_NORMAL);
   320 		}
   321 		FireOnClientMute(target, false);
   322 	}
   323 	
   324 	LogAction(client, target, "\"%L\" unsilenced \"%L\"", client, target);
   325 }
   326 
   327 public Action:Command_Mute(client, args)
   328 {	
   329 	if (args < 1)
   330 	{
   331 		ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
   332 		return Plugin_Handled;
   333 	}
   334 	
   335 	decl String:arg[64];
   336 	GetCmdArg(1, arg, sizeof(arg));
   337 	
   338 	decl String:target_name[MAX_TARGET_LENGTH];
   339 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   340 	
   341 	if ((target_count = ProcessTargetString(
   342 			arg,
   343 			client, 
   344 			target_list, 
   345 			MAXPLAYERS, 
   346 			0,
   347 			target_name,
   348 			sizeof(target_name),
   349 			tn_is_ml)) <= 0)
   350 	{
   351 		ReplyToTargetError(client, target_count);
   352 		return Plugin_Handled;
   353 	}
   354 
   355 	for (new i = 0; i < target_count; i++)
   356 	{
   357 		new target = target_list[i];
   358 		
   359 		PerformMute(client, target);
   360 	}
   361 	
   362 	if (tn_is_ml)
   363 	{
   364 		ShowActivity2(client, "[SM] ", "%t", "Muted target", target_name);
   365 	}
   366 	else
   367 	{
   368 		ShowActivity2(client, "[SM] ", "%t", "Muted target", "_s", target_name);
   369 	}
   370 	
   371 	return Plugin_Handled;	
   372 }
   373 
   374 public Action:Command_Gag(client, args)
   375 {	
   376 	if (args < 1)
   377 	{
   378 		ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
   379 		return Plugin_Handled;
   380 	}
   381 	
   382 	decl String:arg[64];
   383 	GetCmdArg(1, arg, sizeof(arg));
   384 	
   385 	decl String:target_name[MAX_TARGET_LENGTH];
   386 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   387 	
   388 	if ((target_count = ProcessTargetString(
   389 			arg,
   390 			client, 
   391 			target_list, 
   392 			MAXPLAYERS, 
   393 			0,
   394 			target_name,
   395 			sizeof(target_name),
   396 			tn_is_ml)) <= 0)
   397 	{
   398 		ReplyToTargetError(client, target_count);
   399 		return Plugin_Handled;
   400 	}
   401 
   402 	for (new i = 0; i < target_count; i++)
   403 	{
   404 		new target = target_list[i];
   405 		
   406 		PerformGag(client, target);
   407 	}
   408 	
   409 	if (tn_is_ml)
   410 	{
   411 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", target_name);
   412 	}
   413 	else
   414 	{
   415 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", "_s", target_name);
   416 	}
   417 	
   418 	return Plugin_Handled;	
   419 }
   420 
   421 public Action:Command_Silence(client, args)
   422 {	
   423 	if (args < 1)
   424 	{
   425 		ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
   426 		return Plugin_Handled;
   427 	}
   428 	
   429 	decl String:arg[64];
   430 	GetCmdArg(1, arg, sizeof(arg));
   431 	
   432 	decl String:target_name[MAX_TARGET_LENGTH];
   433 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   434 	
   435 	if ((target_count = ProcessTargetString(
   436 			arg,
   437 			client, 
   438 			target_list, 
   439 			MAXPLAYERS, 
   440 			0,
   441 			target_name,
   442 			sizeof(target_name),
   443 			tn_is_ml)) <= 0)
   444 	{
   445 		ReplyToTargetError(client, target_count);
   446 		return Plugin_Handled;
   447 	}
   448 
   449 	for (new i = 0; i < target_count; i++)
   450 	{
   451 		new target = target_list[i];
   452 		
   453 		PerformSilence(client, target);
   454 	}
   455 	
   456 	if (tn_is_ml)
   457 	{
   458 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", target_name);
   459 	}
   460 	else
   461 	{
   462 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", "_s", target_name);
   463 	}
   464 	
   465 	return Plugin_Handled;	
   466 }
   467 
   468 public Action:Command_Unmute(client, args)
   469 {	
   470 	if (args < 1)
   471 	{
   472 		ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
   473 		return Plugin_Handled;
   474 	}
   475 	
   476 	decl String:arg[64];
   477 	GetCmdArg(1, arg, sizeof(arg));
   478 	
   479 	decl String:target_name[MAX_TARGET_LENGTH];
   480 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   481 	
   482 	if ((target_count = ProcessTargetString(
   483 			arg,
   484 			client, 
   485 			target_list, 
   486 			MAXPLAYERS, 
   487 			0,
   488 			target_name,
   489 			sizeof(target_name),
   490 			tn_is_ml)) <= 0)
   491 	{
   492 		ReplyToTargetError(client, target_count);
   493 		return Plugin_Handled;
   494 	}
   495 
   496 	for (new i = 0; i < target_count; i++)
   497 	{
   498 		new target = target_list[i];
   499 		
   500 		if (!g_Muted[target])
   501 		{
   502 			continue;
   503 		}
   504 		
   505 		PerformUnMute(client, target);
   506 	}
   507 	
   508 	if (tn_is_ml)
   509 	{
   510 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", target_name);
   511 	}
   512 	else
   513 	{
   514 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", "_s", target_name);
   515 	}
   516 	
   517 	return Plugin_Handled;	
   518 }
   519 
   520 public Action:Command_Ungag(client, args)
   521 {	
   522 	if (args < 1)
   523 	{
   524 		ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
   525 		return Plugin_Handled;
   526 	}
   527 	
   528 	decl String:arg[64];
   529 	GetCmdArg(1, arg, sizeof(arg));
   530 	
   531 	decl String:target_name[MAX_TARGET_LENGTH];
   532 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   533 	
   534 	if ((target_count = ProcessTargetString(
   535 			arg,
   536 			client, 
   537 			target_list, 
   538 			MAXPLAYERS, 
   539 			0,
   540 			target_name,
   541 			sizeof(target_name),
   542 			tn_is_ml)) <= 0)
   543 	{
   544 		ReplyToTargetError(client, target_count);
   545 		return Plugin_Handled;
   546 	}
   547 
   548 	for (new i = 0; i < target_count; i++)
   549 	{
   550 		new target = target_list[i];
   551 		
   552 		PerformUnGag(client, target);
   553 	}
   554 	
   555 	if (tn_is_ml)
   556 	{
   557 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", target_name);
   558 	}
   559 	else
   560 	{
   561 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", "_s", target_name);
   562 	}
   563 	
   564 	return Plugin_Handled;	
   565 }
   566 
   567 public Action:Command_Unsilence(client, args)
   568 {	
   569 	if (args < 1)
   570 	{
   571 		ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
   572 		return Plugin_Handled;
   573 	}
   574 	
   575 	decl String:arg[64];
   576 	GetCmdArg(1, arg, sizeof(arg));
   577 	
   578 	decl String:target_name[MAX_TARGET_LENGTH];
   579 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   580 	
   581 	if ((target_count = ProcessTargetString(
   582 			arg,
   583 			client, 
   584 			target_list, 
   585 			MAXPLAYERS, 
   586 			0,
   587 			target_name,
   588 			sizeof(target_name),
   589 			tn_is_ml)) <= 0)
   590 	{
   591 		ReplyToTargetError(client, target_count);
   592 		return Plugin_Handled;
   593 	}
   594 
   595 	for (new i = 0; i < target_count; i++)
   596 	{
   597 		new target = target_list[i];
   598 		
   599 		PerformUnSilence(client, target);
   600 	}
   601 	
   602 	if (tn_is_ml)
   603 	{
   604 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", target_name);
   605 	}
   606 	else
   607 	{
   608 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", "_s", target_name);
   609 	}
   610 	
   611 	return Plugin_Handled;	
   612 }