plugins/funcommands/beacon.sp
changeset 1889 5b4d6acc4d82
child 1947 e73a1e51833b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/funcommands/beacon.sp	Fri Feb 22 21:01:08 2008 +0000
     1.3 @@ -0,0 +1,280 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basefuncommands Plugin
     1.8 + * Provides beacon 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 Handle:g_BeaconTimers[MAXPLAYERS+1];
    1.38 +
    1.39 +new Handle:g_BeaconRadius = INVALID_HANDLE;
    1.40 +
    1.41 +SetupBeacon()
    1.42 +{
    1.43 +	RegAdminCmd("sm_beacon", Command_Beacon, ADMFLAG_SLAY, "sm_beacon <#userid|name> [0/1]");
    1.44 +	
    1.45 +	g_BeaconRadius = CreateConVar("sm_beacon_radius", "375", "Sets the radius for beacon's light rings.", 0, true, 50.0, true, 1500.0);
    1.46 +}
    1.47 +
    1.48 +CreateBeacon(client)
    1.49 +{
    1.50 +	g_BeaconTimers[client] = CreateTimer(2.0, Timer_Beacon, client, TIMER_REPEAT);	
    1.51 +}
    1.52 +
    1.53 +KillBeacon(client)
    1.54 +{
    1.55 +	KillTimer(g_BeaconTimers[client]);
    1.56 +	g_BeaconTimers[client] = INVALID_HANDLE;
    1.57 +}
    1.58 +
    1.59 +KillAllBeacons()
    1.60 +{
    1.61 +	new maxclients = GetMaxClients();
    1.62 +	for (new i = 1; i <= maxclients; i++)
    1.63 +	{
    1.64 +		if (g_BeaconTimers[i] != INVALID_HANDLE)
    1.65 +		{
    1.66 +			KillBeacon(i);
    1.67 +		}
    1.68 +	}
    1.69 +}
    1.70 +
    1.71 +PerformBeacon(client, target, toggle)
    1.72 +{
    1.73 +	switch (toggle)
    1.74 +	{
    1.75 +		case (2):
    1.76 +		{
    1.77 +			if (g_BeaconTimers[target] == INVALID_HANDLE)
    1.78 +			{
    1.79 +				CreateBeacon(target);
    1.80 +				LogAction(client, target, "\"%L\" set a beacon on \"%L\"", client, target);
    1.81 +			}
    1.82 +			else
    1.83 +			{
    1.84 +				KillBeacon(target);
    1.85 +				LogAction(client, target, "\"%L\" removed a beacon on \"%L\"", client, target);
    1.86 +			}			
    1.87 +		}
    1.88 +
    1.89 +		case (1):
    1.90 +		{
    1.91 +			if (g_BeaconTimers[target] == INVALID_HANDLE)
    1.92 +			{
    1.93 +				CreateBeacon(target);
    1.94 +				LogAction(client, target, "\"%L\" set a beacon on \"%L\"", client, target);
    1.95 +			}			
    1.96 +		}
    1.97 +		
    1.98 +		case (0):
    1.99 +		{
   1.100 +			if (g_BeaconTimers[target] != INVALID_HANDLE)
   1.101 +			{
   1.102 +				KillBeacon(target);
   1.103 +				LogAction(client, target, "\"%L\" removed a beacon on \"%L\"", client, target);
   1.104 +			}			
   1.105 +		}
   1.106 +	}
   1.107 +}
   1.108 +
   1.109 +public Action:Timer_Beacon(Handle:timer, any:client)
   1.110 +{
   1.111 +	if (!IsClientInGame(client) || !IsPlayerAlive(client))
   1.112 +	{
   1.113 +		KillBeacon(client);		
   1.114 +
   1.115 +		return Plugin_Handled;
   1.116 +	}
   1.117 +	
   1.118 +	new team = GetClientTeam(client);
   1.119 +
   1.120 +	new Float:vec[3];
   1.121 +	GetClientAbsOrigin(client, vec);
   1.122 +	vec[2] += 10;
   1.123 +
   1.124 +	TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greyColor, 10, 0);
   1.125 +	TE_SendToAll();
   1.126 +	
   1.127 +	if (team == 2)
   1.128 +	{
   1.129 +		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, redColor, 10, 0);
   1.130 +	}
   1.131 +	else if (team == 3)
   1.132 +	{
   1.133 +		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, blueColor, 10, 0);
   1.134 +	}
   1.135 +	else
   1.136 +	{
   1.137 +		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, greenColor, 10, 0);
   1.138 +	}
   1.139 +	
   1.140 +	TE_SendToAll();
   1.141 +		
   1.142 +	GetClientEyePosition(client, vec);
   1.143 +	EmitAmbientSound(SOUND_BLIP, vec, client, SNDLEVEL_RAIDSIREN);	
   1.144 +		
   1.145 +	return Plugin_Handled;
   1.146 +}
   1.147 +
   1.148 +public AdminMenu_Beacon(Handle:topmenu, 
   1.149 +					  TopMenuAction:action,
   1.150 +					  TopMenuObject:object_id,
   1.151 +					  param,
   1.152 +					  String:buffer[],
   1.153 +					  maxlength)
   1.154 +{
   1.155 +	if (action == TopMenuAction_DisplayOption)
   1.156 +	{
   1.157 +		Format(buffer, maxlength, "%T", "Beacon player", param);
   1.158 +	}
   1.159 +	else if (action == TopMenuAction_SelectOption)
   1.160 +	{
   1.161 +		DisplayBeaconMenu(param);
   1.162 +	}
   1.163 +}
   1.164 +
   1.165 +DisplayBeaconMenu(client)
   1.166 +{
   1.167 +	new Handle:menu = CreateMenu(MenuHandler_Beacon);
   1.168 +	
   1.169 +	decl String:title[100];
   1.170 +	Format(title, sizeof(title), "%T:", "Beacon player", client);
   1.171 +	SetMenuTitle(menu, title);
   1.172 +	SetMenuExitBackButton(menu, true);
   1.173 +	
   1.174 +	AddTargetsToMenu(menu, client, true, true);
   1.175 +	
   1.176 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   1.177 +}
   1.178 +
   1.179 +public MenuHandler_Beacon(Handle:menu, MenuAction:action, param1, param2)
   1.180 +{
   1.181 +	if (action == MenuAction_End)
   1.182 +	{
   1.183 +		CloseHandle(menu);
   1.184 +	}
   1.185 +	else if (action == MenuAction_Cancel)
   1.186 +	{
   1.187 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.188 +		{
   1.189 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.190 +		}
   1.191 +	}
   1.192 +	else if (action == MenuAction_Select)
   1.193 +	{
   1.194 +		decl String:info[32];
   1.195 +		new userid, target;
   1.196 +		
   1.197 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.198 +		userid = StringToInt(info);
   1.199 +
   1.200 +		if ((target = GetClientOfUserId(userid)) == 0)
   1.201 +		{
   1.202 +			PrintToChat(param1, "[SM] %t", "Player no longer available");
   1.203 +		}
   1.204 +		else if (!CanUserTarget(param1, target))
   1.205 +		{
   1.206 +			PrintToChat(param1, "[SM] %t", "Unable to target");
   1.207 +		}
   1.208 +		else
   1.209 +		{
   1.210 +			new String:name[32];
   1.211 +			GetClientName(target, name, sizeof(name));
   1.212 +			
   1.213 +			PerformBeacon(param1, target, 2);
   1.214 +			ShowActivity2(param1, "[SM] ", "%t", "Toggled beacon on target", "_s", name);
   1.215 +		}
   1.216 +		
   1.217 +		/* Re-draw the menu if they're still valid */
   1.218 +		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   1.219 +		{
   1.220 +			DisplayBeaconMenu(param1);
   1.221 +		}
   1.222 +	}
   1.223 +}
   1.224 +
   1.225 +public Action:Command_Beacon(client, args)
   1.226 +{
   1.227 +	if (args < 1)
   1.228 +	{
   1.229 +		ReplyToCommand(client, "[SM] Usage: sm_beacon <#userid|name> [0/1]");
   1.230 +		return Plugin_Handled;
   1.231 +	}
   1.232 +
   1.233 +	decl String:arg[65];
   1.234 +	GetCmdArg(1, arg, sizeof(arg));
   1.235 +	
   1.236 +	new toggle = 2;
   1.237 +	if (args > 1)
   1.238 +	{
   1.239 +		decl String:arg2[2];
   1.240 +		GetCmdArg(2, arg2, sizeof(arg2));
   1.241 +		if (arg2[0])
   1.242 +		{
   1.243 +			toggle = 1;
   1.244 +		}
   1.245 +		else
   1.246 +		{
   1.247 +			toggle = 0;
   1.248 +		}
   1.249 +	}
   1.250 +
   1.251 +	decl String:target_name[MAX_TARGET_LENGTH];
   1.252 +	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   1.253 +	
   1.254 +	if ((target_count = ProcessTargetString(
   1.255 +			arg,
   1.256 +			client,
   1.257 +			target_list,
   1.258 +			MAXPLAYERS,
   1.259 +			COMMAND_FILTER_ALIVE,
   1.260 +			target_name,
   1.261 +			sizeof(target_name),
   1.262 +			tn_is_ml)) <= 0)
   1.263 +	{
   1.264 +		ReplyToTargetError(client, target_count);
   1.265 +		return Plugin_Handled;
   1.266 +	}
   1.267 +	
   1.268 +	for (new i = 0; i < target_count; i++)
   1.269 +	{
   1.270 +		PerformBeacon(client, target_list[i], toggle);
   1.271 +	}
   1.272 +	
   1.273 +	if (tn_is_ml)
   1.274 +	{
   1.275 +		ShowActivity2(client, "[SM] ", "%t", "Toggled beacon on target", target_name);
   1.276 +	}
   1.277 +	else
   1.278 +	{
   1.279 +		ShowActivity2(client, "[SM] ", "%t", "Toggled beacon on target", "_s", target_name);
   1.280 +	}
   1.281 +	
   1.282 +	return Plugin_Handled;
   1.283 +}