plugins/funcommands/beacon.sp
author Nicholas Hastings <skamonkey@gmail.com>
Wed Oct 06 20:46:29 2010 -0400 (2010-10-06)
changeset 3135 c85fb4eec281
parent 2920 1d5645ab7ae0
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 beacon 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_BeaconSerial[MAXPLAYERS+1] = { 0, ... };
    35 
    36 new Handle:g_Cvar_BeaconRadius = INVALID_HANDLE;
    37 
    38 CreateBeacon(client)
    39 {
    40 	g_BeaconSerial[client] = ++g_Serial_Gen;
    41 	CreateTimer(1.0, Timer_Beacon, client | (g_Serial_Gen << 7), DEFAULT_TIMER_FLAGS);	
    42 }
    43 
    44 KillBeacon(client)
    45 {
    46 	g_BeaconSerial[client] = 0;
    47 
    48 	if (IsClientInGame(client))
    49 	{
    50 		SetEntityRenderColor(client, 255, 255, 255, 255);
    51 	}
    52 }
    53 
    54 KillAllBeacons()
    55 {
    56 	for (new i = 1; i <= MaxClients; i++)
    57 	{
    58 		KillBeacon(i);
    59 	}
    60 }
    61 
    62 PerformBeacon(client, target)
    63 {
    64 	if (g_BeaconSerial[target] == 0)
    65 	{
    66 		CreateBeacon(target);
    67 		LogAction(client, target, "\"%L\" set a beacon on \"%L\"", client, target);
    68 	}
    69 	else
    70 	{
    71 		KillBeacon(target);
    72 		LogAction(client, target, "\"%L\" removed a beacon on \"%L\"", client, target);
    73 	}
    74 }
    75 
    76 public Action:Timer_Beacon(Handle:timer, any:value)
    77 {
    78 	new client = value & 0x7f;
    79 	new serial = value >> 7;
    80 
    81 	if (!IsClientInGame(client)
    82 		|| !IsPlayerAlive(client)
    83 		|| g_BeaconSerial[client] != serial)
    84 	{
    85 		KillBeacon(client);
    86 		return Plugin_Stop;
    87 	}
    88 	
    89 	new team = GetClientTeam(client);
    90 
    91 	new Float:vec[3];
    92 	GetClientAbsOrigin(client, vec);
    93 	vec[2] += 10;
    94 
    95 	TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 15, 0.5, 5.0, 0.0, greyColor, 10, 0);
    96 	TE_SendToAll();
    97 	
    98 	if (team == 2)
    99 	{
   100 		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, redColor, 10, 0);
   101 	}
   102 	else if (team == 3)
   103 	{
   104 		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, blueColor, 10, 0);
   105 	}
   106 	else
   107 	{
   108 		TE_SetupBeamRingPoint(vec, 10.0, GetConVarFloat(g_Cvar_BeaconRadius), g_BeamSprite, g_HaloSprite, 0, 10, 0.6, 10.0, 0.5, greenColor, 10, 0);
   109 	}
   110 	
   111 	TE_SendToAll();
   112 		
   113 	GetClientEyePosition(client, vec);
   114 	EmitAmbientSound(SOUND_BLIP, vec, client, SNDLEVEL_RAIDSIREN);	
   115 		
   116 	return Plugin_Continue;
   117 }
   118 
   119 public AdminMenu_Beacon(Handle:topmenu, 
   120 					  TopMenuAction:action,
   121 					  TopMenuObject:object_id,
   122 					  param,
   123 					  String:buffer[],
   124 					  maxlength)
   125 {
   126 	if (action == TopMenuAction_DisplayOption)
   127 	{
   128 		Format(buffer, maxlength, "%T", "Beacon player", param);
   129 	}
   130 	else if (action == TopMenuAction_SelectOption)
   131 	{
   132 		DisplayBeaconMenu(param);
   133 	}
   134 }
   135 
   136 DisplayBeaconMenu(client)
   137 {
   138 	new Handle:menu = CreateMenu(MenuHandler_Beacon);
   139 	
   140 	decl String:title[100];
   141 	Format(title, sizeof(title), "%T:", "Beacon player", client);
   142 	SetMenuTitle(menu, title);
   143 	SetMenuExitBackButton(menu, true);
   144 	
   145 	AddTargetsToMenu(menu, client, true, true);
   146 	
   147 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   148 }
   149 
   150 public MenuHandler_Beacon(Handle:menu, MenuAction:action, param1, param2)
   151 {
   152 	if (action == MenuAction_End)
   153 	{
   154 		CloseHandle(menu);
   155 	}
   156 	else if (action == MenuAction_Cancel)
   157 	{
   158 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   159 		{
   160 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   161 		}
   162 	}
   163 	else if (action == MenuAction_Select)
   164 	{
   165 		decl String:info[32];
   166 		new userid, target;
   167 		
   168 		GetMenuItem(menu, param2, info, sizeof(info));
   169 		userid = StringToInt(info);
   170 
   171 		if ((target = GetClientOfUserId(userid)) == 0)
   172 		{
   173 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   174 		}
   175 		else if (!CanUserTarget(param1, target))
   176 		{
   177 			PrintToChat(param1, "[SM] %t", "Unable to target");
   178 		}
   179 		else
   180 		{
   181 			new String:name[32];
   182 			GetClientName(target, name, sizeof(name));
   183 			
   184 			PerformBeacon(param1, target);
   185 			ShowActivity2(param1, "[SM] ", "%t", "Toggled beacon on target", "_s", name);
   186 		}
   187 		
   188 		/* Re-draw the menu if they're still valid */
   189 		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   190 		{
   191 			DisplayBeaconMenu(param1);
   192 		}
   193 	}
   194 }
   195 
   196 public Action:Command_Beacon(client, args)
   197 {
   198 	if (args < 1)
   199 	{
   200 		ReplyToCommand(client, "[SM] Usage: sm_beacon <#userid|name>");
   201 		return Plugin_Handled;
   202 	}
   203 
   204 	decl String:arg[65];
   205 	GetCmdArg(1, arg, sizeof(arg));
   206 
   207 	decl String:target_name[MAX_TARGET_LENGTH];
   208 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   209 	
   210 	if ((target_count = ProcessTargetString(
   211 			arg,
   212 			client,
   213 			target_list,
   214 			MAXPLAYERS,
   215 			COMMAND_FILTER_ALIVE,
   216 			target_name,
   217 			sizeof(target_name),
   218 			tn_is_ml)) <= 0)
   219 	{
   220 		ReplyToTargetError(client, target_count);
   221 		return Plugin_Handled;
   222 	}
   223 	
   224 	for (new i = 0; i < target_count; i++)
   225 	{
   226 		PerformBeacon(client, target_list[i]);
   227 	}
   228 	
   229 	if (tn_is_ml)
   230 	{
   231 		ShowActivity2(client, "[SM] ", "%t", "Toggled beacon on target", target_name);
   232 	}
   233 	else
   234 	{
   235 		ShowActivity2(client, "[SM] ", "%t", "Toggled beacon on target", "_s", target_name);
   236 	}
   237 	
   238 	return Plugin_Handled;
   239 }