plugins/playercommands/slay.sp
author David Anderson <danderson@mozilla.com>
Thu Aug 08 09:41:24 2013 -0700 (2013-08-08)
changeset 3977 fca2b54741ca
parent 2289 44045ead61cd
permissions -rw-r--r--
Refactor the JIT to use a newer, simpler macro assembler. (bug 5827, r=ann)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefuncommands Plugin
     5  * Provides slay 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 PerformSlay(client, target)
    35 {
    36 	LogAction(client, target, "\"%L\" slayed \"%L\"", client, target);
    37 	ForcePlayerSuicide(target);
    38 }
    39 
    40 DisplaySlayMenu(client)
    41 {
    42 	new Handle:menu = CreateMenu(MenuHandler_Slay);
    43 	
    44 	decl String:title[100];
    45 	Format(title, sizeof(title), "%T:", "Slay player", client);
    46 	SetMenuTitle(menu, title);
    47 	SetMenuExitBackButton(menu, true);
    48 	
    49 	AddTargetsToMenu(menu, client, true, true);
    50 	
    51 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    52 }
    53 
    54 public AdminMenu_Slay(Handle:topmenu, 
    55 					  TopMenuAction:action,
    56 					  TopMenuObject:object_id,
    57 					  param,
    58 					  String:buffer[],
    59 					  maxlength)
    60 {
    61 	if (action == TopMenuAction_DisplayOption)
    62 	{
    63 		Format(buffer, maxlength, "%T", "Slay player", param);
    64 	}
    65 	else if (action == TopMenuAction_SelectOption)
    66 	{
    67 		DisplaySlayMenu(param);
    68 	}
    69 }
    70 
    71 public MenuHandler_Slay(Handle:menu, MenuAction:action, param1, param2)
    72 {
    73 	if (action == MenuAction_End)
    74 	{
    75 		CloseHandle(menu);
    76 	}
    77 	else if (action == MenuAction_Cancel)
    78 	{
    79 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    80 		{
    81 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    82 		}
    83 	}
    84 	else if (action == MenuAction_Select)
    85 	{
    86 		decl String:info[32];
    87 		new userid, target;
    88 		
    89 		GetMenuItem(menu, param2, info, sizeof(info));
    90 		userid = StringToInt(info);
    91 
    92 		if ((target = GetClientOfUserId(userid)) == 0)
    93 		{
    94 			PrintToChat(param1, "[SM] %t", "Player no longer available");
    95 		}
    96 		else if (!CanUserTarget(param1, target))
    97 		{
    98 			PrintToChat(param1, "[SM] %t", "Unable to target");
    99 		}
   100 		else if (!IsPlayerAlive(target))
   101 		{
   102 			ReplyToCommand(param1, "[SM] %t", "Player has since died");
   103 		}
   104 		else
   105 		{
   106 			decl String:name[32];
   107 			GetClientName(target, name, sizeof(name));
   108 			PerformSlay(param1, target);
   109 			ShowActivity2(param1, "[SM] ", "%t", "Slayed target", "_s", name);
   110 		}
   111 		
   112 		DisplaySlayMenu(param1);
   113 	}
   114 }
   115 
   116 public Action:Command_Slay(client, args)
   117 {
   118 	if (args < 1)
   119 	{
   120 		ReplyToCommand(client, "[SM] Usage: sm_slay <#userid|name>");
   121 		return Plugin_Handled;
   122 	}
   123 
   124 	decl String:arg[65];
   125 	GetCmdArg(1, arg, sizeof(arg));
   126 
   127 	decl String:target_name[MAX_TARGET_LENGTH];
   128 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   129 	
   130 	if ((target_count = ProcessTargetString(
   131 			arg,
   132 			client,
   133 			target_list,
   134 			MAXPLAYERS,
   135 			COMMAND_FILTER_ALIVE,
   136 			target_name,
   137 			sizeof(target_name),
   138 			tn_is_ml)) <= 0)
   139 	{
   140 		ReplyToTargetError(client, target_count);
   141 		return Plugin_Handled;
   142 	}
   143 
   144 	for (new i = 0; i < target_count; i++)
   145 	{
   146 		PerformSlay(client, target_list[i]);
   147 	}
   148 	
   149 	if (tn_is_ml)
   150 	{
   151 		ShowActivity2(client, "[SM] ", "%t", "Slayed target", target_name);
   152 	}
   153 	else
   154 	{
   155 		ShowActivity2(client, "[SM] ", "%t", "Slayed target", "_s", target_name);
   156 	}
   157 
   158 	return Plugin_Handled;
   159 }