plugins/slapslay/slap.sp
changeset 1801 06ff8ce94b2b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/slapslay/slap.sp	Wed Dec 19 01:16:15 2007 +0000
     1.3 @@ -0,0 +1,217 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basefuncommands Plugin
     1.8 + * Provides slap functionality
     1.9 + *
    1.10 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
    1.11 + * =============================================================================
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify it under
    1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 + * Free Software Foundation.
    1.16 + * 
    1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 + * details.
    1.21 + *
    1.22 + * You should have received a copy of the GNU General Public License along with
    1.23 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 + *
    1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 + * or <http://www.sourcemod.net/license.php>.
    1.33 + *
    1.34 + * Version: $Id$
    1.35 + */
    1.36 + 
    1.37 +new g_SlapDamage[MAXPLAYERS+1];
    1.38 +
    1.39 +PerformSlap(client, target, damage)
    1.40 +{
    1.41 +	LogAction(client, target, "\"%L\" slapped \"%L\" (damage \"%d\")", client, target, damage);
    1.42 +	SlapPlayer(target, damage, true);
    1.43 +}
    1.44 +
    1.45 +DisplaySlapDamageMenu(client)
    1.46 +{
    1.47 +	new Handle:menu = CreateMenu(MenuHandler_SlapDamage);
    1.48 +	
    1.49 +	decl String:title[100];
    1.50 +	Format(title, sizeof(title), "%T:", "Slap damage", client);
    1.51 +	SetMenuTitle(menu, title);
    1.52 +	SetMenuExitBackButton(menu, true);
    1.53 +	
    1.54 +	AddMenuItem(menu, "0", "0");
    1.55 +	AddMenuItem(menu, "1", "1");
    1.56 +	AddMenuItem(menu, "5", "5");
    1.57 +	AddMenuItem(menu, "10", "10");
    1.58 +	AddMenuItem(menu, "20", "20");
    1.59 +	AddMenuItem(menu, "50", "50");
    1.60 +	AddMenuItem(menu, "99", "99");
    1.61 +	
    1.62 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    1.63 +}
    1.64 +
    1.65 +DisplaySlapTargetMenu(client)
    1.66 +{
    1.67 +	new Handle:menu = CreateMenu(MenuHandler_Slap);
    1.68 +	
    1.69 +	decl String:title[100];
    1.70 +	Format(title, sizeof(title), "%T:", "Slap player", client);
    1.71 +	SetMenuTitle(menu, title);
    1.72 +	SetMenuExitBackButton(menu, true);
    1.73 +	
    1.74 +	AddTargetsToMenu(menu, client, true, true);
    1.75 +	
    1.76 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    1.77 +}
    1.78 +
    1.79 +public AdminMenu_Slap(Handle:topmenu, 
    1.80 +					  TopMenuAction:action,
    1.81 +					  TopMenuObject:object_id,
    1.82 +					  param,
    1.83 +					  String:buffer[],
    1.84 +					  maxlength)
    1.85 +{
    1.86 +	if (action == TopMenuAction_DisplayOption)
    1.87 +	{
    1.88 +		Format(buffer, maxlength, "%T", "Slap player", param);
    1.89 +	}
    1.90 +	else if (action == TopMenuAction_SelectOption)
    1.91 +	{
    1.92 +		DisplaySlapDamageMenu(param);
    1.93 +	}
    1.94 +}
    1.95 +
    1.96 +public MenuHandler_SlapDamage(Handle:menu, MenuAction:action, param1, param2)
    1.97 +{
    1.98 +	if (action == MenuAction_End)
    1.99 +	{
   1.100 +		CloseHandle(menu);
   1.101 +	}
   1.102 +	else if (action == MenuAction_Cancel)
   1.103 +	{
   1.104 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.105 +		{
   1.106 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.107 +		}
   1.108 +	}
   1.109 +	else if (action == MenuAction_Select)
   1.110 +	{
   1.111 +		decl String:info[32];
   1.112 +		
   1.113 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.114 +		g_SlapDamage[param1] = StringToInt(info);
   1.115 +		
   1.116 +		DisplaySlapTargetMenu(param1);
   1.117 +	}
   1.118 +}
   1.119 +
   1.120 +public MenuHandler_Slap(Handle:menu, MenuAction:action, param1, param2)
   1.121 +{
   1.122 +	if (action == MenuAction_End)
   1.123 +	{
   1.124 +		CloseHandle(menu);
   1.125 +	}
   1.126 +	else if (action == MenuAction_Cancel)
   1.127 +	{
   1.128 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.129 +		{
   1.130 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.131 +		}
   1.132 +	}
   1.133 +	else if (action == MenuAction_Select)
   1.134 +	{
   1.135 +		decl String:info[32];
   1.136 +		new userid, target;
   1.137 +		
   1.138 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.139 +		userid = StringToInt(info);
   1.140 +
   1.141 +		if ((target = GetClientOfUserId(userid)) == 0)
   1.142 +		{
   1.143 +			PrintToChat(param1, "[SM] %t", "Player no longer available");
   1.144 +		}
   1.145 +		else if (!CanUserTarget(param1, target))
   1.146 +		{
   1.147 +			PrintToChat(param1, "[SM] %t", "Unable to target");
   1.148 +		}
   1.149 +		else if (!IsPlayerAlive(target))
   1.150 +		{
   1.151 +			ReplyToCommand(param1, "[SM] %t", "Player has since died");
   1.152 +		}	
   1.153 +		else
   1.154 +		{
   1.155 +			decl String:name[32];
   1.156 +			GetClientName(target, name, sizeof(name));
   1.157 +			PerformSlap(param1, target, g_SlapDamage[param1]);
   1.158 +			ShowActivity2(param1, "[SM] ", "%t", "Slapped target", "_s", name);
   1.159 +		}
   1.160 +		
   1.161 +		DisplaySlapTargetMenu(param1);
   1.162 +	}
   1.163 +}
   1.164 +
   1.165 +public Action:Command_Slap(client, args)
   1.166 +{
   1.167 +	if (args < 1)
   1.168 +	{
   1.169 +		ReplyToCommand(client, "[SM] Usage: sm_slap <#userid|name> [damage]");
   1.170 +		return Plugin_Handled;
   1.171 +	}
   1.172 +
   1.173 +	decl String:arg[65];
   1.174 +	GetCmdArg(1, arg, sizeof(arg));
   1.175 +
   1.176 +	new damage = 0;
   1.177 +	if (args > 1)
   1.178 +	{
   1.179 +		decl String:arg2[20];
   1.180 +		GetCmdArg(2, arg2, sizeof(arg2));
   1.181 +		if (StringToIntEx(arg2, damage) == 0)
   1.182 +		{
   1.183 +			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
   1.184 +			return Plugin_Handled;
   1.185 +		}
   1.186 +	}
   1.187 +	
   1.188 +	decl String:target_name[MAX_TARGET_LENGTH];
   1.189 +	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   1.190 +	
   1.191 +	if ((target_count = ProcessTargetString(
   1.192 +			arg,
   1.193 +			client,
   1.194 +			target_list,
   1.195 +			MAXPLAYERS,
   1.196 +			COMMAND_FILTER_ALIVE,
   1.197 +			target_name,
   1.198 +			sizeof(target_name),
   1.199 +			tn_is_ml)) <= 0)
   1.200 +	{
   1.201 +		ReplyToTargetError(client, target_count);
   1.202 +		return Plugin_Handled;
   1.203 +	}
   1.204 +	
   1.205 +	for (new i = 0; i < target_count; i++)
   1.206 +	{
   1.207 +		PerformSlap(client, target_list[i], damage);
   1.208 +	}
   1.209 +
   1.210 +	if (tn_is_ml)
   1.211 +	{
   1.212 +		ShowActivity2(client, "[SM] ", "%t", "Slapped target", target_name);
   1.213 +	}
   1.214 +	else
   1.215 +	{
   1.216 +		ShowActivity2(client, "[SM] ", "%t", "Slapped target", "_s", target_name);
   1.217 +	}
   1.218 +
   1.219 +	return Plugin_Handled;
   1.220 +}