plugins/funcommands.sp
changeset 1889 5b4d6acc4d82
child 1947 e73a1e51833b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/funcommands.sp	Fri Feb 22 21:01:08 2008 +0000
     1.3 @@ -0,0 +1,412 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basic Fun Commands Plugin
     1.8 + * Implements basic punishment commands.
     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 +#pragma semicolon 1
    1.38 +
    1.39 +#include <sourcemod>
    1.40 +#include <sdktools>
    1.41 +#undef REQUIRE_PLUGIN
    1.42 +#include <adminmenu>
    1.43 +
    1.44 +public Plugin:myinfo =
    1.45 +{
    1.46 +	name = "Fun Commands",
    1.47 +	author = "AlliedModders LLC",
    1.48 +	description = "Fun Commands",
    1.49 +	version = SOURCEMOD_VERSION,
    1.50 +	url = "http://www.sourcemod.net/"
    1.51 +};
    1.52 +
    1.53 +// -------------------------------------------------------------------------------
    1.54 +// Set any of these to 0 and recompile to completely disable those commands
    1.55 +// -------------------------------------------------------------------------------
    1.56 +#define BEACON		1
    1.57 +#define TIMEBOMB	1
    1.58 +#define FIRE		1
    1.59 +#define ICE			1
    1.60 +#define GRAVITY		1
    1.61 +#define BLIND		1
    1.62 +#define NOCLIP		1
    1.63 +#define DRUG		1
    1.64 +#define TELEPORT	1
    1.65 +#define HEALTH		1
    1.66 +#define COLORS		1
    1.67 +#define CASH		1
    1.68 +// -------------------------------------------------------------------------------
    1.69 +
    1.70 +new Handle:hTopMenu = INVALID_HANDLE;
    1.71 +
    1.72 +// Sounds
    1.73 +#define SOUND_BLIP		"buttons/blip1.wav"
    1.74 +#define SOUND_BEEP		"buttons/button17.wav"
    1.75 +#define SOUND_FINAL		"weapons/cguard/charging.wav"
    1.76 +#define SOUND_BOOM		"weapons/explode3.wav"
    1.77 +#define SOUND_FREEZE	"physics/glass/glass_impact_bullet4.wav"
    1.78 +
    1.79 +// Following are model indexes for temp entities
    1.80 +new g_BeamSprite;
    1.81 +new g_BeamSprite2;
    1.82 +new g_HaloSprite;
    1.83 +new g_GlowSprite;
    1.84 +new g_ExplosionSprite;
    1.85 +
    1.86 +// Basic color arrays for temp entities
    1.87 +new redColor[4] = {255, 75, 75, 255};
    1.88 +new orangeColor[4] = {255, 128, 0, 255};
    1.89 +new greenColor[4] = {75, 255, 75, 255};
    1.90 +new blueColor[4] = {75, 75, 255, 255};
    1.91 +new whiteColor[4] = {255, 255, 255, 255};
    1.92 +new greyColor[4] = {128, 128, 128, 255};
    1.93 +
    1.94 +// UserMessageId for Fade.
    1.95 +new UserMsg:g_FadeUserMsgId;
    1.96 +
    1.97 +// Include various commands and supporting functions
    1.98 +#if BEACON
    1.99 +#include "funcommands/beacon.sp"
   1.100 +#endif
   1.101 +#if TIMEBOMB
   1.102 +#include "funcommands/timebomb.sp"
   1.103 +#endif
   1.104 +#if FIRE
   1.105 +#include "funcommands/fire.sp"
   1.106 +#endif
   1.107 +#if ICE
   1.108 +#include "funcommands/ice.sp"
   1.109 +#endif
   1.110 +#if GRAVITY
   1.111 +#include "funcommands/gravity.sp"
   1.112 +#endif
   1.113 +#if BLIND
   1.114 +#include "funcommands/blind.sp"
   1.115 +#endif
   1.116 +#if NOCLIP
   1.117 +#include "funcommands/noclip.sp"
   1.118 +#endif
   1.119 +#if DRUG
   1.120 +#include "funcommands/drug.sp"
   1.121 +#endif
   1.122 +
   1.123 +public OnPluginStart()
   1.124 +{
   1.125 +	if (FindPluginByFile("basefuncommands.smx") != INVALID_HANDLE)
   1.126 +	{
   1.127 +		ThrowError("This plugin replaces basefuncommands.  You cannot run both at once.");
   1.128 +	}
   1.129 +	
   1.130 +	LoadTranslations("common.phrases");
   1.131 +	LoadTranslations("basefuncommands.phrases");
   1.132 +
   1.133 +	g_FadeUserMsgId = GetUserMessageId("Fade");
   1.134 +	
   1.135 +	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
   1.136 +
   1.137 +	HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);	
   1.138 +
   1.139 +	#if BEACON
   1.140 +	SetupBeacon();		// sm_beacon
   1.141 +	#endif
   1.142 +	
   1.143 +	#if TIMEBOMB
   1.144 +	SetupTimeBomb();	// sm_timebomb
   1.145 +	#endif
   1.146 +	
   1.147 +	#if FIRE
   1.148 +	SetupFire();		// sm_burn and sm_firebomb
   1.149 +	#endif
   1.150 +	
   1.151 +	#if ICE
   1.152 +	SetupIce();			// sm_freeze and sm_freezebomb
   1.153 +	#endif
   1.154 +	
   1.155 +	#if GRAVITY
   1.156 +	SetupGravity();		// sm_gravity
   1.157 +	#endif
   1.158 +	
   1.159 +	#if BLIND
   1.160 +	SetupBlind();		// sm_blind
   1.161 +	#endif
   1.162 +	
   1.163 +	#if NOCLIP
   1.164 +	SetupNoClip();		// sm_noclip
   1.165 +	#endif
   1.166 +	
   1.167 +	#if DRUG
   1.168 +	SetupDrugs();		// sm_drug
   1.169 +	#endif
   1.170 +	
   1.171 +	AutoExecConfig(true, "funcommands");
   1.172 +	
   1.173 +	/* Account for late loading */
   1.174 +	new Handle:topmenu;
   1.175 +	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
   1.176 +	{
   1.177 +		OnAdminMenuReady(topmenu);
   1.178 +	}
   1.179 +}
   1.180 +
   1.181 +public OnMapStart()
   1.182 +{
   1.183 +	PrecacheSound(SOUND_BLIP, true);
   1.184 +	PrecacheSound(SOUND_BEEP, true);
   1.185 +	PrecacheSound(SOUND_FINAL, true);
   1.186 +	PrecacheSound(SOUND_BOOM, true);
   1.187 +	PrecacheSound(SOUND_FREEZE, true);
   1.188 +
   1.189 +	g_BeamSprite = PrecacheModel("materials/sprites/laser.vmt");
   1.190 +	g_BeamSprite2 = PrecacheModel("sprites/bluelight1.vmt");
   1.191 +	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");	
   1.192 +	g_GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
   1.193 +	g_ExplosionSprite = PrecacheModel("sprites/sprite_fire01.vmt");
   1.194 +}
   1.195 +
   1.196 +public OnMapEnd()
   1.197 +{
   1.198 +	#if BEACON
   1.199 +	KillAllBeacons();
   1.200 +	#endif
   1.201 +	#if TIMEBOMB
   1.202 +	KillAllTimeBombs();
   1.203 +	#endif
   1.204 +	#if FIRE
   1.205 +	KillAllFireBombs();
   1.206 +	#endif
   1.207 +	#if ICE
   1.208 +	KillAllFreezes();
   1.209 +	#endif
   1.210 +	#if DRUG
   1.211 +	KillAllDrugs();
   1.212 +	#endif
   1.213 +}
   1.214 +
   1.215 +public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
   1.216 +{
   1.217 +	#if BEACON
   1.218 +	KillAllBeacons();
   1.219 +	#endif
   1.220 +	#if TIMEBOMB
   1.221 +	KillAllTimeBombs();
   1.222 +	#endif
   1.223 +	#if FIRE
   1.224 +	KillAllFireBombs();
   1.225 +	#endif
   1.226 +	#if ICE
   1.227 +	KillAllFreezes();
   1.228 +	#endif
   1.229 +	#if DRUG
   1.230 +	KillAllDrugs();
   1.231 +	#endif
   1.232 +	
   1.233 +	return Plugin_Handled;
   1.234 +}
   1.235 +
   1.236 +public OnAdminMenuReady(Handle:topmenu)
   1.237 +{
   1.238 +	/* Block us from being called twice */
   1.239 +	if (topmenu == hTopMenu)
   1.240 +	{
   1.241 +		return;
   1.242 +	}
   1.243 +	
   1.244 +	/* Save the Handle */
   1.245 +	hTopMenu = topmenu;
   1.246 +	
   1.247 +	/* Find the "Player Commands" category */
   1.248 +	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   1.249 +
   1.250 +	if (player_commands != INVALID_TOPMENUOBJECT)
   1.251 +	{
   1.252 +		#if BEACON
   1.253 +		AddToTopMenu(hTopMenu,
   1.254 +			"sm_beacon",
   1.255 +			TopMenuObject_Item,
   1.256 +			AdminMenu_Beacon,
   1.257 +			player_commands,
   1.258 +			"sm_beacon",
   1.259 +			ADMFLAG_SLAY);
   1.260 +		#endif
   1.261 +		
   1.262 +		#if TIMEBOMB
   1.263 +		AddToTopMenu(hTopMenu,
   1.264 +			"sm_timebomb",
   1.265 +			TopMenuObject_Item,
   1.266 +			AdminMenu_TimeBomb,
   1.267 +			player_commands,
   1.268 +			"sm_timebomb",
   1.269 +			ADMFLAG_SLAY);
   1.270 +		#endif
   1.271 +		
   1.272 +		#if FIRE
   1.273 +		AddToTopMenu(hTopMenu,
   1.274 +			"sm_burn",
   1.275 +			TopMenuObject_Item,
   1.276 +			AdminMenu_Burn,
   1.277 +			player_commands,
   1.278 +			"sm_burn",
   1.279 +			ADMFLAG_SLAY);
   1.280 +			
   1.281 +		AddToTopMenu(hTopMenu,
   1.282 +			"sm_firebomb",
   1.283 +			TopMenuObject_Item,
   1.284 +			AdminMenu_FireBomb,
   1.285 +			player_commands,
   1.286 +			"sm_firebomb",
   1.287 +			ADMFLAG_SLAY);
   1.288 +		#endif
   1.289 +		
   1.290 +		#if ICE
   1.291 +		AddToTopMenu(hTopMenu,
   1.292 +			"sm_freeze",
   1.293 +			TopMenuObject_Item,
   1.294 +			AdminMenu_Freeze,
   1.295 +			player_commands,
   1.296 +			"sm_freeze",
   1.297 +			ADMFLAG_SLAY);
   1.298 +			
   1.299 +		AddToTopMenu(hTopMenu,
   1.300 +			"sm_freezebomb",
   1.301 +			TopMenuObject_Item,
   1.302 +			AdminMenu_FreezeBomb,
   1.303 +			player_commands,
   1.304 +			"sm_freezebomb",
   1.305 +			ADMFLAG_SLAY);
   1.306 +		#endif
   1.307 +			
   1.308 +		#if GRAVITY
   1.309 +		AddToTopMenu(hTopMenu,
   1.310 +			"sm_gravity",
   1.311 +			TopMenuObject_Item,
   1.312 +			AdminMenu_Gravity,
   1.313 +			player_commands,
   1.314 +			"sm_gravity",
   1.315 +			ADMFLAG_SLAY);
   1.316 +		#endif
   1.317 +			
   1.318 +		#if BLIND
   1.319 +		AddToTopMenu(hTopMenu,
   1.320 +			"sm_blind",
   1.321 +			TopMenuObject_Item,
   1.322 +			AdminMenu_Blind,
   1.323 +			player_commands,
   1.324 +			"sm_blind",
   1.325 +			ADMFLAG_SLAY);
   1.326 +		#endif
   1.327 +		
   1.328 +		#if NOCLIP
   1.329 +		AddToTopMenu(hTopMenu,
   1.330 +			"sm_noclip",
   1.331 +			TopMenuObject_Item,
   1.332 +			AdminMenu_NoClip,
   1.333 +			player_commands,
   1.334 +			"sm_noclip",
   1.335 +			ADMFLAG_SLAY);
   1.336 +		#endif
   1.337 +		
   1.338 +		#if DRUG
   1.339 +		AddToTopMenu(hTopMenu,
   1.340 +			"sm_drug",
   1.341 +			TopMenuObject_Item,
   1.342 +			AdminMenu_Drug,
   1.343 +			player_commands,
   1.344 +			"sm_drug",
   1.345 +			ADMFLAG_SLAY);
   1.346 +		#endif		
   1.347 +	}
   1.348 +}
   1.349 +
   1.350 +public Action:Command_Play(client, args)
   1.351 +{
   1.352 +	if (args < 2)
   1.353 +	{
   1.354 +		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   1.355 +	}
   1.356 +
   1.357 +	new String:Arguments[PLATFORM_MAX_PATH + 65];
   1.358 +	GetCmdArgString(Arguments, sizeof(Arguments));
   1.359 +
   1.360 + 	decl String:Arg[65];
   1.361 +	new len = BreakString(Arguments, Arg, sizeof(Arg));
   1.362 +
   1.363 +	/* Make sure it does not go out of bound by doing "sm_play user  "*/
   1.364 +	if (len == -1)
   1.365 +	{
   1.366 +		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
   1.367 +		return Plugin_Handled;
   1.368 +	}
   1.369 +
   1.370 +	/* Incase they put quotes and white spaces after the quotes */
   1.371 +	if (Arguments[len] == '"')
   1.372 +	{
   1.373 +		len++;
   1.374 +		new FileLen = TrimString(Arguments[len]) + len;
   1.375 +
   1.376 +		if (Arguments[FileLen - 1] == '"')
   1.377 +		{
   1.378 +			Arguments[FileLen - 1] = '\0';
   1.379 +		}
   1.380 +	}
   1.381 +	
   1.382 +	decl String:target_name[MAX_TARGET_LENGTH];
   1.383 +	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   1.384 +	
   1.385 +	if ((target_count = ProcessTargetString(
   1.386 +			Arg,
   1.387 +			client,
   1.388 +			target_list,
   1.389 +			MAXPLAYERS,
   1.390 +			COMMAND_FILTER_NO_BOTS,
   1.391 +			target_name,
   1.392 +			sizeof(target_name),
   1.393 +			tn_is_ml)) <= 0)
   1.394 +	{
   1.395 +		ReplyToTargetError(client, target_count);
   1.396 +		return Plugin_Handled;
   1.397 +	}
   1.398 +	
   1.399 +	for (new i = 0; i < target_count; i++)
   1.400 +	{
   1.401 +		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
   1.402 +		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);
   1.403 +	}
   1.404 +	
   1.405 +	if (tn_is_ml)
   1.406 +	{
   1.407 +		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
   1.408 +	}
   1.409 +	else
   1.410 +	{
   1.411 +		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
   1.412 +	}
   1.413 +
   1.414 +	return Plugin_Handled;
   1.415 +}