plugins/playercommands/slap.sp
author David Anderson <dvander@alliedmods.net>
Sat Sep 06 14:33:48 2008 +0000 (2008-09-06)
changeset 2266 d133c47713e2
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Added product version file, first step to removing modules.versions someday.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Basefuncommands Plugin
ds@1952
     5
 * Provides slap functionality
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id$
ds@1952
    32
 */
ds@1952
    33
 
ds@1952
    34
new g_SlapDamage[MAXPLAYERS+1];
ds@1952
    35
ds@1952
    36
PerformSlap(client, target, damage)
ds@1952
    37
{
ds@1952
    38
	LogAction(client, target, "\"%L\" slapped \"%L\" (damage \"%d\")", client, target, damage);
ds@1952
    39
	SlapPlayer(target, damage, true);
ds@1952
    40
}
ds@1952
    41
ds@1952
    42
DisplaySlapDamageMenu(client)
ds@1952
    43
{
ds@1952
    44
	new Handle:menu = CreateMenu(MenuHandler_SlapDamage);
ds@1952
    45
	
ds@1952
    46
	decl String:title[100];
ds@1952
    47
	Format(title, sizeof(title), "%T:", "Slap damage", client);
ds@1952
    48
	SetMenuTitle(menu, title);
ds@1952
    49
	SetMenuExitBackButton(menu, true);
ds@1952
    50
	
ds@1952
    51
	AddMenuItem(menu, "0", "0");
ds@1952
    52
	AddMenuItem(menu, "1", "1");
ds@1952
    53
	AddMenuItem(menu, "5", "5");
ds@1952
    54
	AddMenuItem(menu, "10", "10");
ds@1952
    55
	AddMenuItem(menu, "20", "20");
ds@1952
    56
	AddMenuItem(menu, "50", "50");
ds@1952
    57
	AddMenuItem(menu, "99", "99");
ds@1952
    58
	
ds@1952
    59
	DisplayMenu(menu, client, MENU_TIME_FOREVER);
ds@1952
    60
}
ds@1952
    61
ds@1952
    62
DisplaySlapTargetMenu(client)
ds@1952
    63
{
ds@1952
    64
	new Handle:menu = CreateMenu(MenuHandler_Slap);
ds@1952
    65
	
ds@1952
    66
	decl String:title[100];
ds@1952
    67
	Format(title, sizeof(title), "%T:", "Slap player", client);
ds@1952
    68
	SetMenuTitle(menu, title);
ds@1952
    69
	SetMenuExitBackButton(menu, true);
ds@1952
    70
	
ds@1952
    71
	AddTargetsToMenu(menu, client, true, true);
ds@1952
    72
	
ds@1952
    73
	DisplayMenu(menu, client, MENU_TIME_FOREVER);
ds@1952
    74
}
ds@1952
    75
ds@1952
    76
public AdminMenu_Slap(Handle:topmenu, 
ds@1952
    77
					  TopMenuAction:action,
ds@1952
    78
					  TopMenuObject:object_id,
ds@1952
    79
					  param,
ds@1952
    80
					  String:buffer[],
ds@1952
    81
					  maxlength)
ds@1952
    82
{
ds@1952
    83
	if (action == TopMenuAction_DisplayOption)
ds@1952
    84
	{
ds@1952
    85
		Format(buffer, maxlength, "%T", "Slap player", param);
ds@1952
    86
	}
ds@1952
    87
	else if (action == TopMenuAction_SelectOption)
ds@1952
    88
	{
ds@1952
    89
		DisplaySlapDamageMenu(param);
ds@1952
    90
	}
ds@1952
    91
}
ds@1952
    92
ds@1952
    93
public MenuHandler_SlapDamage(Handle:menu, MenuAction:action, param1, param2)
ds@1952
    94
{
ds@1952
    95
	if (action == MenuAction_End)
ds@1952
    96
	{
ds@1952
    97
		CloseHandle(menu);
ds@1952
    98
	}
ds@1952
    99
	else if (action == MenuAction_Cancel)
ds@1952
   100
	{
ds@1952
   101
		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
ds@1952
   102
		{
ds@1952
   103
			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
ds@1952
   104
		}
ds@1952
   105
	}
ds@1952
   106
	else if (action == MenuAction_Select)
ds@1952
   107
	{
ds@1952
   108
		decl String:info[32];
ds@1952
   109
		
ds@1952
   110
		GetMenuItem(menu, param2, info, sizeof(info));
ds@1952
   111
		g_SlapDamage[param1] = StringToInt(info);
ds@1952
   112
		
ds@1952
   113
		DisplaySlapTargetMenu(param1);
ds@1952
   114
	}
ds@1952
   115
}
ds@1952
   116
ds@1952
   117
public MenuHandler_Slap(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   118
{
ds@1952
   119
	if (action == MenuAction_End)
ds@1952
   120
	{
ds@1952
   121
		CloseHandle(menu);
ds@1952
   122
	}
ds@1952
   123
	else if (action == MenuAction_Cancel)
ds@1952
   124
	{
ds@1952
   125
		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
ds@1952
   126
		{
ds@1952
   127
			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
ds@1952
   128
		}
ds@1952
   129
	}
ds@1952
   130
	else if (action == MenuAction_Select)
ds@1952
   131
	{
ds@1952
   132
		decl String:info[32];
ds@1952
   133
		new userid, target;
ds@1952
   134
		
ds@1952
   135
		GetMenuItem(menu, param2, info, sizeof(info));
ds@1952
   136
		userid = StringToInt(info);
ds@1952
   137
ds@1952
   138
		if ((target = GetClientOfUserId(userid)) == 0)
ds@1952
   139
		{
ds@1952
   140
			PrintToChat(param1, "[SM] %t", "Player no longer available");
ds@1952
   141
		}
ds@1952
   142
		else if (!CanUserTarget(param1, target))
ds@1952
   143
		{
ds@1952
   144
			PrintToChat(param1, "[SM] %t", "Unable to target");
ds@1952
   145
		}
ds@1952
   146
		else if (!IsPlayerAlive(target))
ds@1952
   147
		{
ds@1952
   148
			ReplyToCommand(param1, "[SM] %t", "Player has since died");
ds@1952
   149
		}	
ds@1952
   150
		else
ds@1952
   151
		{
ds@1952
   152
			decl String:name[32];
ds@1952
   153
			GetClientName(target, name, sizeof(name));
ds@1952
   154
			PerformSlap(param1, target, g_SlapDamage[param1]);
ds@1952
   155
			ShowActivity2(param1, "[SM] ", "%t", "Slapped target", "_s", name);
ds@1952
   156
		}
ds@1952
   157
		
ds@1952
   158
		DisplaySlapTargetMenu(param1);
ds@1952
   159
	}
ds@1952
   160
}
ds@1952
   161
ds@1952
   162
public Action:Command_Slap(client, args)
ds@1952
   163
{
ds@1952
   164
	if (args < 1)
ds@1952
   165
	{
ds@1952
   166
		ReplyToCommand(client, "[SM] Usage: sm_slap <#userid|name> [damage]");
ds@1952
   167
		return Plugin_Handled;
ds@1952
   168
	}
ds@1952
   169
ds@1952
   170
	decl String:arg[65];
ds@1952
   171
	GetCmdArg(1, arg, sizeof(arg));
ds@1952
   172
ds@1952
   173
	new damage = 0;
ds@1952
   174
	if (args > 1)
ds@1952
   175
	{
ds@1952
   176
		decl String:arg2[20];
ds@1952
   177
		GetCmdArg(2, arg2, sizeof(arg2));
ds@1952
   178
		if (StringToIntEx(arg2, damage) == 0 || damage < 0)
ds@1952
   179
		{
ds@1952
   180
			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
ds@1952
   181
			return Plugin_Handled;
ds@1952
   182
		}
ds@1952
   183
	}
ds@1952
   184
	
ds@1952
   185
	decl String:target_name[MAX_TARGET_LENGTH];
ds@1952
   186
	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
ds@1952
   187
	
ds@1952
   188
	if ((target_count = ProcessTargetString(
ds@1952
   189
			arg,
ds@1952
   190
			client,
ds@1952
   191
			target_list,
ds@1952
   192
			MAXPLAYERS,
ds@1952
   193
			COMMAND_FILTER_ALIVE,
ds@1952
   194
			target_name,
ds@1952
   195
			sizeof(target_name),
ds@1952
   196
			tn_is_ml)) <= 0)
ds@1952
   197
	{
ds@1952
   198
		ReplyToTargetError(client, target_count);
ds@1952
   199
		return Plugin_Handled;
ds@1952
   200
	}
ds@1952
   201
	
ds@1952
   202
	for (new i = 0; i < target_count; i++)
ds@1952
   203
	{
ds@1952
   204
		PerformSlap(client, target_list[i], damage);
ds@1952
   205
	}
ds@1952
   206
ds@1952
   207
	if (tn_is_ml)
ds@1952
   208
	{
ds@1952
   209
		ShowActivity2(client, "[SM] ", "%t", "Slapped target", target_name);
ds@1952
   210
	}
ds@1952
   211
	else
ds@1952
   212
	{
ds@1952
   213
		ShowActivity2(client, "[SM] ", "%t", "Slapped target", "_s", target_name);
ds@1952
   214
	}
ds@1952
   215
ds@1952
   216
	return Plugin_Handled;
ds@1952
   217
}