plugins/funcommands.sp
author David Anderson <dvander@alliedmods.net>
Thu May 29 04:47:42 2008 +0000 (2008-05-29)
changeset 2092 204db878bcfa
parent 2020 87ea1cf0fe76
child 2289 44045ead61cd
permissions -rw-r--r--
(merging from branch) fixed amb1583 - MySQL string fetch from prepared queries returned corrupted data.
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod Basic Fun Commands Plugin
ds@1952
     5
 * Implements basic punishment commands.
ds@1952
     6
 *
ds@1952
     7
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     8
 * =============================================================================
ds@1952
     9
 *
ds@1952
    10
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    11
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    12
 * Free Software Foundation.
ds@1952
    13
 * 
ds@1952
    14
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    16
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    17
 * details.
ds@1952
    18
 *
ds@1952
    19
 * You should have received a copy of the GNU General Public License along with
ds@1952
    20
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    21
 *
ds@1952
    22
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    23
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    24
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    25
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    26
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    27
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    28
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    29
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    30
 *
ds@1952
    31
 * Version: $Id$
ds@1952
    32
 */
ds@1952
    33
ds@1952
    34
#pragma semicolon 1
ds@1952
    35
ds@1952
    36
#include <sourcemod>
ds@1952
    37
#include <sdktools>
ds@1952
    38
#undef REQUIRE_PLUGIN
ds@1952
    39
#include <adminmenu>
ds@1952
    40
ds@1952
    41
public Plugin:myinfo =
ds@1952
    42
{
ds@1952
    43
	name = "Fun Commands",
ds@1952
    44
	author = "AlliedModders LLC",
ds@1952
    45
	description = "Fun Commands",
ds@1952
    46
	version = SOURCEMOD_VERSION,
ds@1952
    47
	url = "http://www.sourcemod.net/"
ds@1952
    48
};
ds@1952
    49
ds@1952
    50
// -------------------------------------------------------------------------------
ds@1952
    51
// Set any of these to 0 and recompile to completely disable those commands
ds@1952
    52
// -------------------------------------------------------------------------------
ds@1952
    53
#define BEACON		1
ds@1952
    54
#define TIMEBOMB	1
ds@1952
    55
#define FIRE		1
ds@1952
    56
#define ICE			1
ds@1952
    57
#define GRAVITY		1
ds@1952
    58
#define BLIND		1
ds@1952
    59
#define NOCLIP		1
ds@1952
    60
#define DRUG		1
ds@1952
    61
#define TELEPORT	1
ds@1952
    62
#define HEALTH		1
ds@1952
    63
#define COLORS		1
ds@1952
    64
#define CASH		1
ds@1952
    65
// -------------------------------------------------------------------------------
ds@1952
    66
ds@1952
    67
new Handle:hTopMenu = INVALID_HANDLE;
ds@1952
    68
ds@1952
    69
// Sounds
ds@1952
    70
#define SOUND_BLIP		"buttons/blip1.wav"
ds@1952
    71
#define SOUND_BEEP		"buttons/button17.wav"
ds@1952
    72
#define SOUND_FINAL		"weapons/cguard/charging.wav"
ds@1952
    73
#define SOUND_BOOM		"weapons/explode3.wav"
ds@1952
    74
#define SOUND_FREEZE	"physics/glass/glass_impact_bullet4.wav"
ds@1952
    75
ds@1952
    76
// Following are model indexes for temp entities
ds@1952
    77
new g_BeamSprite;
ds@1952
    78
new g_BeamSprite2;
ds@1952
    79
new g_HaloSprite;
ds@1952
    80
new g_GlowSprite;
ds@1952
    81
new g_ExplosionSprite;
ds@1952
    82
ds@1952
    83
// Basic color arrays for temp entities
ds@1952
    84
new redColor[4] = {255, 75, 75, 255};
ds@1952
    85
new orangeColor[4] = {255, 128, 0, 255};
ds@1952
    86
new greenColor[4] = {75, 255, 75, 255};
ds@1952
    87
new blueColor[4] = {75, 75, 255, 255};
ds@1952
    88
new whiteColor[4] = {255, 255, 255, 255};
ds@1952
    89
new greyColor[4] = {128, 128, 128, 255};
ds@1952
    90
ds@1952
    91
// UserMessageId for Fade.
ds@1952
    92
new UserMsg:g_FadeUserMsgId;
ds@1952
    93
ds@1952
    94
// Include various commands and supporting functions
ds@1952
    95
#if BEACON
ds@1952
    96
#include "funcommands/beacon.sp"
ds@1952
    97
#endif
ds@1952
    98
#if TIMEBOMB
ds@1952
    99
#include "funcommands/timebomb.sp"
ds@1952
   100
#endif
ds@1952
   101
#if FIRE
ds@1952
   102
#include "funcommands/fire.sp"
ds@1952
   103
#endif
ds@1952
   104
#if ICE
ds@1952
   105
#include "funcommands/ice.sp"
ds@1952
   106
#endif
ds@1952
   107
#if GRAVITY
ds@1952
   108
#include "funcommands/gravity.sp"
ds@1952
   109
#endif
ds@1952
   110
#if BLIND
ds@1952
   111
#include "funcommands/blind.sp"
ds@1952
   112
#endif
ds@1952
   113
#if NOCLIP
ds@1952
   114
#include "funcommands/noclip.sp"
ds@1952
   115
#endif
ds@1952
   116
#if DRUG
ds@1952
   117
#include "funcommands/drug.sp"
ds@1952
   118
#endif
ds@1952
   119
ds@1952
   120
public OnPluginStart()
ds@1952
   121
{
ds@1952
   122
	if (FindPluginByFile("basefuncommands.smx") != INVALID_HANDLE)
ds@1952
   123
	{
ds@1952
   124
		ThrowError("This plugin replaces basefuncommands.  You cannot run both at once.");
ds@1952
   125
	}
ds@1952
   126
	
ds@1952
   127
	LoadTranslations("common.phrases");
dvander@2020
   128
	LoadTranslations("funcommands.phrases");
ds@1952
   129
ds@1952
   130
	g_FadeUserMsgId = GetUserMessageId("Fade");
ds@1952
   131
	
ds@1952
   132
	RegAdminCmd("sm_play", Command_Play, ADMFLAG_GENERIC, "sm_play <#userid|name> <filename>");
ds@1952
   133
ds@1952
   134
	HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);	
ds@1952
   135
ds@1952
   136
	#if BEACON
ds@1952
   137
	SetupBeacon();		// sm_beacon
ds@1952
   138
	#endif
ds@1952
   139
	
ds@1952
   140
	#if TIMEBOMB
ds@1952
   141
	SetupTimeBomb();	// sm_timebomb
ds@1952
   142
	#endif
ds@1952
   143
	
ds@1952
   144
	#if FIRE
ds@1952
   145
	SetupFire();		// sm_burn and sm_firebomb
ds@1952
   146
	#endif
ds@1952
   147
	
ds@1952
   148
	#if ICE
ds@1952
   149
	SetupIce();			// sm_freeze and sm_freezebomb
ds@1952
   150
	#endif
ds@1952
   151
	
ds@1952
   152
	#if GRAVITY
ds@1952
   153
	SetupGravity();		// sm_gravity
ds@1952
   154
	#endif
ds@1952
   155
	
ds@1952
   156
	#if BLIND
ds@1952
   157
	SetupBlind();		// sm_blind
ds@1952
   158
	#endif
ds@1952
   159
	
ds@1952
   160
	#if NOCLIP
ds@1952
   161
	SetupNoClip();		// sm_noclip
ds@1952
   162
	#endif
ds@1952
   163
	
ds@1952
   164
	#if DRUG
ds@1952
   165
	SetupDrugs();		// sm_drug
ds@1952
   166
	#endif
ds@1952
   167
	
ds@1952
   168
	AutoExecConfig(true, "funcommands");
ds@1952
   169
	
ds@1952
   170
	/* Account for late loading */
ds@1952
   171
	new Handle:topmenu;
ds@1952
   172
	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
ds@1952
   173
	{
ds@1952
   174
		OnAdminMenuReady(topmenu);
ds@1952
   175
	}
ds@1952
   176
}
ds@1952
   177
ds@1952
   178
public OnMapStart()
ds@1952
   179
{
ds@1952
   180
	PrecacheSound(SOUND_BLIP, true);
ds@1952
   181
	PrecacheSound(SOUND_BEEP, true);
ds@1952
   182
	PrecacheSound(SOUND_FINAL, true);
ds@1952
   183
	PrecacheSound(SOUND_BOOM, true);
ds@1952
   184
	PrecacheSound(SOUND_FREEZE, true);
ds@1952
   185
ds@1952
   186
	g_BeamSprite = PrecacheModel("materials/sprites/laser.vmt");
ds@1952
   187
	g_BeamSprite2 = PrecacheModel("sprites/bluelight1.vmt");
ds@1952
   188
	g_HaloSprite = PrecacheModel("materials/sprites/halo01.vmt");	
ds@1952
   189
	g_GlowSprite = PrecacheModel("sprites/blueglow2.vmt");
ds@1952
   190
	g_ExplosionSprite = PrecacheModel("sprites/sprite_fire01.vmt");
ds@1952
   191
}
ds@1952
   192
ds@1952
   193
public OnMapEnd()
ds@1952
   194
{
ds@1952
   195
	#if BEACON
ds@1952
   196
	KillAllBeacons();
ds@1952
   197
	#endif
ds@1952
   198
	#if TIMEBOMB
ds@1952
   199
	KillAllTimeBombs();
ds@1952
   200
	#endif
ds@1952
   201
	#if FIRE
ds@1952
   202
	KillAllFireBombs();
ds@1952
   203
	#endif
ds@1952
   204
	#if ICE
ds@1952
   205
	KillAllFreezes();
ds@1952
   206
	#endif
ds@1952
   207
	#if DRUG
ds@1952
   208
	KillAllDrugs();
ds@1952
   209
	#endif
ds@1952
   210
}
ds@1952
   211
ds@1952
   212
public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
ds@1952
   213
{
ds@1952
   214
	#if BEACON
ds@1952
   215
	KillAllBeacons();
ds@1952
   216
	#endif
ds@1952
   217
	#if TIMEBOMB
ds@1952
   218
	KillAllTimeBombs();
ds@1952
   219
	#endif
ds@1952
   220
	#if FIRE
ds@1952
   221
	KillAllFireBombs();
ds@1952
   222
	#endif
ds@1952
   223
	#if ICE
ds@1952
   224
	KillAllFreezes();
ds@1952
   225
	#endif
ds@1952
   226
	#if DRUG
ds@1952
   227
	KillAllDrugs();
ds@1952
   228
	#endif
ds@1952
   229
	
ds@1952
   230
	return Plugin_Handled;
ds@1952
   231
}
ds@1952
   232
ds@1952
   233
public OnAdminMenuReady(Handle:topmenu)
ds@1952
   234
{
ds@1952
   235
	/* Block us from being called twice */
ds@1952
   236
	if (topmenu == hTopMenu)
ds@1952
   237
	{
ds@1952
   238
		return;
ds@1952
   239
	}
ds@1952
   240
	
ds@1952
   241
	/* Save the Handle */
ds@1952
   242
	hTopMenu = topmenu;
ds@1952
   243
	
ds@1952
   244
	/* Find the "Player Commands" category */
ds@1952
   245
	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
ds@1952
   246
ds@1952
   247
	if (player_commands != INVALID_TOPMENUOBJECT)
ds@1952
   248
	{
ds@1952
   249
		#if BEACON
ds@1952
   250
		AddToTopMenu(hTopMenu,
ds@1952
   251
			"sm_beacon",
ds@1952
   252
			TopMenuObject_Item,
ds@1952
   253
			AdminMenu_Beacon,
ds@1952
   254
			player_commands,
ds@1952
   255
			"sm_beacon",
ds@1952
   256
			ADMFLAG_SLAY);
ds@1952
   257
		#endif
ds@1952
   258
		
ds@1952
   259
		#if TIMEBOMB
ds@1952
   260
		AddToTopMenu(hTopMenu,
ds@1952
   261
			"sm_timebomb",
ds@1952
   262
			TopMenuObject_Item,
ds@1952
   263
			AdminMenu_TimeBomb,
ds@1952
   264
			player_commands,
ds@1952
   265
			"sm_timebomb",
ds@1952
   266
			ADMFLAG_SLAY);
ds@1952
   267
		#endif
ds@1952
   268
		
ds@1952
   269
		#if FIRE
ds@1952
   270
		AddToTopMenu(hTopMenu,
ds@1952
   271
			"sm_burn",
ds@1952
   272
			TopMenuObject_Item,
ds@1952
   273
			AdminMenu_Burn,
ds@1952
   274
			player_commands,
ds@1952
   275
			"sm_burn",
ds@1952
   276
			ADMFLAG_SLAY);
ds@1952
   277
			
ds@1952
   278
		AddToTopMenu(hTopMenu,
ds@1952
   279
			"sm_firebomb",
ds@1952
   280
			TopMenuObject_Item,
ds@1952
   281
			AdminMenu_FireBomb,
ds@1952
   282
			player_commands,
ds@1952
   283
			"sm_firebomb",
ds@1952
   284
			ADMFLAG_SLAY);
ds@1952
   285
		#endif
ds@1952
   286
		
ds@1952
   287
		#if ICE
ds@1952
   288
		AddToTopMenu(hTopMenu,
ds@1952
   289
			"sm_freeze",
ds@1952
   290
			TopMenuObject_Item,
ds@1952
   291
			AdminMenu_Freeze,
ds@1952
   292
			player_commands,
ds@1952
   293
			"sm_freeze",
ds@1952
   294
			ADMFLAG_SLAY);
ds@1952
   295
			
ds@1952
   296
		AddToTopMenu(hTopMenu,
ds@1952
   297
			"sm_freezebomb",
ds@1952
   298
			TopMenuObject_Item,
ds@1952
   299
			AdminMenu_FreezeBomb,
ds@1952
   300
			player_commands,
ds@1952
   301
			"sm_freezebomb",
ds@1952
   302
			ADMFLAG_SLAY);
ds@1952
   303
		#endif
ds@1952
   304
			
ds@1952
   305
		#if GRAVITY
ds@1952
   306
		AddToTopMenu(hTopMenu,
ds@1952
   307
			"sm_gravity",
ds@1952
   308
			TopMenuObject_Item,
ds@1952
   309
			AdminMenu_Gravity,
ds@1952
   310
			player_commands,
ds@1952
   311
			"sm_gravity",
ds@1952
   312
			ADMFLAG_SLAY);
ds@1952
   313
		#endif
ds@1952
   314
			
ds@1952
   315
		#if BLIND
ds@1952
   316
		AddToTopMenu(hTopMenu,
ds@1952
   317
			"sm_blind",
ds@1952
   318
			TopMenuObject_Item,
ds@1952
   319
			AdminMenu_Blind,
ds@1952
   320
			player_commands,
ds@1952
   321
			"sm_blind",
ds@1952
   322
			ADMFLAG_SLAY);
ds@1952
   323
		#endif
ds@1952
   324
		
ds@1952
   325
		#if NOCLIP
ds@1952
   326
		AddToTopMenu(hTopMenu,
ds@1952
   327
			"sm_noclip",
ds@1952
   328
			TopMenuObject_Item,
ds@1952
   329
			AdminMenu_NoClip,
ds@1952
   330
			player_commands,
ds@1952
   331
			"sm_noclip",
ds@1952
   332
			ADMFLAG_SLAY);
ds@1952
   333
		#endif
ds@1952
   334
		
ds@1952
   335
		#if DRUG
ds@1952
   336
		AddToTopMenu(hTopMenu,
ds@1952
   337
			"sm_drug",
ds@1952
   338
			TopMenuObject_Item,
ds@1952
   339
			AdminMenu_Drug,
ds@1952
   340
			player_commands,
ds@1952
   341
			"sm_drug",
ds@1952
   342
			ADMFLAG_SLAY);
ds@1952
   343
		#endif		
ds@1952
   344
	}
ds@1952
   345
}
ds@1952
   346
ds@1952
   347
public Action:Command_Play(client, args)
ds@1952
   348
{
ds@1952
   349
	if (args < 2)
ds@1952
   350
	{
ds@1952
   351
		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
ds@1952
   352
	}
ds@1952
   353
ds@1952
   354
	new String:Arguments[PLATFORM_MAX_PATH + 65];
ds@1952
   355
	GetCmdArgString(Arguments, sizeof(Arguments));
ds@1952
   356
ds@1952
   357
 	decl String:Arg[65];
ds@1952
   358
	new len = BreakString(Arguments, Arg, sizeof(Arg));
ds@1952
   359
ds@1952
   360
	/* Make sure it does not go out of bound by doing "sm_play user  "*/
ds@1952
   361
	if (len == -1)
ds@1952
   362
	{
ds@1952
   363
		ReplyToCommand(client, "[SM] Usage: sm_play <#userid|name> <filename>");
ds@1952
   364
		return Plugin_Handled;
ds@1952
   365
	}
ds@1952
   366
ds@1952
   367
	/* Incase they put quotes and white spaces after the quotes */
ds@1952
   368
	if (Arguments[len] == '"')
ds@1952
   369
	{
ds@1952
   370
		len++;
ds@1952
   371
		new FileLen = TrimString(Arguments[len]) + len;
ds@1952
   372
ds@1952
   373
		if (Arguments[FileLen - 1] == '"')
ds@1952
   374
		{
ds@1952
   375
			Arguments[FileLen - 1] = '\0';
ds@1952
   376
		}
ds@1952
   377
	}
ds@1952
   378
	
ds@1952
   379
	decl String:target_name[MAX_TARGET_LENGTH];
ds@1952
   380
	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
ds@1952
   381
	
ds@1952
   382
	if ((target_count = ProcessTargetString(
ds@1952
   383
			Arg,
ds@1952
   384
			client,
ds@1952
   385
			target_list,
ds@1952
   386
			MAXPLAYERS,
ds@1952
   387
			COMMAND_FILTER_NO_BOTS,
ds@1952
   388
			target_name,
ds@1952
   389
			sizeof(target_name),
ds@1952
   390
			tn_is_ml)) <= 0)
ds@1952
   391
	{
ds@1952
   392
		ReplyToTargetError(client, target_count);
ds@1952
   393
		return Plugin_Handled;
ds@1952
   394
	}
ds@1952
   395
	
ds@1952
   396
	for (new i = 0; i < target_count; i++)
ds@1952
   397
	{
ds@1952
   398
		ClientCommand(target_list[i], "playgamesound \"%s\"", Arguments[len]);
ds@1952
   399
		LogAction(client, target_list[i], "\"%L\" played sound on \"%L\" (file \"%s\")", client, target_list[i], Arguments[len]);
ds@1952
   400
	}
ds@1952
   401
	
ds@1952
   402
	if (tn_is_ml)
ds@1952
   403
	{
ds@1952
   404
		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", target_name);
ds@1952
   405
	}
ds@1952
   406
	else
ds@1952
   407
	{
ds@1952
   408
		ShowActivity2(client, "[SM] ", "%t", "Played sound to target", "_s", target_name);
ds@1952
   409
	}
ds@1952
   410
ds@1952
   411
	return Plugin_Handled;
ds@1952
   412
}