plugins/funcommands.sp
author Peace-Maker <januk@freenet.de>
Sat May 10 05:42:33 2014 -0700 (2014-05-10)
changeset 4354 7011587e0021
parent 4310 896868764315
permissions -rw-r--r--
Remove LogMessageEx definition from logging.inc (bug 5897, r=kyles).
     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 // Admin Menu
    51 new Handle:hTopMenu = INVALID_HANDLE;
    52 
    53 // Sounds
    54 new String:g_BlipSound[PLATFORM_MAX_PATH];
    55 new String:g_BeepSound[PLATFORM_MAX_PATH];
    56 new String:g_FinalSound[PLATFORM_MAX_PATH];
    57 new String:g_BoomSound[PLATFORM_MAX_PATH];
    58 new String:g_FreezeSound[PLATFORM_MAX_PATH];
    59 
    60 // Following are model indexes for temp entities
    61 new g_BeamSprite        = -1;
    62 new g_BeamSprite2       = -1;
    63 new g_HaloSprite        = -1;
    64 new g_GlowSprite        = -1;
    65 new g_ExplosionSprite   = -1;
    66 
    67 // Basic color arrays for temp entities
    68 new redColor[4]		= {255, 75, 75, 255};
    69 new orangeColor[4]	= {255, 128, 0, 255};
    70 new greenColor[4]	= {75, 255, 75, 255};
    71 new blueColor[4]	= {75, 75, 255, 255};
    72 new whiteColor[4]	= {255, 255, 255, 255};
    73 new greyColor[4]	= {128, 128, 128, 255};
    74 
    75 // UserMessageId for Fade.
    76 new UserMsg:g_FadeUserMsgId;
    77 
    78 // Serial Generator for Timer Safety
    79 new g_Serial_Gen = 0;
    80 
    81 new EngineVersion:g_GameEngine = Engine_Unknown;
    82 
    83 // Flags used in various timers
    84 #define DEFAULT_TIMER_FLAGS TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE
    85 
    86 // Include various commands and supporting functions
    87 #include "funcommands/beacon.sp"
    88 #include "funcommands/timebomb.sp"
    89 #include "funcommands/fire.sp"
    90 #include "funcommands/ice.sp"
    91 #include "funcommands/gravity.sp"
    92 #include "funcommands/blind.sp"
    93 #include "funcommands/noclip.sp"
    94 #include "funcommands/drug.sp"
    95 
    96 public OnPluginStart()
    97 {
    98 	if (FindPluginByFile("basefuncommands.smx") != INVALID_HANDLE)
    99 	{
   100 		ThrowError("This plugin replaces basefuncommands.  You cannot run both at once.");
   101 	}
   102 	
   103 	LoadTranslations("common.phrases");
   104 	LoadTranslations("funcommands.phrases");
   105 	g_GameEngine = GetEngineVersion();
   106 	g_FadeUserMsgId = GetUserMessageId("Fade");
   107 
   108 	RegisterCvars( );
   109 	RegisterCmds( );
   110 	HookEvents( );
   111 	
   112 	/* Account for late loading */
   113 	new Handle:topmenu;
   114 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
   115 	{
   116 		OnAdminMenuReady(topmenu);
   117 	}
   118 }
   119 
   120 RegisterCvars( )
   121 {
   122 	// beacon
   123 	g_Cvar_BeaconRadius = CreateConVar("sm_beacon_radius", "375", "Sets the radius for beacon's light rings.", 0, true, 50.0, true, 1500.0);
   124 
   125 	// timebomb
   126 	g_Cvar_TimeBombTicks = CreateConVar("sm_timebomb_ticks", "10.0", "Sets how long the timebomb fuse is.", 0, true, 5.0, true, 120.0);
   127 	g_Cvar_TimeBombRadius = CreateConVar("sm_timebomb_radius", "600", "Sets the bomb blast radius.", 0, true, 50.0, true, 3000.0);
   128 	g_Cvar_TimeBombMode = CreateConVar("sm_timebomb_mode", "0", "Who is killed by the timebomb? 0 = Target only, 1 = Target's team, 2 = Everyone", 0, true, 0.0, true, 2.0);
   129 	
   130 	// fire
   131 	g_Cvar_BurnDuration = CreateConVar("sm_burn_duration", "20.0", "Sets the default duration of sm_burn and firebomb victims.", 0, true, 0.5, true, 20.0);
   132 	g_Cvar_FireBombTicks = CreateConVar("sm_firebomb_ticks", "10.0", "Sets how long the FireBomb fuse is.", 0, true, 5.0, true, 120.0);
   133 	g_Cvar_FireBombRadius = CreateConVar("sm_firebomb_radius", "600", "Sets the bomb blast radius.", 0, true, 50.0, true, 3000.0);
   134 	g_Cvar_FireBombMode = CreateConVar("sm_firebomb_mode", "0", "Who is targetted by the FireBomb? 0 = Target only, 1 = Target's team, 2 = Everyone", 0, true, 0.0, true, 2.0);
   135 	
   136 	// ice
   137 	g_Cvar_FreezeDuration = CreateConVar("sm_freeze_duration", "10.0", "Sets the default duration for sm_freeze and freezebomb victims", 0, true, 1.0, true, 120.0);	
   138 	g_Cvar_FreezeBombTicks = CreateConVar("sm_freezebomb_ticks", "10.0", "Sets how long the freezebomb fuse is.", 0, true, 5.0, true, 120.0);
   139 	g_Cvar_FreezeBombRadius = CreateConVar("sm_freezebomb_radius", "600", "Sets the freezebomb blast radius.", 0, true, 50.0, true, 3000.0);
   140 	g_Cvar_FreezeBombMode = CreateConVar("sm_freezebomb_mode", "0", "Who is targetted by the freezebomb? 0 = Target only, 1 = Target's team, 2 = Everyone", 0, true, 0.0, true, 2.0);
   141 	
   142 	AutoExecConfig(true, "funcommands");
   143 }
   144 
   145 RegisterCmds( )
   146 {
   147 	RegAdminCmd("sm_beacon", Command_Beacon, ADMFLAG_SLAY, "sm_beacon <#userid|name> [0/1]");
   148 	RegAdminCmd("sm_timebomb", Command_TimeBomb, ADMFLAG_SLAY, "sm_timebomb <#userid|name> [0/1]");
   149 	RegAdminCmd("sm_burn", Command_Burn, ADMFLAG_SLAY, "sm_burn <#userid|name> [time]");
   150 	RegAdminCmd("sm_firebomb", Command_FireBomb, ADMFLAG_SLAY, "sm_firebomb <#userid|name> [0/1]");
   151 	RegAdminCmd("sm_freeze", Command_Freeze, ADMFLAG_SLAY, "sm_freeze <#userid|name> [time]");
   152 	RegAdminCmd("sm_freezebomb", Command_FreezeBomb, ADMFLAG_SLAY, "sm_freezebomb <#userid|name> [0/1]");
   153 	RegAdminCmd("sm_gravity", Command_Gravity, ADMFLAG_SLAY, "sm_gravity <#userid|name> [amount] - Leave amount off to reset. Amount is 0.0 through 5.0");
   154 	RegAdminCmd("sm_blind", Command_Blind, ADMFLAG_SLAY, "sm_blind <#userid|name> [amount] - Leave amount off to reset.");
   155 	RegAdminCmd("sm_noclip", Command_NoClip, ADMFLAG_SLAY|ADMFLAG_CHEATS, "sm_noclip <#userid|name>");
   156 	RegAdminCmd("sm_drug", Command_Drug, ADMFLAG_SLAY, "sm_drug <#userid|name> [0/1]");
   157 }
   158 
   159 HookEvents( )
   160 {
   161 	decl String:folder[64];
   162 	GetGameFolderName(folder, sizeof(folder));
   163 
   164 	if (strcmp(folder, "tf") == 0)
   165 	{
   166 		HookEvent("teamplay_win_panel", Event_RoundEnd, EventHookMode_PostNoCopy);
   167 		HookEvent("teamplay_restart_round", Event_RoundEnd, EventHookMode_PostNoCopy);
   168 		HookEvent("arena_win_panel", Event_RoundEnd, EventHookMode_PostNoCopy);
   169 	}
   170 	else if (strcmp(folder, "nucleardawn") == 0)
   171 	{
   172 		HookEvent("round_win", Event_RoundEnd, EventHookMode_PostNoCopy);
   173 	}
   174 	else
   175 	{
   176 		HookEvent("round_end", Event_RoundEnd, EventHookMode_PostNoCopy);
   177 	}	
   178 }
   179 
   180 public OnMapStart()
   181 {
   182 	new Handle:gameConfig = LoadGameConfigFile("funcommands.games");
   183 	if (gameConfig == INVALID_HANDLE)
   184 	{
   185 		SetFailState("Unable to load game config funcommands.games");
   186 		return;
   187 	}
   188 	
   189 	if (GameConfGetKeyValue(gameConfig, "SoundBlip", g_BlipSound, sizeof(g_BlipSound)) && g_BlipSound[0])
   190 	{
   191 		PrecacheSound(g_BlipSound, true);
   192 	}
   193 	
   194 	if (GameConfGetKeyValue(gameConfig, "SoundBeep", g_BeepSound, sizeof(g_BeepSound)) && g_BeepSound[0])
   195 	{
   196 		PrecacheSound(g_BeepSound, true);
   197 	}
   198 	
   199 	if (GameConfGetKeyValue(gameConfig, "SoundFinal", g_FinalSound, sizeof(g_FinalSound)) && g_FinalSound[0])
   200 	{
   201 		PrecacheSound(g_FinalSound, true);
   202 	}
   203 	
   204 	if (GameConfGetKeyValue(gameConfig, "SoundBoom", g_BoomSound, sizeof(g_BoomSound)) && g_BoomSound[0])
   205 	{
   206 		PrecacheSound(g_BoomSound, true);
   207 	}
   208 	
   209 	if (GameConfGetKeyValue(gameConfig, "SoundFreeze", g_FreezeSound, sizeof(g_FreezeSound)) && g_FreezeSound[0])
   210 	{
   211 		PrecacheSound(g_FreezeSound, true);
   212 	}
   213 	
   214 	new String:buffer[PLATFORM_MAX_PATH];
   215 	if (GameConfGetKeyValue(gameConfig, "SpriteBeam", buffer, sizeof(buffer)) && buffer[0])
   216 	{
   217 		g_BeamSprite = PrecacheModel(buffer);
   218 	}
   219 	
   220 	if (GameConfGetKeyValue(gameConfig, "SpriteBeam2", buffer, sizeof(buffer)) && buffer[0])
   221 	{
   222 		g_BeamSprite2 = PrecacheModel(buffer);
   223 	}
   224 	
   225 	if (GameConfGetKeyValue(gameConfig, "SpriteExplosion", buffer, sizeof(buffer)) && buffer[0])
   226 	{
   227 		g_ExplosionSprite = PrecacheModel(buffer);
   228 	}
   229 	
   230 	if (GameConfGetKeyValue(gameConfig, "SpriteGlow", buffer, sizeof(buffer)) && buffer[0])
   231 	{
   232 		g_GlowSprite = PrecacheModel(buffer);
   233 	}
   234 	
   235 	if (GameConfGetKeyValue(gameConfig, "SpriteHalo", buffer, sizeof(buffer)) && buffer[0])
   236 	{
   237 		g_HaloSprite = PrecacheModel(buffer);
   238 	}
   239 	
   240 	CloseHandle(gameConfig);
   241 }
   242 
   243 public OnMapEnd()
   244 {
   245 	KillAllBeacons( );
   246 	KillAllTimeBombs();
   247 	KillAllFireBombs();
   248 	KillAllFreezes();
   249 	KillAllDrugs();
   250 }
   251 
   252 public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
   253 {
   254 	KillAllBeacons( );
   255 	KillAllTimeBombs();
   256 	KillAllFireBombs();
   257 	KillAllFreezes();
   258 	KillAllDrugs();
   259 }
   260 
   261 public OnAdminMenuReady(Handle:topmenu)
   262 {
   263 	/* Block us from being called twice */
   264 	if (topmenu == hTopMenu)
   265 	{
   266 		return;
   267 	}
   268 	
   269 	/* Save the Handle */
   270 	hTopMenu = topmenu;
   271 	
   272 	/* Find the "Player Commands" category */
   273 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   274 
   275 	if (player_commands != INVALID_TOPMENUOBJECT)
   276 	{
   277 		AddToTopMenu(hTopMenu,
   278 			"sm_beacon",
   279 			TopMenuObject_Item,
   280 			AdminMenu_Beacon,
   281 			player_commands,
   282 			"sm_beacon",
   283 			ADMFLAG_SLAY);
   284 	
   285 		AddToTopMenu(hTopMenu,
   286 			"sm_timebomb",
   287 			TopMenuObject_Item,
   288 			AdminMenu_TimeBomb,
   289 			player_commands,
   290 			"sm_timebomb",
   291 			ADMFLAG_SLAY);
   292 
   293 		AddToTopMenu(hTopMenu,
   294 			"sm_burn",
   295 			TopMenuObject_Item,
   296 			AdminMenu_Burn,
   297 			player_commands,
   298 			"sm_burn",
   299 			ADMFLAG_SLAY);
   300 		
   301 		AddToTopMenu(hTopMenu,
   302 			"sm_firebomb",
   303 			TopMenuObject_Item,
   304 			AdminMenu_FireBomb,
   305 			player_commands,
   306 			"sm_firebomb",
   307 			ADMFLAG_SLAY);
   308 
   309 		AddToTopMenu(hTopMenu,
   310 			"sm_freeze",
   311 			TopMenuObject_Item,
   312 			AdminMenu_Freeze,
   313 			player_commands,
   314 			"sm_freeze",
   315 			ADMFLAG_SLAY);
   316 			
   317 		AddToTopMenu(hTopMenu,
   318 			"sm_freezebomb",
   319 			TopMenuObject_Item,
   320 			AdminMenu_FreezeBomb,
   321 			player_commands,
   322 			"sm_freezebomb",
   323 			ADMFLAG_SLAY);
   324 
   325 		AddToTopMenu(hTopMenu,
   326 			"sm_gravity",
   327 			TopMenuObject_Item,
   328 			AdminMenu_Gravity,
   329 			player_commands,
   330 			"sm_gravity",
   331 			ADMFLAG_SLAY);
   332 
   333 		AddToTopMenu(hTopMenu,
   334 			"sm_blind",
   335 			TopMenuObject_Item,
   336 			AdminMenu_Blind,
   337 			player_commands,
   338 			"sm_blind",
   339 			ADMFLAG_SLAY);
   340 
   341 		AddToTopMenu(hTopMenu,
   342 			"sm_noclip",
   343 			TopMenuObject_Item,
   344 			AdminMenu_NoClip,
   345 			player_commands,
   346 			"sm_noclip",
   347 			ADMFLAG_SLAY);
   348 
   349 		AddToTopMenu(hTopMenu,
   350 			"sm_drug",
   351 			TopMenuObject_Item,
   352 			AdminMenu_Drug,
   353 			player_commands,
   354 			"sm_drug",
   355 			ADMFLAG_SLAY);
   356 	}
   357 }
   358 
   359 AddTranslatedMenuItem(Handle:menu, const String:opt[], const String:phrase[], client)
   360 {
   361 	decl String:buffer[128];
   362 	Format(buffer, sizeof(buffer), "%T", phrase, client);
   363 	AddMenuItem(menu, opt, buffer);
   364 }
   365