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