plugins/funcommands/noclip.sp
author Nicholas Hastings <skamonkey@gmail.com>
Fri Nov 04 10:01:33 2011 -0400 (2011-11-04)
changeset 3438 07a1b8a8a2ba
parent 2501 73a73b6e0dc8
permissions -rw-r--r--
Updated TF2_OnIsHolidayActive ret behavior to match doc (bug 5155, r=fyren).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefuncommands Plugin
     5  * Provides noclip 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 PerformNoClip(client, target)
    35 {
    36 	new MoveType:movetype = GetEntityMoveType(target);
    37 
    38 	if (movetype != MOVETYPE_NOCLIP)
    39 	{
    40 		SetEntityMoveType(target, MOVETYPE_NOCLIP);
    41 	}
    42 	else
    43 	{
    44 		SetEntityMoveType(target, MOVETYPE_WALK);
    45 	}
    46 	
    47 	LogAction(client, target, "\"%L\" toggled noclip on \"%L\"", client, target);
    48 }
    49 
    50 public AdminMenu_NoClip(Handle:topmenu, 
    51 					  TopMenuAction:action,
    52 					  TopMenuObject:object_id,
    53 					  param,
    54 					  String:buffer[],
    55 					  maxlength)
    56 {
    57 	if (action == TopMenuAction_DisplayOption)
    58 	{
    59 		Format(buffer, maxlength, "%T", "NoClip player", param);
    60 	}
    61 	else if (action == TopMenuAction_SelectOption)
    62 	{
    63 		DisplayNoClipMenu(param);
    64 	}
    65 }
    66 
    67 DisplayNoClipMenu(client)
    68 {
    69 	new Handle:menu = CreateMenu(MenuHandler_NoClip);
    70 	
    71 	decl String:title[100];
    72 	Format(title, sizeof(title), "%T:", "NoClip player", client);
    73 	SetMenuTitle(menu, title);
    74 	SetMenuExitBackButton(menu, true);
    75 	
    76 	AddTargetsToMenu(menu, client, true, true);
    77 	
    78 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    79 }
    80 
    81 public MenuHandler_NoClip(Handle:menu, MenuAction:action, param1, param2)
    82 {
    83 	if (action == MenuAction_End)
    84 	{
    85 		CloseHandle(menu);
    86 	}
    87 	else if (action == MenuAction_Cancel)
    88 	{
    89 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
    90 		{
    91 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
    92 		}
    93 	}
    94 	else if (action == MenuAction_Select)
    95 	{
    96 		decl String:info[32];
    97 		new userid, target;
    98 		
    99 		GetMenuItem(menu, param2, info, sizeof(info));
   100 		userid = StringToInt(info);
   101 
   102 		if ((target = GetClientOfUserId(userid)) == 0)
   103 		{
   104 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   105 		}
   106 		else if (!CanUserTarget(param1, target))
   107 		{
   108 			PrintToChat(param1, "[SM] %t", "Unable to target");
   109 		}
   110 		else
   111 		{
   112 			new String:name[32];
   113 			GetClientName(target, name, sizeof(name));
   114 			
   115 			PerformNoClip(param1, target);
   116 			ShowActivity2(param1, "[SM] ", "%t", "Toggled noclip on target", "_s", name);
   117 		}
   118 		
   119 		/* Re-draw the menu if they're still valid */
   120 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   121 		{
   122 			DisplayNoClipMenu(param1);
   123 		}
   124 	}
   125 }
   126 
   127 public Action:Command_NoClip(client, args)
   128 {
   129 	if (args < 1)
   130 	{
   131 		ReplyToCommand(client, "[SM] Usage: sm_noclip <#userid|name>");
   132 		return Plugin_Handled;
   133 	}
   134 
   135 	decl String:arg[65];
   136 	GetCmdArg(1, arg, sizeof(arg));
   137 	
   138 	decl String:target_name[MAX_TARGET_LENGTH];
   139 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   140 	
   141 	if ((target_count = ProcessTargetString(
   142 			arg,
   143 			client,
   144 			target_list,
   145 			MAXPLAYERS,
   146 			COMMAND_FILTER_ALIVE,
   147 			target_name,
   148 			sizeof(target_name),
   149 			tn_is_ml)) <= 0)
   150 	{
   151 		ReplyToTargetError(client, target_count);
   152 		return Plugin_Handled;
   153 	}
   154 	
   155 	for (new i = 0; i < target_count; i++)
   156 	{
   157 		PerformNoClip(client, target_list[i]);
   158 	}
   159 	
   160 	if (tn_is_ml)
   161 	{
   162 		ShowActivity2(client, "[SM] ", "%t", "Toggled noclip on target", target_name);
   163 	}
   164 	else
   165 	{
   166 		ShowActivity2(client, "[SM] ", "%t", "Toggled noclip on target", "_s", target_name);
   167 	}
   168 	
   169 	return Plugin_Handled;
   170 }