plugins/funcommands/timebomb.sp
author Nicholas Hastings <skamonkey@gmail.com>
Wed Oct 06 20:46:29 2010 -0400 (2010-10-06)
changeset 3135 c85fb4eec281
parent 3094 f606f5c1dbca
child 4305 fe0e55c4d544
permissions -rw-r--r--
Updated CSS/DODS/TF2/HL2DM CommitSuicide offset (bug 4650, r=fyren).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefuncommands Plugin
     5  * Provides TimeBomb 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 new g_TimeBombSerial[MAXPLAYERS+1] = { 0, ... };
    35 new g_TimeBombTime[MAXPLAYERS+1] = { 0, ... };
    36 
    37 new Handle:g_Cvar_TimeBombTicks = INVALID_HANDLE;
    38 new Handle:g_Cvar_TimeBombRadius = INVALID_HANDLE;
    39 new Handle:g_Cvar_TimeBombMode = INVALID_HANDLE;
    40 
    41 CreateTimeBomb(client)
    42 {
    43 	g_TimeBombSerial[client] = ++g_Serial_Gen;
    44 	CreateTimer(1.0, Timer_TimeBomb, client | (g_Serial_Gen << 7), DEFAULT_TIMER_FLAGS);
    45 	g_TimeBombTime[client] = GetConVarInt(g_Cvar_TimeBombTicks);
    46 }
    47 
    48 KillTimeBomb(client)
    49 {
    50 	g_TimeBombSerial[client] = 0;
    51 
    52 	if (IsClientInGame(client))
    53 	{
    54 		SetEntityRenderColor(client, 255, 255, 255, 255);
    55 	}
    56 }
    57 
    58 KillAllTimeBombs()
    59 {
    60 	for (new i = 1; i <= MaxClients; i++)
    61 	{
    62 		KillTimeBomb(i);
    63 	}
    64 }
    65 
    66 PerformTimeBomb(client, target)
    67 {
    68 	if (g_TimeBombSerial[target] == 0)
    69 	{
    70 		CreateTimeBomb(target);
    71 		LogAction(client, target, "\"%L\" set a TimeBomb on \"%L\"", client, target);
    72 	}
    73 	else
    74 	{
    75 		KillTimeBomb(target);
    76 		SetEntityRenderColor(client, 255, 255, 255, 255);
    77 		LogAction(client, target, "\"%L\" removed a TimeBomb on \"%L\"", client, target);
    78 	}
    79 }
    80 
    81 public Action:Timer_TimeBomb(Handle:timer, any:value)
    82 {
    83 	new client = value & 0x7f;
    84 	new serial = value >> 7;
    85 
    86 	if (!IsClientInGame(client)
    87 		|| !IsPlayerAlive(client)
    88 		|| serial != g_TimeBombSerial[client])
    89 	{
    90 		KillTimeBomb(client);
    91 		return Plugin_Stop;
    92 	}	
    93 	g_TimeBombTime[client]--;
    94 	
    95 	new Float:vec[3];
    96 	GetClientEyePosition(client, vec);
    97 	
    98 	if (g_TimeBombTime[client] > 0)
    99 	{
   100 		new color;
   101 		
   102 		if (g_TimeBombTime[client] > 1)
   103 		{
   104 			color = RoundToFloor(g_TimeBombTime[client] * (128.0 / GetConVarFloat(g_Cvar_TimeBombTicks)));
   105 			EmitAmbientSound(SOUND_BEEP, vec, client, SNDLEVEL_RAIDSIREN);	
   106 		}
   107 		else
   108 		{
   109 			color = 0;
   110 			EmitAmbientSound(SOUND_FINAL, vec, client, SNDLEVEL_RAIDSIREN);
   111 		}
   112 		
   113 		SetEntityRenderColor(client, 255, 128, color, 255);
   114 
   115 		decl String:name[64];
   116 		GetClientName(client, name, sizeof(name));
   117 		PrintCenterTextAll("%t", "Till Explodes", name, g_TimeBombTime[client]);
   118 		
   119 		GetClientAbsOrigin(client, vec);
   120 		vec[2] += 10;
   121 
   122 		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_TimeBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greyColor, 10, 0);
   123 		TE_SendToAll();
   124 		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_TimeBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, whiteColor, 10, 0);
   125 		TE_SendToAll();
   126 		return Plugin_Continue;
   127 	}
   128 	else
   129 	{
   130 		if (g_ExplosionSprite > -1)
   131 		{
   132 			TE_SetupExplosion(vec, g_ExplosionSprite, 5.0, 1, 0, GetConVarInt(g_Cvar_TimeBombRadius), 5000);
   133 			TE_SendToAll();
   134 		}
   135 
   136 		EmitAmbientSound(SOUND_BOOM, vec, client, SNDLEVEL_RAIDSIREN);
   137 
   138 		ForcePlayerSuicide(client);
   139 		KillTimeBomb(client);
   140 		SetEntityRenderColor(client, 255, 255, 255, 255);
   141 		
   142 		if (GetConVarInt(g_Cvar_TimeBombMode) > 0)
   143 		{
   144 			new teamOnly = ((GetConVarInt(g_Cvar_TimeBombMode) == 1) ? true : false);
   145 			
   146 			for (new i = 1; i <= MaxClients; i++)
   147 			{
   148 				if (!IsClientInGame(i) || !IsPlayerAlive(i) || i == client)
   149 				{
   150 					continue;
   151 				}
   152 				
   153 				if (teamOnly && GetClientTeam(i) != GetClientTeam(client))
   154 				{
   155 					continue;
   156 				}
   157 				
   158 				new Float:pos[3];
   159 				GetClientEyePosition(i, pos);
   160 				
   161 				new Float:distance = GetVectorDistance(vec, pos);
   162 				
   163 				if (distance > GetConVarFloat(g_Cvar_TimeBombRadius))
   164 				{
   165 					continue;
   166 				}
   167 				
   168 				new damage = 220;
   169 				damage = RoundToFloor(damage * ((GetConVarFloat(g_Cvar_TimeBombRadius) - distance) / GetConVarFloat(g_Cvar_TimeBombRadius)));
   170 					
   171 				SlapPlayer(i, damage, false);
   172 				
   173 				if (g_ExplosionSprite > -1)
   174 				{
   175 					TE_SetupExplosion(pos, g_ExplosionSprite, 0.05, 1, 0, 1, 1);
   176 					TE_SendToAll();	
   177 				}
   178 				
   179 				/* ToDo
   180 				new Float:dir[3];
   181 				SubtractVectors(vec, pos, dir);
   182 				TR_TraceRayFilter(vec, dir, MASK_SOLID, RayType_Infinite, TR_Filter_Client);
   183 
   184 				if (i == TR_GetEntityIndex())
   185 				{
   186 					new damage = 100;
   187 					new radius = GetConVarInt(g_Cvar_TimeBombRadius) / 2;
   188 					
   189 					if (distance > radius)
   190 					{
   191 						distance -= radius;
   192 						damage = RoundToFloor(damage * ((radius - distance) / radius));
   193 					}
   194 					
   195 					SlapPlayer(i, damage, false);
   196 				}
   197 				*/
   198 			}		
   199 		}
   200 		return Plugin_Stop;
   201 	}
   202 }
   203 
   204 public AdminMenu_TimeBomb(Handle:topmenu, 
   205 					  TopMenuAction:action,
   206 					  TopMenuObject:object_id,
   207 					  param,
   208 					  String:buffer[],
   209 					  maxlength)
   210 {
   211 	if (action == TopMenuAction_DisplayOption)
   212 	{
   213 		Format(buffer, maxlength, "%T", "TimeBomb player", param);
   214 	}
   215 	else if (action == TopMenuAction_SelectOption)
   216 	{
   217 		DisplayTimeBombMenu(param);
   218 	}
   219 }
   220 
   221 DisplayTimeBombMenu(client)
   222 {
   223 	new Handle:menu = CreateMenu(MenuHandler_TimeBomb);
   224 	
   225 	decl String:title[100];
   226 	Format(title, sizeof(title), "%T:", "TimeBomb player", client);
   227 	SetMenuTitle(menu, title);
   228 	SetMenuExitBackButton(menu, true);
   229 	
   230 	AddTargetsToMenu(menu, client, true, true);
   231 	
   232 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   233 }
   234 
   235 public MenuHandler_TimeBomb(Handle:menu, MenuAction:action, param1, param2)
   236 {
   237 	if (action == MenuAction_End)
   238 	{
   239 		CloseHandle(menu);
   240 	}
   241 	else if (action == MenuAction_Cancel)
   242 	{
   243 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   244 		{
   245 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   246 		}
   247 	}
   248 	else if (action == MenuAction_Select)
   249 	{
   250 		decl String:info[32];
   251 		new userid, target;
   252 		
   253 		GetMenuItem(menu, param2, info, sizeof(info));
   254 		userid = StringToInt(info);
   255 
   256 		if ((target = GetClientOfUserId(userid)) == 0)
   257 		{
   258 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   259 		}
   260 		else if (!CanUserTarget(param1, target))
   261 		{
   262 			PrintToChat(param1, "[SM] %t", "Unable to target");
   263 		}
   264 		else
   265 		{
   266 			new String:name[32];
   267 			GetClientName(target, name, sizeof(name));
   268 			
   269 			PerformTimeBomb(param1, target);
   270 			ShowActivity2(param1, "[SM] ", "%t", "Toggled TimeBomb on target", "_s", name);
   271 		}
   272 		
   273 		/* Re-draw the menu if they're still valid */
   274 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   275 		{
   276 			DisplayTimeBombMenu(param1);
   277 		}
   278 	}
   279 }
   280 
   281 public Action:Command_TimeBomb(client, args)
   282 {
   283 	if (args < 1)
   284 	{
   285 		ReplyToCommand(client, "[SM] Usage: sm_timebomb <#userid|name>");
   286 		return Plugin_Handled;
   287 	}
   288 
   289 	decl String:arg[65];
   290 	GetCmdArg(1, arg, sizeof(arg));
   291 
   292 	decl String:target_name[MAX_TARGET_LENGTH];
   293 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   294 	
   295 	if ((target_count = ProcessTargetString(
   296 			arg,
   297 			client,
   298 			target_list,
   299 			MAXPLAYERS,
   300 			COMMAND_FILTER_ALIVE,
   301 			target_name,
   302 			sizeof(target_name),
   303 			tn_is_ml)) <= 0)
   304 	{
   305 		ReplyToTargetError(client, target_count);
   306 		return Plugin_Handled;
   307 	}
   308 	
   309 	for (new i = 0; i < target_count; i++)
   310 	{
   311 		PerformTimeBomb(client, target_list[i]);
   312 	}
   313 	
   314 	if (tn_is_ml)
   315 	{
   316 		ShowActivity2(client, "[SM] ", "%t", "Toggled TimeBomb on target", target_name);
   317 	}
   318 	else
   319 	{
   320 		ShowActivity2(client, "[SM] ", "%t", "Toggled TimeBomb on target", "_s", target_name);
   321 	}
   322 	
   323 	return Plugin_Handled;
   324 }