2008-03-30 09:00:22 +02:00
/ * *
* vim : set ts = 4 :
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* SourceMod Basic Fun Commands Plugin
* Implements basic punishment commands .
*
* SourceMod ( C ) 2004 - 2008 AlliedModders LLC . All rights reserved .
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License , version 3.0 , as published by the
* Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License along with
* this program . If not , see < http : //www.gnu.org/licenses/>.
*
* As a special exception , AlliedModders LLC gives you permission to link the
* code of this program ( as well as its derivative works ) to " Half-Life 2, " the
* " Source Engine, " the " SourcePawn JIT, " and any Game MODs that run on software
* by the Valve Corporation . You must obey the GNU General Public License in
* all respects for all other code used . Additionally , AlliedModders LLC grants
* this exception to all derivative works . AlliedModders LLC defines further
* exceptions , found in LICENSE . txt ( as of this writing , version JULY - 31 - 2007 ) ,
* or < http : //www.sourcemod.net/license.php>.
*
* Version : $ Id $
* /
# pragma semicolon 1
# include <sourcemod>
# include <sdktools>
# undef REQUIRE_PLUGIN
# include <adminmenu>
2016-05-11 16:56:12 +02:00
# pragma newdecls required
public Plugin myinfo =
2008-03-30 09:00:22 +02:00
{
name = " Fun Commands " ,
author = " AlliedModders LLC " ,
description = " Fun Commands " ,
version = SOURCEMOD_VERSION ,
url = " http://www.sourcemod.net/ "
} ;
2009-01-08 01:21:54 +01:00
// Admin Menu
2014-10-29 03:03:38 +01:00
TopMenu hTopMenu ;
2008-03-30 09:00:22 +02:00
// Sounds
2016-05-11 16:56:12 +02:00
char g_BlipSound [ PLATFORM_MAX_PATH ] ;
char g_BeepSound [ PLATFORM_MAX_PATH ] ;
char g_FinalSound [ PLATFORM_MAX_PATH ] ;
char g_BoomSound [ PLATFORM_MAX_PATH ] ;
char g_FreezeSound [ PLATFORM_MAX_PATH ] ;
2008-03-30 09:00:22 +02:00
// Following are model indexes for temp entities
2016-05-11 16:56:12 +02:00
int g_BeamSprite = - 1 ;
int g_BeamSprite2 = - 1 ;
int g_HaloSprite = - 1 ;
int g_GlowSprite = - 1 ;
int g_ExplosionSprite = - 1 ;
2008-03-30 09:00:22 +02:00
// Basic color arrays for temp entities
2016-05-11 16:56:12 +02:00
int orangeColor [ 4 ] = { 255 , 128 , 0 , 255 } ;
int blueColor [ 4 ] = { 75 , 75 , 255 , 255 } ;
int whiteColor [ 4 ] = { 255 , 255 , 255 , 255 } ;
int greyColor [ 4 ] = { 128 , 128 , 128 , 255 } ;
2008-03-30 09:00:22 +02:00
Change sm_beacon to use game-specific team colors (#1187)
Added game color config & specific settings for L4D/L4D2
Created the following keys:
"Team1Color" "75,255,75,255"
"Team2Color" "255,75,75,255"
"Team3Color" "75,75,255,255"
"Team4Color" "255,128,0,255"
"TeamUnknownColor" "255,255,255,255"
Added a specific setting for L4D/L4D2 game:
"Team2Color" "75,75,255,255"
"Team3Color" "255,75,75,255"
2020-02-23 15:03:00 +01:00
int g_ExternalBeaconColor [ 4 ] ;
int g_Team1BeaconColor [ 4 ] ;
int g_Team2BeaconColor [ 4 ] ;
int g_Team3BeaconColor [ 4 ] ;
int g_Team4BeaconColor [ 4 ] ;
int g_TeamUnknownBeaconColor [ 4 ] ;
2008-03-30 09:00:22 +02:00
// UserMessageId for Fade.
2016-05-11 16:56:12 +02:00
UserMsg g_FadeUserMsgId ;
2008-03-30 09:00:22 +02:00
2009-01-08 01:21:54 +01:00
// Serial Generator for Timer Safety
2016-05-11 16:56:12 +02:00
int g_Serial_Gen = 0 ;
2009-01-08 01:21:54 +01:00
2016-05-11 16:56:12 +02:00
EngineVersion g_GameEngine = Engine_Unknown ;
2009-02-18 09:19:22 +01:00
2009-01-08 01:21:54 +01:00
// Flags used in various timers
# define DEFAULT_TIMER_FLAGS TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE
2008-03-30 09:00:22 +02:00
// Include various commands and supporting functions
# include "funcommands/beacon.sp"
# include "funcommands/timebomb.sp"
# include "funcommands/fire.sp"
# include "funcommands/ice.sp"
# include "funcommands/gravity.sp"
# include "funcommands/blind.sp"
# include "funcommands/noclip.sp"
# include "funcommands/drug.sp"
2016-05-11 16:56:12 +02:00
public void OnPluginStart ( )
2008-03-30 09:00:22 +02:00
{
2014-11-16 01:30:45 +01:00
if ( FindPluginByFile ( " basefuncommands.smx " ) ! = null )
2008-03-30 09:00:22 +02:00
{
ThrowError ( " This plugin replaces basefuncommands. You cannot run both at once. " ) ;
}
LoadTranslations ( " common.phrases " ) ;
2008-04-22 02:44:14 +02:00
LoadTranslations ( " funcommands.phrases " ) ;
2013-07-21 17:53:56 +02:00
g_GameEngine = GetEngineVersion ( ) ;
2008-03-30 09:00:22 +02:00
g_FadeUserMsgId = GetUserMessageId ( " Fade " ) ;
2016-05-11 16:56:12 +02:00
RegisterCvars ( ) ;
RegisterCmds ( ) ;
HookEvents ( ) ;
2008-03-30 09:00:22 +02:00
/* Account for late loading */
2014-10-29 03:03:38 +01:00
TopMenu topmenu ;
if ( LibraryExists ( " adminmenu " ) & & ( ( topmenu = GetAdminTopMenu ( ) ) ! = null ) )
2008-03-30 09:00:22 +02:00
{
OnAdminMenuReady ( topmenu ) ;
}
}
2016-05-11 16:56:12 +02:00
void RegisterCvars ( )
2009-01-08 01:21:54 +01:00
{
// beacon
g_Cvar_BeaconRadius = CreateConVar ( " sm_beacon_radius " , " 375 " , " Sets the radius for beacon's light rings. " , 0 , true , 50.0 , true , 1500.0 ) ;
// timebomb
g_Cvar_TimeBombTicks = CreateConVar ( " sm_timebomb_ticks " , " 10.0 " , " Sets how long the timebomb fuse is. " , 0 , true , 5.0 , true , 120.0 ) ;
g_Cvar_TimeBombRadius = CreateConVar ( " sm_timebomb_radius " , " 600 " , " Sets the bomb blast radius. " , 0 , true , 50.0 , true , 3000.0 ) ;
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 ) ;
// fire
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 ) ;
g_Cvar_FireBombTicks = CreateConVar ( " sm_firebomb_ticks " , " 10.0 " , " Sets how long the FireBomb fuse is. " , 0 , true , 5.0 , true , 120.0 ) ;
g_Cvar_FireBombRadius = CreateConVar ( " sm_firebomb_radius " , " 600 " , " Sets the bomb blast radius. " , 0 , true , 50.0 , true , 3000.0 ) ;
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 ) ;
// ice
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 ) ;
g_Cvar_FreezeBombTicks = CreateConVar ( " sm_freezebomb_ticks " , " 10.0 " , " Sets how long the freezebomb fuse is. " , 0 , true , 5.0 , true , 120.0 ) ;
g_Cvar_FreezeBombRadius = CreateConVar ( " sm_freezebomb_radius " , " 600 " , " Sets the freezebomb blast radius. " , 0 , true , 50.0 , true , 3000.0 ) ;
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 ) ;
AutoExecConfig ( true , " funcommands " ) ;
}
2016-05-11 16:56:12 +02:00
void RegisterCmds ( )
2009-01-08 01:21:54 +01:00
{
RegAdminCmd ( " sm_beacon " , Command_Beacon , ADMFLAG_SLAY , " sm_beacon <#userid|name> [0/1] " ) ;
RegAdminCmd ( " sm_timebomb " , Command_TimeBomb , ADMFLAG_SLAY , " sm_timebomb <#userid|name> [0/1] " ) ;
RegAdminCmd ( " sm_burn " , Command_Burn , ADMFLAG_SLAY , " sm_burn <#userid|name> [time] " ) ;
RegAdminCmd ( " sm_firebomb " , Command_FireBomb , ADMFLAG_SLAY , " sm_firebomb <#userid|name> [0/1] " ) ;
RegAdminCmd ( " sm_freeze " , Command_Freeze , ADMFLAG_SLAY , " sm_freeze <#userid|name> [time] " ) ;
RegAdminCmd ( " sm_freezebomb " , Command_FreezeBomb , ADMFLAG_SLAY , " sm_freezebomb <#userid|name> [0/1] " ) ;
RegAdminCmd ( " sm_gravity " , Command_Gravity , ADMFLAG_SLAY , " sm_gravity <#userid|name> [amount] - Leave amount off to reset. Amount is 0.0 through 5.0 " ) ;
RegAdminCmd ( " sm_blind " , Command_Blind , ADMFLAG_SLAY , " sm_blind <#userid|name> [amount] - Leave amount off to reset. " ) ;
RegAdminCmd ( " sm_noclip " , Command_NoClip , ADMFLAG_SLAY | ADMFLAG_CHEATS , " sm_noclip <#userid|name> " ) ;
RegAdminCmd ( " sm_drug " , Command_Drug , ADMFLAG_SLAY , " sm_drug <#userid|name> [0/1] " ) ;
}
2016-05-11 16:56:12 +02:00
void HookEvents ( )
2009-01-08 01:21:54 +01:00
{
2016-05-11 16:56:12 +02:00
char folder [ 64 ] ;
2011-10-12 01:47:20 +02:00
GetGameFolderName ( folder , sizeof ( folder ) ) ;
if ( strcmp ( folder , " tf " ) = = 0 )
{
HookEvent ( " teamplay_win_panel " , Event_RoundEnd , EventHookMode_PostNoCopy ) ;
HookEvent ( " teamplay_restart_round " , Event_RoundEnd , EventHookMode_PostNoCopy ) ;
HookEvent ( " arena_win_panel " , Event_RoundEnd , EventHookMode_PostNoCopy ) ;
}
else if ( strcmp ( folder , " nucleardawn " ) = = 0 )
{
HookEvent ( " round_win " , Event_RoundEnd , EventHookMode_PostNoCopy ) ;
}
else
{
HookEvent ( " round_end " , Event_RoundEnd , EventHookMode_PostNoCopy ) ;
}
2009-01-08 01:21:54 +01:00
}
2016-05-11 16:56:12 +02:00
public void OnMapStart ( )
2008-03-30 09:00:22 +02:00
{
2018-10-12 05:27:56 +02:00
GameData gameConfig = new GameData ( " funcommands.games " ) ;
2014-11-16 01:30:45 +01:00
if ( gameConfig = = null )
2014-03-29 20:07:07 +01:00
{
SetFailState ( " Unable to load game config funcommands.games " ) ;
return ;
2014-03-29 20:07:07 +01:00
}
2014-03-29 20:07:07 +01:00
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SoundBlip " , g_BlipSound , sizeof ( g_BlipSound ) ) & & g_BlipSound [ 0 ] )
2014-03-29 20:07:07 +01:00
{
PrecacheSound ( g_BlipSound , true ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SoundBeep " , g_BeepSound , sizeof ( g_BeepSound ) ) & & g_BeepSound [ 0 ] )
2014-03-29 20:07:07 +01:00
{
PrecacheSound ( g_BeepSound , true ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SoundFinal " , g_FinalSound , sizeof ( g_FinalSound ) ) & & g_FinalSound [ 0 ] )
2014-03-29 20:07:07 +01:00
{
PrecacheSound ( g_FinalSound , true ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SoundBoom " , g_BoomSound , sizeof ( g_BoomSound ) ) & & g_BoomSound [ 0 ] )
2014-03-29 20:07:07 +01:00
{
PrecacheSound ( g_BoomSound , true ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SoundFreeze " , g_FreezeSound , sizeof ( g_FreezeSound ) ) & & g_FreezeSound [ 0 ] )
2014-03-29 20:07:07 +01:00
{
PrecacheSound ( g_FreezeSound , true ) ;
}
2016-05-11 16:56:12 +02:00
char buffer [ PLATFORM_MAX_PATH ] ;
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SpriteBeam " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
2014-03-29 20:07:07 +01:00
{
g_BeamSprite = PrecacheModel ( buffer ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SpriteBeam2 " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
2014-03-29 20:07:07 +01:00
{
g_BeamSprite2 = PrecacheModel ( buffer ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SpriteExplosion " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
2014-03-29 20:07:07 +01:00
{
g_ExplosionSprite = PrecacheModel ( buffer ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SpriteGlow " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
2014-03-29 20:07:07 +01:00
{
g_GlowSprite = PrecacheModel ( buffer ) ;
}
2018-10-12 05:27:56 +02:00
if ( gameConfig . GetKeyValue ( " SpriteHalo " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
2010-07-26 14:15:52 +02:00
{
2014-03-29 20:07:07 +01:00
g_HaloSprite = PrecacheModel ( buffer ) ;
2010-07-26 14:15:52 +02:00
}
Change sm_beacon to use game-specific team colors (#1187)
Added game color config & specific settings for L4D/L4D2
Created the following keys:
"Team1Color" "75,255,75,255"
"Team2Color" "255,75,75,255"
"Team3Color" "75,75,255,255"
"Team4Color" "255,128,0,255"
"TeamUnknownColor" "255,255,255,255"
Added a specific setting for L4D/L4D2 game:
"Team2Color" "75,75,255,255"
"Team3Color" "255,75,75,255"
2020-02-23 15:03:00 +01:00
if ( gameConfig . GetKeyValue ( " ExternalBeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_ExternalBeaconColor = ParseColor ( buffer ) ;
}
if ( gameConfig . GetKeyValue ( " Team1BeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_Team1BeaconColor = ParseColor ( buffer ) ;
}
if ( gameConfig . GetKeyValue ( " Team2BeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_Team2BeaconColor = ParseColor ( buffer ) ;
}
if ( gameConfig . GetKeyValue ( " Team3BeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_Team3BeaconColor = ParseColor ( buffer ) ;
}
if ( gameConfig . GetKeyValue ( " Team4BeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_Team4BeaconColor = ParseColor ( buffer ) ;
}
if ( gameConfig . GetKeyValue ( " TeamUnknownBeaconColor " , buffer , sizeof ( buffer ) ) & & buffer [ 0 ] )
{
g_TeamUnknownBeaconColor = ParseColor ( buffer ) ;
}
2014-11-16 01:30:45 +01:00
delete gameConfig ;
2008-03-30 09:00:22 +02:00
}
2016-05-11 16:56:12 +02:00
public void OnMapEnd ( )
2008-03-30 09:00:22 +02:00
{
2016-05-11 16:56:12 +02:00
KillAllBeacons ( ) ;
2008-03-30 09:00:22 +02:00
KillAllTimeBombs ( ) ;
KillAllFireBombs ( ) ;
KillAllFreezes ( ) ;
KillAllDrugs ( ) ;
}
2016-05-11 16:56:12 +02:00
public Action Event_RoundEnd ( Event event , const char [ ] name , bool dontBroadcast )
2008-03-30 09:00:22 +02:00
{
2016-05-11 16:56:12 +02:00
KillAllBeacons ( ) ;
2008-03-30 09:00:22 +02:00
KillAllTimeBombs ( ) ;
KillAllFireBombs ( ) ;
KillAllFreezes ( ) ;
KillAllDrugs ( ) ;
2021-08-04 16:46:15 +02:00
return Plugin_Continue ;
2008-03-30 09:00:22 +02:00
}
2016-05-11 16:56:12 +02:00
public void OnAdminMenuReady ( Handle aTopMenu )
2008-03-30 09:00:22 +02:00
{
2014-12-12 08:34:00 +01:00
TopMenu topmenu = TopMenu . FromHandle ( aTopMenu ) ;
2008-03-30 09:00:22 +02:00
/* Block us from being called twice */
if ( topmenu = = hTopMenu )
{
return ;
}
/* Save the Handle */
hTopMenu = topmenu ;
/* Find the "Player Commands" category */
2014-10-29 03:03:38 +01:00
TopMenuObject player_commands = hTopMenu . FindCategory ( ADMINMENU_PLAYERCOMMANDS ) ;
2008-03-30 09:00:22 +02:00
if ( player_commands ! = INVALID_TOPMENUOBJECT )
{
2014-10-29 03:03:38 +01:00
hTopMenu . AddItem ( " sm_beacon " , AdminMenu_Beacon , player_commands , " sm_beacon " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_timebomb " , AdminMenu_TimeBomb , player_commands , " sm_timebomb " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_burn " , AdminMenu_Burn , player_commands , " sm_burn " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_firebomb " , AdminMenu_FireBomb , player_commands , " sm_firebomb " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_freeze " , AdminMenu_Freeze , player_commands , " sm_freeze " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_freezebomb " , AdminMenu_FreezeBomb , player_commands , " sm_freezebomb " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_gravity " , AdminMenu_Gravity , player_commands , " sm_gravity " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_blind " , AdminMenu_Blind , player_commands , " sm_blind " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_noclip " , AdminMenu_NoClip , player_commands , " sm_noclip " , ADMFLAG_SLAY ) ;
hTopMenu . AddItem ( " sm_drug " , AdminMenu_Drug , player_commands , " sm_drug " , ADMFLAG_SLAY ) ;
2008-03-30 09:00:22 +02:00
}
}
2014-11-16 01:30:45 +01:00
void AddTranslatedMenuItem ( Menu menu , const char [ ] opt , const char [ ] phrase , int client )
2013-04-08 14:00:13 +02:00
{
2014-11-16 01:30:45 +01:00
char buffer [ 128 ] ;
2013-04-08 14:00:13 +02:00
Format ( buffer , sizeof ( buffer ) , " %T " , phrase , client ) ;
2014-11-16 01:30:45 +01:00
menu . AddItem ( opt , buffer ) ;
2013-04-08 14:00:13 +02:00
}
Change sm_beacon to use game-specific team colors (#1187)
Added game color config & specific settings for L4D/L4D2
Created the following keys:
"Team1Color" "75,255,75,255"
"Team2Color" "255,75,75,255"
"Team3Color" "75,75,255,255"
"Team4Color" "255,128,0,255"
"TeamUnknownColor" "255,255,255,255"
Added a specific setting for L4D/L4D2 game:
"Team2Color" "75,75,255,255"
"Team3Color" "255,75,75,255"
2020-02-23 15:03:00 +01:00
int [ ] ParseColor ( const char [ ] buffer )
{
char sColor [ 16 ] [ 4 ] ;
ExplodeString ( buffer , " , " , sColor , sizeof ( sColor ) , sizeof ( sColor [ ] ) ) ;
int iColor [ 4 ] ;
iColor [ 0 ] = StringToInt ( sColor [ 0 ] ) ;
iColor [ 1 ] = StringToInt ( sColor [ 1 ] ) ;
iColor [ 2 ] = StringToInt ( sColor [ 2 ] ) ;
iColor [ 3 ] = StringToInt ( sColor [ 3 ] ) ;
return iColor ;
}