plugins/funcommands/fire.sp
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 4310 896868764315
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basefuncommands Plugin
     5  * Provides FireBomb 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_FireBombSerial[MAXPLAYERS+1] = { 0, ... };
    35 new g_FireBombTime[MAXPLAYERS+1] = { 0, ... };
    36 
    37 new Handle:g_Cvar_BurnDuration = INVALID_HANDLE;
    38 new Handle:g_Cvar_FireBombTicks = INVALID_HANDLE;
    39 new Handle:g_Cvar_FireBombRadius = INVALID_HANDLE;
    40 new Handle:g_Cvar_FireBombMode = INVALID_HANDLE;
    41 
    42 CreateFireBomb(client)
    43 {
    44 	g_FireBombSerial[client] = ++g_Serial_Gen;
    45 	CreateTimer(1.0, Timer_FireBomb, client | (g_Serial_Gen << 7), DEFAULT_TIMER_FLAGS);
    46 	g_FireBombTime[client] = GetConVarInt(g_Cvar_FireBombTicks);
    47 }
    48 
    49 KillFireBomb(client)
    50 {
    51 	g_FireBombSerial[client] = 0;
    52 
    53 	if (IsClientInGame(client))
    54 	{
    55 		SetEntityRenderColor(client, 255, 255, 255, 255);
    56 	}
    57 }
    58 
    59 KillAllFireBombs()
    60 {
    61 	for (new i = 1; i <= MaxClients; i++)
    62 	{
    63 		KillFireBomb(i);
    64 	}
    65 }
    66 
    67 PerformBurn(client, target, Float:seconds)
    68 {
    69 	IgniteEntity(target, seconds);
    70 	LogAction(client, target, "\"%L\" ignited \"%L\" (seconds \"%f\")", client, target, seconds);
    71 }
    72 
    73 PerformFireBomb(client, target)
    74 {
    75 	if (g_FireBombSerial[client] == 0)
    76 	{
    77 		CreateFireBomb(target);
    78 		LogAction(client, target, "\"%L\" set a FireBomb on \"%L\"", client, target);
    79 	}
    80 	else
    81 	{
    82 		KillFireBomb(target);
    83 		SetEntityRenderColor(client, 255, 255, 255, 255);
    84 		LogAction(client, target, "\"%L\" removed a FireBomb on \"%L\"", client, target);
    85 	}
    86 }
    87 
    88 public Action:Timer_FireBomb(Handle:timer, any:value)
    89 {
    90 	new client = value & 0x7f;
    91 	new serial = value >> 7;
    92 
    93 	if (!IsClientInGame(client)
    94 		|| !IsPlayerAlive(client)
    95 		|| g_FireBombSerial[client] != serial)
    96 	{
    97 		KillFireBomb(client);
    98 		return Plugin_Stop;
    99 	}	
   100 	g_FireBombTime[client]--;
   101 	
   102 	new Float:vec[3];
   103 	GetClientEyePosition(client, vec);
   104 	
   105 	if (g_FireBombTime[client] > 0)
   106 	{
   107 		new color;
   108 		
   109 		if (g_FireBombTime[client] > 1)
   110 		{
   111 			color = RoundToFloor(g_FireBombTime[client] * (255.0 / GetConVarFloat(g_Cvar_FireBombTicks)));
   112 			if (g_BeepSound[0])
   113 			{
   114 				EmitAmbientSound(g_BeepSound, vec, client, SNDLEVEL_RAIDSIREN);	
   115 			}
   116 		}
   117 		else
   118 		{
   119 			color = 0;
   120 			if (g_FinalSound[0])
   121 			{
   122 				EmitAmbientSound(g_FinalSound, vec, client, SNDLEVEL_RAIDSIREN);
   123 			}
   124 		}
   125 		
   126 		SetEntityRenderColor(client, 255, color, color, 255);
   127 
   128 		decl String:name[64];
   129 		GetClientName(client, name, sizeof(name));
   130 		PrintCenterTextAll("%t", "Till Explodes", name, g_FireBombTime[client]);		
   131 		
   132 		if (g_BeamSprite > -1 && g_HaloSprite > -1)
   133 		{
   134 			GetClientAbsOrigin(client, vec);
   135 			vec[2] += 10;
   136 
   137 			TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_FireBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greyColor, 10, 0);
   138 			TE_SendToAll();
   139 			TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_FireBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, whiteColor, 10, 0);
   140 			TE_SendToAll();
   141 		}
   142 		return Plugin_Continue;
   143 	}
   144 	else
   145 	{
   146 		if (g_ExplosionSprite > -1)
   147 		{
   148 			TE_SetupExplosion(vec, g_ExplosionSprite, 0.1, 1, 0, GetConVarInt(g_Cvar_FireBombRadius), 5000);
   149 			TE_SendToAll();
   150 		}
   151 		
   152 		if (g_BeamSprite > -1 && g_HaloSprite > -1)
   153 		{
   154 			GetClientAbsOrigin(client, vec);
   155 			vec[2] += 10;
   156 			TE_SetupBeamRingPoint(vec, 50.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.5, 30.0, 1.5, orangeColor, 5, 0);
   157 			TE_SendToAll();
   158 			vec[2] += 15;
   159 			TE_SetupBeamRingPoint(vec, 40.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 30.0, 1.5, orangeColor, 5, 0);
   160 			TE_SendToAll();	
   161 			vec[2] += 15;
   162 			TE_SetupBeamRingPoint(vec, 30.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.7, 30.0, 1.5, orangeColor, 5, 0);
   163 			TE_SendToAll();
   164 			vec[2] += 15;
   165 			TE_SetupBeamRingPoint(vec, 20.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.8, 30.0, 1.5, orangeColor, 5, 0);
   166 			TE_SendToAll();		
   167 		}
   168 		
   169 		if (g_BoomSound[0])
   170 		{
   171 			EmitAmbientSound(g_BoomSound, vec, client, SNDLEVEL_RAIDSIREN);
   172 		}
   173 
   174 		IgniteEntity(client, GetConVarFloat(g_Cvar_BurnDuration));
   175 		KillFireBomb(client);
   176 		SetEntityRenderColor(client, 255, 255, 255, 255);
   177 		
   178 		if (GetConVarInt(g_Cvar_FireBombMode) > 0)
   179 		{
   180 			new teamOnly = ((GetConVarInt(g_Cvar_FireBombMode) == 1) ? true : false);
   181 			
   182 			for (new i = 1; i <= MaxClients; i++)
   183 			{
   184 				if (!IsClientInGame(i) || !IsPlayerAlive(i) || i == client)
   185 				{
   186 					continue;
   187 				}
   188 				
   189 				if (teamOnly && GetClientTeam(i) != GetClientTeam(client))
   190 				{
   191 					continue;
   192 				}
   193 				
   194 				new Float:pos[3];
   195 				GetClientAbsOrigin(i, pos);
   196 				
   197 				new Float:distance = GetVectorDistance(vec, pos);
   198 				
   199 				if (distance > GetConVarFloat(g_Cvar_FireBombRadius))
   200 				{
   201 					continue;
   202 				}
   203 				
   204 				new Float:duration = GetConVarFloat(g_Cvar_BurnDuration);
   205 				duration *= (GetConVarFloat(g_Cvar_FireBombRadius) - distance) / GetConVarFloat(g_Cvar_FireBombRadius);
   206 
   207 				IgniteEntity(i, duration);
   208 			}		
   209 		}
   210 		return Plugin_Stop;
   211 	}
   212 }
   213 
   214 public AdminMenu_Burn(Handle:topmenu, 
   215 					  TopMenuAction:action,
   216 					  TopMenuObject:object_id,
   217 					  param,
   218 					  String:buffer[],
   219 					  maxlength)
   220 {
   221 	if (action == TopMenuAction_DisplayOption)
   222 	{
   223 		Format(buffer, maxlength, "%T", "Burn player", param);
   224 	}
   225 	else if (action == TopMenuAction_SelectOption)
   226 	{
   227 		DisplayBurnMenu(param);
   228 	}
   229 }
   230 
   231 public AdminMenu_FireBomb(Handle:topmenu, 
   232 					  TopMenuAction:action,
   233 					  TopMenuObject:object_id,
   234 					  param,
   235 					  String:buffer[],
   236 					  maxlength)
   237 {
   238 	if (action == TopMenuAction_DisplayOption)
   239 	{
   240 		Format(buffer, maxlength, "%T", "FireBomb player", param);
   241 	}
   242 	else if (action == TopMenuAction_SelectOption)
   243 	{
   244 		DisplayFireBombMenu(param);
   245 	}
   246 }
   247 
   248 DisplayBurnMenu(client)
   249 {
   250 	new Handle:menu = CreateMenu(MenuHandler_Burn);
   251 	
   252 	decl String:title[100];
   253 	Format(title, sizeof(title), "%T:", "Burn player", client);
   254 	SetMenuTitle(menu, title);
   255 	SetMenuExitBackButton(menu, true);
   256 	
   257 	AddTargetsToMenu(menu, client, true, true);
   258 	
   259 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   260 }
   261 
   262 DisplayFireBombMenu(client)
   263 {
   264 	new Handle:menu = CreateMenu(MenuHandler_FireBomb);
   265 	
   266 	decl String:title[100];
   267 	Format(title, sizeof(title), "%T:", "FireBomb player", client);
   268 	SetMenuTitle(menu, title);
   269 	SetMenuExitBackButton(menu, true);
   270 	
   271 	AddTargetsToMenu(menu, client, true, true);
   272 	
   273 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   274 }
   275 
   276 public MenuHandler_Burn(Handle:menu, MenuAction:action, param1, param2)
   277 {
   278 	if (action == MenuAction_End)
   279 	{
   280 		CloseHandle(menu);
   281 	}
   282 	else if (action == MenuAction_Cancel)
   283 	{
   284 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   285 		{
   286 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   287 		}
   288 	}
   289 	else if (action == MenuAction_Select)
   290 	{
   291 		decl String:info[32];
   292 		new userid, target;
   293 		
   294 		GetMenuItem(menu, param2, info, sizeof(info));
   295 		userid = StringToInt(info);
   296 
   297 		if ((target = GetClientOfUserId(userid)) == 0)
   298 		{
   299 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   300 		}
   301 		else if (!CanUserTarget(param1, target))
   302 		{
   303 			PrintToChat(param1, "[SM] %t", "Unable to target");
   304 		}
   305 		else
   306 		{
   307 			new String:name[32];
   308 			GetClientName(target, name, sizeof(name));
   309 			PerformBurn(param1, target, 20.0);
   310 			ShowActivity2(param1, "[SM] ", "%t", "Set target on fire", "_s", name);
   311 		}
   312 		
   313 		/* Re-draw the menu if they're still valid */
   314 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   315 		{
   316 			DisplayBurnMenu(param1);
   317 		}
   318 	}
   319 }
   320 
   321 public MenuHandler_FireBomb(Handle:menu, MenuAction:action, param1, param2)
   322 {
   323 	if (action == MenuAction_End)
   324 	{
   325 		CloseHandle(menu);
   326 	}
   327 	else if (action == MenuAction_Cancel)
   328 	{
   329 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   330 		{
   331 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   332 		}
   333 	}
   334 	else if (action == MenuAction_Select)
   335 	{
   336 		decl String:info[32];
   337 		new userid, target;
   338 		
   339 		GetMenuItem(menu, param2, info, sizeof(info));
   340 		userid = StringToInt(info);
   341 
   342 		if ((target = GetClientOfUserId(userid)) == 0)
   343 		{
   344 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   345 		}
   346 		else if (!CanUserTarget(param1, target))
   347 		{
   348 			PrintToChat(param1, "[SM] %t", "Unable to target");
   349 		}
   350 		else
   351 		{
   352 			new String:name[32];
   353 			GetClientName(target, name, sizeof(name));
   354 			
   355 			PerformFireBomb(param1, target);
   356 			ShowActivity2(param1, "[SM] ", "%t", "Toggled FireBomb on target", "_s", name);
   357 		}
   358 		
   359 		/* Re-draw the menu if they're still valid */
   360 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   361 		{
   362 			DisplayFireBombMenu(param1);
   363 		}
   364 	}
   365 }
   366 
   367 public Action:Command_Burn(client, args)
   368 {
   369 	if (args < 1)
   370 	{
   371 		ReplyToCommand(client, "[SM] Usage: sm_burn <#userid|name> [time]");
   372 		return Plugin_Handled;
   373 	}
   374 
   375 	decl String:arg[65];
   376 	GetCmdArg(1, arg, sizeof(arg));
   377 
   378 	new Float:seconds = GetConVarFloat(g_Cvar_BurnDuration);
   379 	
   380 	if (args > 1)
   381 	{
   382 		decl String:time[20];
   383 		GetCmdArg(2, time, sizeof(time));
   384 		if (StringToFloatEx(time, seconds) == 0)
   385 		{
   386 			ReplyToCommand(client, "[SM] %t", "Invalid Amount");
   387 			return Plugin_Handled;
   388 		}
   389 	}
   390 	
   391 	decl String:target_name[MAX_TARGET_LENGTH];
   392 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   393 	
   394 	if ((target_count = ProcessTargetString(
   395 			arg,
   396 			client,
   397 			target_list,
   398 			MAXPLAYERS,
   399 			COMMAND_FILTER_ALIVE,
   400 			target_name,
   401 			sizeof(target_name),
   402 			tn_is_ml)) <= 0)
   403 	{
   404 		ReplyToTargetError(client, target_count);
   405 		return Plugin_Handled;
   406 	}
   407 	
   408 	for (new i = 0; i < target_count; i++)
   409 	{
   410 		PerformBurn(client, target_list[i], seconds);
   411 	}
   412 	
   413 	if (tn_is_ml)
   414 	{
   415 		ShowActivity2(client, "[SM] ", "%t", "Set target on fire", target_name);
   416 	}
   417 	else
   418 	{
   419 		ShowActivity2(client, "[SM] ", "%t", "Set target on fire", "_s", target_name);
   420 	}
   421 
   422 	return Plugin_Handled;
   423 }
   424 
   425 public Action:Command_FireBomb(client, args)
   426 {
   427 	if (args < 1)
   428 	{
   429 		ReplyToCommand(client, "[SM] Usage: sm_firebomb <#userid|name>");
   430 		return Plugin_Handled;
   431 	}
   432 
   433 	decl String:arg[65];
   434 	GetCmdArg(1, arg, sizeof(arg));
   435 
   436 	decl String:target_name[MAX_TARGET_LENGTH];
   437 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   438 	
   439 	if ((target_count = ProcessTargetString(
   440 			arg,
   441 			client,
   442 			target_list,
   443 			MAXPLAYERS,
   444 			COMMAND_FILTER_ALIVE,
   445 			target_name,
   446 			sizeof(target_name),
   447 			tn_is_ml)) <= 0)
   448 	{
   449 		ReplyToTargetError(client, target_count);
   450 		return Plugin_Handled;
   451 	}
   452 	
   453 	for (new i = 0; i < target_count; i++)
   454 	{
   455 		PerformFireBomb(client, target_list[i]);
   456 	}
   457 	
   458 	if (tn_is_ml)
   459 	{
   460 		ShowActivity2(client, "[SM] ", "%t", "Toggled FireBomb on target", target_name);
   461 	}
   462 	else
   463 	{
   464 		ShowActivity2(client, "[SM] ", "%t", "Toggled FireBomb on target", "_s", target_name);
   465 	}	
   466 	return Plugin_Handled;
   467 }
   468 
   469 
   470 
   471 
   472 
   473