plugins/basefuncommands.sp
author David Anderson <dvander@alliedmods.net>
Tue Jan 22 16:47:10 2008 +0000 (2008-01-22)
changeset 1853 b046cf080755
parent 1821 214e212a8c04
child 1863 d5d37955013f
permissions -rw-r--r--
fire requires timebomb
     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 // -------------------------------------------------------------------------------
    51 // Set any of these to 0 and recompile to completely disable those commands
    52 // -------------------------------------------------------------------------------
    53 #define BEACON		1
    54 #define TIMEBOMB	1
    55 #define FIRE		1
    56 #define ICE			1
    57 #define GRAVITY		1
    58 #define BLIND		1
    59 #define NOCLIP		1
    60 #define DRUG		1
    61 #define TELEPORT	1
    62 #define HEALTH		1
    63 #define COLORS		1
    64 #define CASH		1
    65 // -------------------------------------------------------------------------------
    66 
    67 /**
    68  * Fire requires timebomb
    69  */
    70 #if TIMEBOMB == 0 && FIRE == 1
    71 #error "TimeBomb requires Fire"
    72 #endif
    73 
    74 new Handle:hTopMenu = INVALID_HANDLE;
    75 
    76 // Sounds
    77 #define SOUND_BLIP		"buttons/blip1.wav"
    78 #define SOUND_BEEP		"buttons/button17.wav"
    79 #define SOUND_FINAL		"weapons/cguard/charging.wav"
    80 #define SOUND_BOOM		"weapons/explode3.wav"
    81 #define SOUND_FREEZE		"physics/glass/glass_impact_bullet4.wav"
    82 
    83 // Following are model indexes for temp entities
    84 new g_BeamSprite;
    85 new g_BeamSprite2;
    86 new g_HaloSprite;
    87 new g_GlowSprite;
    88 new g_ExplosionSprite;
    89 
    90 // Basic color arrays for temp entities
    91 new redColor[4] = {255, 75, 75, 255};
    92 new orangeColor[4] = {255, 128, 0, 255};
    93 new greenColor[4] = {75, 255, 75, 255};
    94 new blueColor[4] = {75, 75, 255, 255};
    95 new whiteColor[4] = {255, 255, 255, 255};
    96 new greyColor[4] = {128, 128, 128, 255};
    97 
    98 // UserMessageId for Fade.
    99 new UserMsg:g_FadeUserMsgId;
   100 
   101 // Include various commands and supporting functions
   102 #if BEACON
   103 #include "basefuncommands/beacon.sp"
   104 #endif
   105 #if TIMEBOMB
   106 #include "basefuncommands/timebomb.sp"
   107 #endif
   108 #if FIRE
   109 #include "basefuncommands/fire.sp"
   110 #endif
   111 #if ICE
   112 #include "basefuncommands/ice.sp"
   113 #endif
   114 #if GRAVITY
   115 #include "basefuncommands/gravity.sp"
   116 #endif
   117 #if BLIND
   118 #include "basefuncommands/blind.sp"
   119 #endif
   120 #if NOCLIP
   121 #include "basefuncommands/noclip.sp"
   122 #endif
   123 #if DRUG
   124 #include "basefuncommands/drug.sp"
   125 #endif
   126 
   127 public OnPluginStart()
   128 {
   129 	LoadTranslations("common.phrases");
   130 	LoadTranslations("basefuncommands.phrases");
   131 
   132 	g_FadeUserMsgId = GetUserMessageId("Fade");
   133 	
   134 	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
   135 
   136 	HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);	
   137 
   138 	#if BEACON
   139 	SetupBeacon();		// sm_beacon
   140 	#endif
   141 	
   142 	#if TIMEBOMB
   143 	SetupTimeBomb();	// sm_timebomb
   144 	#endif
   145 	
   146 	#if FIRE
   147 	SetupFire();		// sm_burn and sm_firebomb
   148 	#endif
   149 	
   150 	#if ICE
   151 	SetupIce();			// sm_freeze and sm_freezebomb
   152 	#endif
   153 	
   154 	#if GRAVITY
   155 	SetupGravity();		// sm_gravity
   156 	#endif
   157 	
   158 	#if BLIND
   159 	SetupBlind();		// sm_blind
   160 	#endif
   161 	
   162 	#if NOCLIP
   163 	SetupNoClip();		// sm_noclip
   164 	#endif
   165 	
   166 	#if DRUG
   167 	SetupDrugs();		// sm_drug
   168 	#endif
   169 	
   170 	AutoExecConfig(true, "funcommands");
   171 	
   172 	/* Account for late loading */
   173 	new Handle:topmenu;
   174 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
   175 	{
   176 		OnAdminMenuReady(topmenu);
   177 	}
   178 }
   179 
   180 public OnMapStart()
   181 {
   182 	PrecacheSound(SOUND_BLIP, true);
   183 	PrecacheSound(SOUND_BEEP, true);
   184 	PrecacheSound(SOUND_FINAL, true);
   185 	PrecacheSound(SOUND_BOOM, true);
   186 	PrecacheSound(SOUND_FREEZE, true);
   187 
   188 	g_BeamSprite = PrecacheModel("materials/sprites/laser.vmt");
   189 	g_BeamSprite2 = PrecacheModel("sprites/bluelight1.vmt");
   190 	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");	
   191 	g_GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
   192 	g_ExplosionSprite = PrecacheModel("sprites/sprite_fire01.vmt");
   193 }
   194 
   195 public OnMapEnd()
   196 {
   197 	#if BEACON
   198 	KillAllBeacons();
   199 	#endif
   200 	#if TIMEBOMB
   201 	KillAllTimeBombs();
   202 	#endif
   203 	#if FIRE
   204 	KillAllFireBombs();
   205 	#endif
   206 	#if ICE
   207 	KillAllFreezes();
   208 	#endif
   209 	#if DRUG
   210 	KillAllDrugs();
   211 	#endif
   212 }
   213 
   214 public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
   215 {
   216 	#if BEACON
   217 	KillAllBeacons();
   218 	#endif
   219 	#if TIMEBOMB
   220 	KillAllTimeBombs();
   221 	#endif
   222 	#if FIRE
   223 	KillAllFireBombs();
   224 	#endif
   225 	#if ICE
   226 	KillAllFreezes();
   227 	#endif
   228 	#if DRUG
   229 	KillAllDrugs();
   230 	#endif
   231 	
   232 	return Plugin_Handled;
   233 }
   234 
   235 public OnAdminMenuReady(Handle:topmenu)
   236 {
   237 	/* Block us from being called twice */
   238 	if (topmenu == hTopMenu)
   239 	{
   240 		return;
   241 	}
   242 	
   243 	/* Save the Handle */
   244 	hTopMenu = topmenu;
   245 	
   246 	/* Find the "Player Commands" category */
   247 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   248 
   249 	if (player_commands != INVALID_TOPMENUOBJECT)
   250 	{
   251 		#if BEACON
   252 		AddToTopMenu(hTopMenu,
   253 			"sm_beacon",
   254 			TopMenuObject_Item,
   255 			AdminMenu_Beacon,
   256 			player_commands,
   257 			"sm_beacon",
   258 			ADMFLAG_SLAY);
   259 		#endif
   260 		
   261 		#if TIMEBOMB
   262 		AddToTopMenu(hTopMenu,
   263 			"sm_timebomb",
   264 			TopMenuObject_Item,
   265 			AdminMenu_TimeBomb,
   266 			player_commands,
   267 			"sm_timebomb",
   268 			ADMFLAG_SLAY);
   269 		#endif
   270 		
   271 		#if FIRE
   272 		AddToTopMenu(hTopMenu,
   273 			"sm_burn",
   274 			TopMenuObject_Item,
   275 			AdminMenu_Burn,
   276 			player_commands,
   277 			"sm_burn",
   278 			ADMFLAG_SLAY);
   279 			
   280 		AddToTopMenu(hTopMenu,
   281 			"sm_firebomb",
   282 			TopMenuObject_Item,
   283 			AdminMenu_FireBomb,
   284 			player_commands,
   285 			"sm_firebomb",
   286 			ADMFLAG_SLAY);
   287 		#endif
   288 		
   289 		#if ICE
   290 		AddToTopMenu(hTopMenu,
   291 			"sm_freeze",
   292 			TopMenuObject_Item,
   293 			AdminMenu_Freeze,
   294 			player_commands,
   295 			"sm_freeze",
   296 			ADMFLAG_SLAY);
   297 			
   298 		AddToTopMenu(hTopMenu,
   299 			"sm_freezebomb",
   300 			TopMenuObject_Item,
   301 			AdminMenu_FreezeBomb,
   302 			player_commands,
   303 			"sm_freezebomb",
   304 			ADMFLAG_SLAY);
   305 		#endif
   306 			
   307 		#if GRAVITY
   308 		AddToTopMenu(hTopMenu,
   309 			"sm_gravity",
   310 			TopMenuObject_Item,
   311 			AdminMenu_Gravity,
   312 			player_commands,
   313 			"sm_gravity",
   314 			ADMFLAG_SLAY);
   315 		#endif
   316 			
   317 		#if BLIND
   318 		AddToTopMenu(hTopMenu,
   319 			"sm_blind",
   320 			TopMenuObject_Item,
   321 			AdminMenu_Blind,
   322 			player_commands,
   323 			"sm_blind",
   324 			ADMFLAG_SLAY);
   325 		#endif
   326 		
   327 		#if NOCLIP
   328 		AddToTopMenu(hTopMenu,
   329 			"sm_noclip",
   330 			TopMenuObject_Item,
   331 			AdminMenu_NoClip,
   332 			player_commands,
   333 			"sm_noclip",
   334 			ADMFLAG_SLAY);
   335 		#endif
   336 		
   337 		#if DRUG
   338 		AddToTopMenu(hTopMenu,
   339 			"sm_drug",
   340 			TopMenuObject_Item,
   341 			AdminMenu_Drug,
   342 			player_commands,
   343 			"sm_drug",
   344 			ADMFLAG_SLAY);
   345 		#endif		
   346 	}
   347 }
   348 
   349 public Action:Command_Play(client, args)
   350 {
   351 	if (args < 2)
   352 	{
   353 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   354 	}
   355 
   356 	new String:Arguments[PLATFORM_MAX_PATH + 65];
   357 	GetCmdArgString(Arguments, sizeof(Arguments));
   358 
   359  	decl String:Arg[65];
   360 	new len = BreakString(Arguments, Arg, sizeof(Arg));
   361 
   362 	/* Make sure it does not go out of bound by doing "sm_play user  "*/
   363 	if (len == -1)
   364 	{
   365 		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   366 		return Plugin_Handled;
   367 	}
   368 
   369 	/* Incase they put quotes and white spaces after the quotes */
   370 	if (Arguments[len] == '"')
   371 	{
   372 		len++;
   373 		new FileLen = TrimString(Arguments[len]) + len;
   374 
   375 		if (Arguments[FileLen - 1] == '"')
   376 		{
   377 			Arguments[FileLen - 1] = '\0';
   378 		}
   379 	}
   380 	
   381 	decl String:target_name[MAX_TARGET_LENGTH];
   382 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   383 	
   384 	if ((target_count = ProcessTargetString(
   385 			Arg,
   386 			client,
   387 			target_list,
   388 			MAXPLAYERS,
   389 			COMMAND_FILTER_NO_BOTS,
   390 			target_name,
   391 			sizeof(target_name),
   392 			tn_is_ml)) <= 0)
   393 	{
   394 		ReplyToTargetError(client, target_count);
   395 		return Plugin_Handled;
   396 	}
   397 	
   398 	for (new i = 0; i < target_count; i++)
   399 	{
   400 		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
   401 		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);
   402 	}
   403 	
   404 	if (tn_is_ml)
   405 	{
   406 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
   407 	}
   408 	else
   409 	{
   410 		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
   411 	}
   412 
   413 	return Plugin_Handled;
   414 }