plugins/basefuncommands/slap.sp
author Michael McKoy <ferret99gt@gmail.com>
Thu Dec 13 00:21:07 2007 +0000 (2007-12-13)
changeset 1789 55172f6df9a4
parent 1682 a7478db7aa6b
permissions -rw-r--r--
Fixed file headers on all base plugin includes.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefuncommands Plugin
     5  * Provides slap functionality
     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: admin-flatfile.sp 1438 2007-09-16 03:45:06Z dvander $
    32  */
    33 
    34 PerformSlap(client, target, damage)
    35 {
    36 	LogAction(client, target, "\"%L\" slapped \"%L\" (damage \"%d\")", client, target, damage);
    37 	SlapPlayer(target, damage, true);
    38 }
    39 
    40 DisplaySlapDamageMenu(client)
    41 {
    42 	new Handle:menu = CreateMenu(MenuHandler_SlapDamage);
    43 	
    44 	decl String:title[100];
    45 	Format(title, sizeof(title), "%T:", "Slap damage", client);
    46 	SetMenuTitle(menu, title);
    47 	SetMenuExitBackButton(menu, true);
    48 	
    49 	AddMenuItem(menu, "0", "0");
    50 	AddMenuItem(menu, "1", "1");
    51 	AddMenuItem(menu, "5", "5");
    52 	AddMenuItem(menu, "10", "10");
    53 	AddMenuItem(menu, "20", "20");
    54 	AddMenuItem(menu, "50", "50");
    55 	AddMenuItem(menu, "99", "99");
    56 	
    57 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    58 }
    59 
    60 DisplaySlapTargetMenu(client)
    61 {
    62 	new Handle:menu = CreateMenu(MenuHandler_Slap);
    63 	
    64 	decl String:title[100];
    65 	Format(title, sizeof(title), "%T:", "Slap player", client);
    66 	SetMenuTitle(menu, title);
    67 	SetMenuExitBackButton(menu, true);
    68 	
    69 	AddTargetsToMenu(menu, client, true, true);
    70 	
    71 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    72 }
    73 
    74 public AdminMenu_Slap(Handle:topmenu, 
    75 					  TopMenuAction:action,
    76 					  TopMenuObject:object_id,
    77 					  param,
    78 					  String:buffer[],
    79 					  maxlength)
    80 {
    81 	if (action == TopMenuAction_DisplayOption)
    82 	{
    83 		Format(buffer, maxlength, "%T", "Slap player", param);
    84 	}
    85 	else if (action == TopMenuAction_SelectOption)
    86 	{
    87 		DisplaySlapDamageMenu(param);
    88 	}
    89 }
    90 
    91 public MenuHandler_SlapDamage(Handle:menu, MenuAction:action, param1, param2)
    92 {
    93 	if (action == MenuAction_End)
    94 	{
    95 		CloseHandle(menu);
    96 	}
    97 	else if (action == MenuAction_Cancel)
    98 	{
    99 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   100 		{
   101 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   102 		}
   103 	}
   104 	else if (action == MenuAction_Select)
   105 	{
   106 		decl String:info[32];
   107 		
   108 		GetMenuItem(menu, param2, info, sizeof(info));
   109 		g_SlapDamage[param1] = StringToInt(info);
   110 		
   111 		DisplaySlapTargetMenu(param1);
   112 	}
   113 }
   114 
   115 public MenuHandler_Slap(Handle:menu, MenuAction:action, param1, param2)
   116 {
   117 	if (action == MenuAction_End)
   118 	{
   119 		CloseHandle(menu);
   120 	}
   121 	else if (action == MenuAction_Cancel)
   122 	{
   123 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   124 		{
   125 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   126 		}
   127 	}
   128 	else if (action == MenuAction_Select)
   129 	{
   130 		decl String:info[32];
   131 		new userid, target;
   132 		
   133 		GetMenuItem(menu, param2, info, sizeof(info));
   134 		userid = StringToInt(info);
   135 
   136 		if ((target = GetClientOfUserId(userid)) == 0)
   137 		{
   138 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   139 		}
   140 		else if (!CanUserTarget(param1, target))
   141 		{
   142 			PrintToChat(param1, "[SM] %t", "Unable to target");
   143 		}
   144 		else if (!IsPlayerAlive(target))
   145 		{
   146 			ReplyToCommand(param1, "[SM] %t", "Player has since died");
   147 		}	
   148 		else
   149 		{
   150 			decl String:name[32];
   151 			GetClientName(target, name, sizeof(name));
   152 			PerformSlap(param1, target, g_SlapDamage[param1]);
   153 			ShowActivity2(param1, "[SM] ", "%t", "Slapped target", "_s", name);
   154 		}
   155 		
   156 		DisplaySlapTargetMenu(param1);
   157 	}
   158 }
   159 
   160 public Action:Command_Slap(client, args)
   161 {
   162 	if (args < 1)
   163 	{
   164 		ReplyToCommand(client, "[SM] Usage: sm_slap <#userid|name> [damage]");
   165 		return Plugin_Handled;
   166 	}
   167 
   168 	decl String:arg[65];
   169 	GetCmdArg(1, arg, sizeof(arg));
   170 
   171 	new damage = 0;
   172 	if (args > 1)
   173 	{
   174 		decl String:arg2[20];
   175 		GetCmdArg(2, arg2, sizeof(arg2));
   176 		if (StringToIntEx(arg2, damage) == 0)
   177 		{
   178 			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
   179 			return Plugin_Handled;
   180 		}
   181 	}
   182 	
   183 	decl String:target_name[MAX_TARGET_LENGTH];
   184 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   185 	
   186 	if ((target_count = ProcessTargetString(
   187 			arg,
   188 			client,
   189 			target_list,
   190 			MAXPLAYERS,
   191 			COMMAND_FILTER_ALIVE,
   192 			target_name,
   193 			sizeof(target_name),
   194 			tn_is_ml)) <= 0)
   195 	{
   196 		ReplyToTargetError(client, target_count);
   197 		return Plugin_Handled;
   198 	}
   199 	
   200 	for (new i = 0; i < target_count; i++)
   201 	{
   202 		PerformSlap(client, target_list[i], damage);
   203 	}
   204 
   205 	if (tn_is_ml)
   206 	{
   207 		ShowActivity2(client, "[SM] ", "%t", "Slapped target", target_name);
   208 	}
   209 	else
   210 	{
   211 		ShowActivity2(client, "[SM] ", "%t", "Slapped target", "_s", target_name);
   212 	}
   213 
   214 	return Plugin_Handled;
   215 }