plugins/basefuncommands.sp
author David Anderson <dvander@alliedmods.net>
Sat Dec 22 08:57:08 2007 +0000 (2007-12-22)
changeset 1813 372939c88bc7
parent 1801 06ff8ce94b2b
child 1821 214e212a8c04
permissions -rw-r--r--
fixed amb1305 by making OnClientPostAdminCheck() always occur after OnClientPutInServer(). this is now GUARANTEED. it was undefined before, however the usual case was opposite. if plugins were relying on this, they were written poorly and shouldn't have worked in the first place, especially with the threaded SQL plugin.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basic Fun Commands Plugin
     5  * Implements basic punishment commands.
     6  *
     7  * SourceMod (C)2004-2007 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 #pragma semicolon 1
    35 
    36 #include <sourcemod>
    37 #include <sdktools>
    38 #undef REQUIRE_PLUGIN
    39 #include <adminmenu>
    40 
    41 public Plugin:myinfo =
    42 {
    43 	name = "Basic Fun Commands",
    44 	author = "AlliedModders LLC",
    45 	description = "Basic Fun Commands",
    46 	version = SOURCEMOD_VERSION,
    47 	url = "http://www.sourcemod.net/"
    48 };
    49 
    50 new Handle:hTopMenu = INVALID_HANDLE;
    51 
    52 // Sounds
    53 #define SOUND_BLIP		"buttons/blip1.wav"
    54 #define SOUND_BEEP		"buttons/button17.wav"
    55 #define SOUND_FINAL		"weapons/cguard/charging.wav"
    56 #define SOUND_BOOM		"weapons/explode3.wav"
    57 #define SOUND_FREEZE		"physics/glass/glass_impact_bullet4.wav"
    58 
    59 // Following are model indexes for temp entities
    60 new g_BeamSprite;
    61 new g_BeamSprite2;
    62 new g_HaloSprite;
    63 new g_GlowSprite;
    64 new g_ExplosionSprite;
    65 
    66 // Basic color arrays for temp entities
    67 new redColor[4] = {255, 75, 75, 255};
    68 new orangeColor[4] = {255, 128, 0, 255};
    69 new greenColor[4] = {75, 255, 75, 255};
    70 new blueColor[4] = {75, 75, 255, 255};
    71 new whiteColor[4] = {255, 255, 255, 255};
    72 new greyColor[4] = {128, 128, 128, 255};
    73 
    74 // Used for some trace rays.
    75 /*
    76 new g_FilteredEntity = -1;
    77 public bool:TR_Filter_Client(ent, contentMask)
    78 {
    79    return (ent == g_FilteredEntity) ? false : true;
    80 }
    81 */
    82 
    83 // Include various commands and supporting functions
    84 #include "basefuncommands/beacon.sp"
    85 #include "basefuncommands/timebomb.sp"
    86 #include "basefuncommands/fire.sp"
    87 #include "basefuncommands/ice.sp"
    88 
    89 public OnPluginStart()
    90 {
    91 	LoadTranslations("common.phrases");
    92 	LoadTranslations("basefuncommands.phrases");
    93 
    94 	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
    95 
    96 	HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);	
    97 
    98 	SetupBeacon();		// sm_beacon
    99 	SetupTimeBomb();	// sm_timebomb
   100 	SetupFire();		// sm_burn and sm_firebomb
   101 	SetupIce();			// sm_freeze and sm_freezebomb
   102 	
   103 	AutoExecConfig(true, "funcommands");
   104 	
   105 	/* Account for late loading */
   106 	new Handle:topmenu;
   107 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
   108 	{
   109 		OnAdminMenuReady(topmenu);
   110 	}
   111 }
   112 
   113 public OnMapStart()
   114 {
   115 	PrecacheSound(SOUND_BLIP, true);
   116 	PrecacheSound(SOUND_BEEP, true);
   117 	PrecacheSound(SOUND_FINAL, true);
   118 	PrecacheSound(SOUND_BOOM, true);
   119 	PrecacheSound(SOUND_FREEZE, true);
   120 
   121 	g_BeamSprite = PrecacheModel("materials/sprites/laser.vmt");
   122 	g_BeamSprite2 = PrecacheModel("sprites/bluelight1.vmt");
   123 	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");	
   124 	g_GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
   125 	g_ExplosionSprite = PrecacheModel("sprites/sprite_fire01.vmt");
   126 }
   127 
   128 public OnMapEnd()
   129 {
   130 	KillAllBeacons();
   131 	KillAllTimeBombs();
   132 	KillAllFireBombs();
   133 	KillAllFreezes();
   134 }
   135 
   136 public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
   137 {
   138 	KillAllBeacons();
   139 	KillAllTimeBombs();
   140 	KillAllFireBombs();
   141 	KillAllFreezes();
   142 	
   143 	return Plugin_Handled;
   144 }
   145 
   146 public OnAdminMenuReady(Handle:topmenu)
   147 {
   148 	/* Block us from being called twice */
   149 	if (topmenu == hTopMenu)
   150 	{
   151 		return;
   152 	}
   153 	
   154 	/* Save the Handle */
   155 	hTopMenu = topmenu;
   156 	
   157 	/* Find the "Player Commands" category */
   158 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   159 
   160 	if (player_commands != INVALID_TOPMENUOBJECT)
   161 	{
   162 		AddToTopMenu(hTopMenu,
   163 			"sm_beacon",
   164 			TopMenuObject_Item,
   165 			AdminMenu_Beacon,
   166 			player_commands,
   167 			"sm_beacon",
   168 			ADMFLAG_SLAY);
   169 		
   170 		AddToTopMenu(hTopMenu,
   171 			"sm_burn",
   172 			TopMenuObject_Item,
   173 			AdminMenu_Burn,
   174 			player_commands,
   175 			"sm_burn",
   176 			ADMFLAG_SLAY);
   177 			
   178 		AddToTopMenu(hTopMenu,
   179 			"sm_freeze",
   180 			TopMenuObject_Item,
   181 			AdminMenu_Freeze,
   182 			player_commands,
   183 			"sm_freeze",
   184 			ADMFLAG_SLAY);
   185 
   186 		AddToTopMenu(hTopMenu,
   187 			"sm_timebomb",
   188 			TopMenuObject_Item,
   189 			AdminMenu_TimeBomb,
   190 			player_commands,
   191 			"sm_timebomb",
   192 			ADMFLAG_SLAY);	
   193 			
   194 		AddToTopMenu(hTopMenu,
   195 			"sm_firebomb",
   196 			TopMenuObject_Item,
   197 			AdminMenu_FireBomb,
   198 			player_commands,
   199 			"sm_firebomb",
   200 			ADMFLAG_SLAY);
   201 			
   202 		AddToTopMenu(hTopMenu,
   203 			"sm_freezebomb",
   204 			TopMenuObject_Item,
   205 			AdminMenu_FreezeBomb,
   206 			player_commands,
   207 			"sm_freezebomb",
   208 			ADMFLAG_SLAY);
   209 	}
   210 }
   211 
   212 public Action:Command_Play(client, args)
   213 {
   214 	if (args < 2)
   215 	{
   216 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   217 	}
   218 
   219 	new String:Arguments[PLATFORM_MAX_PATH + 65];
   220 	GetCmdArgString(Arguments, sizeof(Arguments));
   221 
   222  	decl String:Arg[65];
   223 	new len = BreakString(Arguments, Arg, sizeof(Arg));
   224 
   225 	/* Make sure it does not go out of bound by doing "sm_play user  "*/
   226 	if (len == -1)
   227 	{
   228 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   229 		return Plugin_Handled;
   230 	}
   231 
   232 	/* Incase they put quotes and white spaces after the quotes */
   233 	if (Arguments[len] == '"')
   234 	{
   235 		len++;
   236 		new FileLen = TrimString(Arguments[len]) + len;
   237 
   238 		if (Arguments[FileLen - 1] == '"')
   239 		{
   240 			Arguments[FileLen - 1] = '\0';
   241 		}
   242 	}
   243 	
   244 	decl String:target_name[MAX_TARGET_LENGTH];
   245 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   246 	
   247 	if ((target_count = ProcessTargetString(
   248 			Arg,
   249 			client,
   250 			target_list,
   251 			MAXPLAYERS,
   252 			COMMAND_FILTER_NO_BOTS,
   253 			target_name,
   254 			sizeof(target_name),
   255 			tn_is_ml)) <= 0)
   256 	{
   257 		ReplyToTargetError(client, target_count);
   258 		return Plugin_Handled;
   259 	}
   260 	
   261 	for (new i = 0; i < target_count; i++)
   262 	{
   263 		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
   264 		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);
   265 	}
   266 	
   267 	if (tn_is_ml)
   268 	{
   269 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
   270 	}
   271 	else
   272 	{
   273 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
   274 	}
   275 
   276 	return Plugin_Handled;
   277 }