plugins/funcommands/fire.sp
changeset 2501 73a73b6e0dc8
parent 2289 44045ead61cd
child 2810 2ceb5b2b0da0
     1.1 --- a/plugins/funcommands/fire.sp	Wed Dec 31 23:05:36 2008 -0500
     1.2 +++ b/plugins/funcommands/fire.sp	Wed Jan 07 19:21:54 2009 -0500
     1.3 @@ -31,116 +31,86 @@
     1.4   * Version: $Id$
     1.5   */
     1.6  
     1.7 -new Handle:g_FireBombTimers[MAXPLAYERS+1];
     1.8 -new g_FireBombTracker[MAXPLAYERS+1];
     1.9 -
    1.10 -new Handle:g_BurnDuration = INVALID_HANDLE;
    1.11 -new Handle:g_FireBombTicks = INVALID_HANDLE;
    1.12 -new Handle:g_FireBombRadius = INVALID_HANDLE;
    1.13 -new Handle:g_FireBombMode = INVALID_HANDLE;
    1.14 +new g_FireBombSerial[MAXPLAYERS+1] = { 0, ... };
    1.15 +new g_FireBombTime[MAXPLAYERS+1] = { 0, ... };
    1.16  
    1.17 -SetupFire()
    1.18 -{
    1.19 -	RegAdminCmd("sm_burn", Command_Burn, ADMFLAG_SLAY, "sm_burn <#userid|name> [time]");
    1.20 -	RegAdminCmd("sm_firebomb", Command_FireBomb, ADMFLAG_SLAY, "sm_firebomb <#userid|name> [0/1]");	
    1.21 -	
    1.22 -	g_BurnDuration = CreateConVar("sm_burn_duration", "20", "Sets the default duration of sm_burn and firebomb victims.", 0, true, 0.5, true, 20.0);
    1.23 -	g_FireBombTicks = CreateConVar("sm_firebomb_ticks", "10", "Sets how long the FireBomb fuse is.", 0, true, 5.0, true, 120.0);
    1.24 -	g_FireBombRadius = CreateConVar("sm_firebomb_radius", "600", "Sets the bomb blast radius.", 0, true, 50.0, true, 3000.0);
    1.25 -	g_FireBombMode = CreateConVar("sm_firebomb_mode", "0", "Who is targetted by the FireBomb? 0 = Target only, 1 = Target's team, 2 = Everyone", 0, true, 0.0, true, 2.0);
    1.26 -}
    1.27 +new Handle:g_Cvar_BurnDuration = INVALID_HANDLE;
    1.28 +new Handle:g_Cvar_FireBombTicks = INVALID_HANDLE;
    1.29 +new Handle:g_Cvar_FireBombRadius = INVALID_HANDLE;
    1.30 +new Handle:g_Cvar_FireBombMode = INVALID_HANDLE;
    1.31  
    1.32  CreateFireBomb(client)
    1.33  {
    1.34 -	g_FireBombTimers[client] = CreateTimer(1.0, Timer_FireBomb, client, TIMER_REPEAT);
    1.35 -	g_FireBombTracker[client] = GetConVarInt(g_FireBombTicks);
    1.36 +	g_FireBombSerial[client] = ++g_Serial_Gen;
    1.37 +	CreateTimer(1.0, Timer_FireBomb, client | (g_Serial_Gen << 7), DEFAULT_TIMER_FLAGS);
    1.38 +	g_FireBombTime[client] = GetConVarInt(g_Cvar_FireBombTicks);
    1.39  }
    1.40  
    1.41  KillFireBomb(client)
    1.42  {
    1.43 -	KillTimer(g_FireBombTimers[client]);
    1.44 -	g_FireBombTimers[client] = INVALID_HANDLE;
    1.45 +	g_FireBombSerial[client] = 0;
    1.46 +
    1.47 +	if (IsClientInGame(client))
    1.48 +	{
    1.49 +		SetEntityRenderColor(client, 255, 255, 255, 255);
    1.50 +	}
    1.51  }
    1.52  
    1.53  KillAllFireBombs()
    1.54  {
    1.55  	new maxclients = GetMaxClients();
    1.56 +
    1.57  	for (new i = 1; i <= maxclients; i++)
    1.58  	{
    1.59 -		if (g_FireBombTimers[i] != INVALID_HANDLE)
    1.60 -		{
    1.61 -			KillFireBomb(i);
    1.62 -		}
    1.63 +		KillFireBomb(i);
    1.64  	}
    1.65  }
    1.66  
    1.67  PerformBurn(client, target, Float:seconds)
    1.68  {
    1.69 +	IgniteEntity(target, seconds);
    1.70  	LogAction(client, target, "\"%L\" ignited \"%L\" (seconds \"%f\")", client, target, seconds);
    1.71 -	IgniteEntity(target, seconds);
    1.72  }
    1.73  
    1.74 -PerformFireBomb(client, target, toggle)
    1.75 +PerformFireBomb(client, target)
    1.76  {
    1.77 -	switch (toggle)
    1.78 +	if (g_FireBombSerial[client] == 0)
    1.79  	{
    1.80 -		case (2):
    1.81 -		{
    1.82 -			if (g_FireBombTimers[target] == INVALID_HANDLE)
    1.83 -			{
    1.84 -				CreateFireBomb(target);
    1.85 -				LogAction(client, target, "\"%L\" set a FireBomb on \"%L\"", client, target);
    1.86 -			}
    1.87 -			else
    1.88 -			{
    1.89 -				KillFireBomb(target);
    1.90 -				SetEntityRenderColor(client, 255, 255, 255, 255);
    1.91 -				LogAction(client, target, "\"%L\" removed a FireBomb on \"%L\"", client, target);
    1.92 -			}			
    1.93 -		}
    1.94 -
    1.95 -		case (1):
    1.96 -		{
    1.97 -			if (g_FireBombTimers[target] == INVALID_HANDLE)
    1.98 -			{
    1.99 -				CreateFireBomb(target);
   1.100 -				LogAction(client, target, "\"%L\" set a FireBomb on \"%L\"", client, target);
   1.101 -			}			
   1.102 -		}
   1.103 -		
   1.104 -		case (0):
   1.105 -		{
   1.106 -			if (g_FireBombTimers[target] != INVALID_HANDLE)
   1.107 -			{
   1.108 -				KillFireBomb(target);
   1.109 -				SetEntityRenderColor(client, 255, 255, 255, 255);
   1.110 -				LogAction(client, target, "\"%L\" removed a FireBomb on \"%L\"", client, target);
   1.111 -			}			
   1.112 -		}
   1.113 +		CreateFireBomb(target);
   1.114 +		LogAction(client, target, "\"%L\" set a FireBomb on \"%L\"", client, target);
   1.115 +	}
   1.116 +	else
   1.117 +	{
   1.118 +		KillFireBomb(target);
   1.119 +		SetEntityRenderColor(client, 255, 255, 255, 255);
   1.120 +		LogAction(client, target, "\"%L\" removed a FireBomb on \"%L\"", client, target);
   1.121  	}
   1.122  }
   1.123  
   1.124 -public Action:Timer_FireBomb(Handle:timer, any:client)
   1.125 +public Action:Timer_FireBomb(Handle:timer, any:value)
   1.126  {
   1.127 -	if (!IsClientInGame(client) || !IsPlayerAlive(client))
   1.128 +	new client = value & 0x7f;
   1.129 +	new serial = value >> 7;
   1.130 +
   1.131 +	if (!IsClientInGame(client)
   1.132 +		|| !IsPlayerAlive(client)
   1.133 +		|| g_FireBombSerial[client] != serial)
   1.134  	{
   1.135 -		KillFireBomb(client);		
   1.136 -
   1.137 -		return Plugin_Handled;
   1.138 -	}
   1.139 -	
   1.140 -	g_FireBombTracker[client]--;
   1.141 +		KillFireBomb(client);
   1.142 +		return Plugin_Stop;
   1.143 +	}	
   1.144 +	g_FireBombTime[client]--;
   1.145  	
   1.146  	new Float:vec[3];
   1.147  	GetClientEyePosition(client, vec);
   1.148  	
   1.149 -	if (g_FireBombTracker[client] > 0)
   1.150 +	if (g_FireBombTime[client] > 0)
   1.151  	{
   1.152  		new color;
   1.153  		
   1.154 -		if (g_FireBombTracker[client] > 1)
   1.155 +		if (g_FireBombTime[client] > 1)
   1.156  		{
   1.157 -			color = RoundToFloor(g_FireBombTracker[client] * (255.0 / GetConVarFloat(g_FireBombTicks)));
   1.158 +			color = RoundToFloor(g_FireBombTime[client] * (255.0 / GetConVarFloat(g_Cvar_FireBombTicks)));
   1.159  			EmitAmbientSound(SOUND_BEEP, vec, client, SNDLEVEL_RAIDSIREN);	
   1.160  		}
   1.161  		else
   1.162 @@ -153,44 +123,45 @@
   1.163  
   1.164  		decl String:name[64];
   1.165  		GetClientName(client, name, sizeof(name));
   1.166 -		PrintCenterTextAll("%t", "Till Explodes", name, g_FireBombTracker[client]);		
   1.167 +		PrintCenterTextAll("%t", "Till Explodes", name, g_FireBombTime[client]);		
   1.168  		
   1.169  		GetClientAbsOrigin(client, vec);
   1.170  		vec[2] += 10;
   1.171  
   1.172 -		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_FireBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greyColor, 10, 0);
   1.173 +		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);
   1.174  		TE_SendToAll();
   1.175 -		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_FireBombRadius) / 3.0, g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, whiteColor, 10, 0);
   1.176 +		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);
   1.177  		TE_SendToAll();
   1.178 +		return Plugin_Continue;
   1.179  	}
   1.180  	else
   1.181  	{
   1.182 -		TE_SetupExplosion(vec, g_ExplosionSprite, 0.1, 1, 0, GetConVarInt(g_FireBombRadius), 5000);
   1.183 +		TE_SetupExplosion(vec, g_ExplosionSprite, 0.1, 1, 0, GetConVarInt(g_Cvar_FireBombRadius), 5000);
   1.184  		TE_SendToAll();
   1.185  		
   1.186  		GetClientAbsOrigin(client, vec);
   1.187  		vec[2] += 10;
   1.188 -		TE_SetupBeamRingPoint(vec, 50.0, GetConVarFloat(g_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.5, 30.0, 1.5, orangeColor, 5, 0);
   1.189 +		TE_SetupBeamRingPoint(vec, 50.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.5, 30.0, 1.5, orangeColor, 5, 0);
   1.190  		TE_SendToAll();
   1.191  		vec[2] += 15;
   1.192 -		TE_SetupBeamRingPoint(vec, 40.0, GetConVarFloat(g_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 30.0, 1.5, orangeColor, 5, 0);
   1.193 +		TE_SetupBeamRingPoint(vec, 40.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 30.0, 1.5, orangeColor, 5, 0);
   1.194  		TE_SendToAll();	
   1.195  		vec[2] += 15;
   1.196 -		TE_SetupBeamRingPoint(vec, 30.0, GetConVarFloat(g_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.7, 30.0, 1.5, orangeColor, 5, 0);
   1.197 +		TE_SetupBeamRingPoint(vec, 30.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.7, 30.0, 1.5, orangeColor, 5, 0);
   1.198  		TE_SendToAll();
   1.199  		vec[2] += 15;
   1.200 -		TE_SetupBeamRingPoint(vec, 20.0, GetConVarFloat(g_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.8, 30.0, 1.5, orangeColor, 5, 0);
   1.201 +		TE_SetupBeamRingPoint(vec, 20.0, GetConVarFloat(g_Cvar_FireBombRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.8, 30.0, 1.5, orangeColor, 5, 0);
   1.202  		TE_SendToAll();		
   1.203  		
   1.204  		EmitAmbientSound(SOUND_BOOM, vec, client, SNDLEVEL_RAIDSIREN);
   1.205  
   1.206 -		IgniteEntity(client, GetConVarFloat(g_BurnDuration));
   1.207 +		IgniteEntity(client, GetConVarFloat(g_Cvar_BurnDuration));
   1.208  		KillFireBomb(client);
   1.209  		SetEntityRenderColor(client, 255, 255, 255, 255);
   1.210  		
   1.211 -		if (GetConVarInt(g_FireBombMode) > 0)
   1.212 +		if (GetConVarInt(g_Cvar_FireBombMode) > 0)
   1.213  		{
   1.214 -			new teamOnly = ((GetConVarInt(g_FireBombMode) == 1) ? true : false);
   1.215 +			new teamOnly = ((GetConVarInt(g_Cvar_FireBombMode) == 1) ? true : false);
   1.216  			new maxClients = GetMaxClients();
   1.217  			
   1.218  			for (new i = 1; i < maxClients; i++)
   1.219 @@ -210,20 +181,19 @@
   1.220  				
   1.221  				new Float:distance = GetVectorDistance(vec, pos);
   1.222  				
   1.223 -				if (distance > GetConVarFloat(g_FireBombRadius))
   1.224 +				if (distance > GetConVarFloat(g_Cvar_FireBombRadius))
   1.225  				{
   1.226  					continue;
   1.227  				}
   1.228  				
   1.229 -				new Float:duration = GetConVarFloat(g_BurnDuration);
   1.230 -				duration *= (GetConVarFloat(g_FireBombRadius) - distance) / GetConVarFloat(g_FireBombRadius);
   1.231 +				new Float:duration = GetConVarFloat(g_Cvar_BurnDuration);
   1.232 +				duration *= (GetConVarFloat(g_Cvar_FireBombRadius) - distance) / GetConVarFloat(g_Cvar_FireBombRadius);
   1.233  
   1.234  				IgniteEntity(i, duration);
   1.235  			}		
   1.236  		}
   1.237 +		return Plugin_Stop;
   1.238  	}
   1.239 -			
   1.240 -	return Plugin_Handled;
   1.241  }
   1.242  
   1.243  public AdminMenu_Burn(Handle:topmenu, 
   1.244 @@ -367,7 +337,7 @@
   1.245  			new String:name[32];
   1.246  			GetClientName(target, name, sizeof(name));
   1.247  			
   1.248 -			PerformFireBomb(param1, target, 2);
   1.249 +			PerformFireBomb(param1, target);
   1.250  			ShowActivity2(param1, "[SM] ", "%t", "Toggled FireBomb on target", "_s", name);
   1.251  		}
   1.252  		
   1.253 @@ -390,7 +360,7 @@
   1.254  	decl String:arg[65];
   1.255  	GetCmdArg(1, arg, sizeof(arg));
   1.256  
   1.257 -	new Float:seconds = GetConVarFloat(g_BurnDuration);
   1.258 +	new Float:seconds = GetConVarFloat(g_Cvar_BurnDuration);
   1.259  	
   1.260  	if (args > 1)
   1.261  	{
   1.262 @@ -441,27 +411,12 @@
   1.263  {
   1.264  	if (args < 1)
   1.265  	{
   1.266 -		ReplyToCommand(client, "[SM] Usage: sm_firebomb <#userid|name> [0/1]");
   1.267 +		ReplyToCommand(client, "[SM] Usage: sm_firebomb <#userid|name>");
   1.268  		return Plugin_Handled;
   1.269  	}
   1.270  
   1.271  	decl String:arg[65];
   1.272  	GetCmdArg(1, arg, sizeof(arg));
   1.273 -	
   1.274 -	new toggle = 2;
   1.275 -	if (args > 1)
   1.276 -	{
   1.277 -		decl String:arg2[2];
   1.278 -		GetCmdArg(2, arg2, sizeof(arg2));
   1.279 -		if (arg2[0])
   1.280 -		{
   1.281 -			toggle = 1;
   1.282 -		}
   1.283 -		else
   1.284 -		{
   1.285 -			toggle = 0;
   1.286 -		}
   1.287 -	}
   1.288  
   1.289  	decl String:target_name[MAX_TARGET_LENGTH];
   1.290  	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   1.291 @@ -482,7 +437,7 @@
   1.292  	
   1.293  	for (new i = 0; i < target_count; i++)
   1.294  	{
   1.295 -		PerformFireBomb(client, target_list[i], toggle);
   1.296 +		PerformFireBomb(client, target_list[i]);
   1.297  	}
   1.298  	
   1.299  	if (tn_is_ml)
   1.300 @@ -492,8 +447,7 @@
   1.301  	else
   1.302  	{
   1.303  		ShowActivity2(client, "[SM] ", "%t", "Toggled FireBomb on target", "_s", target_name);
   1.304 -	}
   1.305 -	
   1.306 +	}	
   1.307  	return Plugin_Handled;
   1.308  }
   1.309