/*
* BombSite Lock
* Version: 0.4
* Author: Bugsy
*
*
* Description
*
* This plugin allows you to lock bombsite(s), preventing them from being used.
* When a bombsite is locked, the player currently holding the bomb will have a HUD message indicating which bombsite(s) are locked.
* Bombsite locks will remain from round to round but not between map changes.
* There are cvars to control if and how bombsites are automatically locked depending on the number of CT players on the server.
*
*
* Commands
*
* amx_setbombsite <A|B> <0|1> - unlocks/locks the specified bombsite
* amx_bombsitemenu - displays bomb site lock menu
*
*
* CVars
*
* bl_allowplantctnum - Minimum number of CT players required to allow bomb planting (both sites would be locked if less).
* Default: 0 (0=disabled or any number as # CT of players)
* bl_locksitectnum - Minimum number of CT players required to have both bombsites open for planting. If there are less CT players, one of the bombsites (defined by cvar bl_locksite) will be locked.
* Default: 2 (0=disabled or any number as # CT of players)
* bl_locksite - The bombsite that will be locked if the number of CT players is less than bl_locksitectnum value.
* Default: b (Must be a or b)
*
*
* Modules
*
* VexdUM
*
*
* ChangeLog
*
* 0.4
* Fixed support for all maps, but not for more than two bombsites (supports now the "info_bomb_target" entities).
* Plugin will be unitialized if there are not two bombsites found at least.
* 0.3
* Added support for all maps (experimental).
* Bombsites on all of the standard CS maps with an A and B designation should all work properly according to A and B naming.
* Maps without an A and B designation will still be treated as A and B by the plugin; A and B is chosen by
* the plugin based on which bombsite entity is spawned first.
* If you notice a map where A and B are handled by the plugin oppositely, let me know and I can correct it.
* Menu will now display only the available commands for use. ie, if A is already locked, "Lock A" menu item will be disabled etc.
* Fixed bug which affected the HUD being displayed to the user holding the bomb.
* Added cvars to control auto-locking of bombsites. See above.
* 0.2
* Initial release
*
*/
/******************************************************************************/
// If you change one of the following settings, do not forget to recompile
// the plugin and to install the new .amx file on your server.
// You can find the list of admin flags in the amx/examples/include/amxconst.inc file.
#define FLAG_AMX_SETBOMBSITE ADMIN_CVAR
#define FLAG_AMX_BOMBSITEMENU ADMIN_CVAR
/******************************************************************************/
#include <translator>
#include <amxmod>
#include <amxmisc>
#include <VexdUM>
enum BombSites
{
BOMBSITE_A,
BOMBSITE_B
}
new g_iBombSiteEntity[ BombSites ];
new bool:g_bBombSiteStatus[ BombSites ];
new bool:g_bIsBombSiteInfo[ BombSites ];
new Float:g_flBombSiteInfoOrigins[ BombSites ][3];
new g_iPlayerWithBomb;
new bool:g_bPlayerHoldingBomb;
new g_iHUDEntity;
new g_pCVarAllowPlantNum;
new g_pCVarLockSiteNum;
new g_pCVarLockSite;
public plugin_init( )
{
load_translations( "bombsite_lock" );
register_plugin( _T( "BombSite Lock" ) , "0.4" , "Bugsy" );
new szMap[ 11 ] , BombSites:bsBombSiteA , BombSites:bsBombSiteB;
get_mapname( szMap , charsmax( szMap ) );
if ( equal( szMap , "de_chateau" ) || equal( szMap , "de_dust2" , 8 ) || equal( szMap , "de_train" ) )
{
bsBombSiteA = BOMBSITE_B;
bsBombSiteB = BOMBSITE_A;
}
else
{
bsBombSiteA = BOMBSITE_A;
bsBombSiteB = BOMBSITE_B;
}
g_iBombSiteEntity[ bsBombSiteA ] = find_entity( -1 , "func_bomb_target" );
if ( g_iBombSiteEntity[ bsBombSiteA ] <= 0 )
{
g_iBombSiteEntity[ bsBombSiteA ] = find_entity( -1 , "info_bomb_target" );
if ( g_iBombSiteEntity[ bsBombSiteA ] > 0 )
{
g_bIsBombSiteInfo[ bsBombSiteA ] = true;
entity_get_vector( g_iBombSiteEntity[ bsBombSiteA ] , EV_VEC_origin , g_flBombSiteInfoOrigins[ bsBombSiteA ] );
}
}
g_iBombSiteEntity[ bsBombSiteB ] = find_entity( g_iBombSiteEntity[ bsBombSiteA ] , "func_bomb_target" );
if ( g_iBombSiteEntity[ bsBombSiteB ] <= 0 )
{
g_iBombSiteEntity[ bsBombSiteB ] = find_entity( g_iBombSiteEntity[ bsBombSiteA ] , "info_bomb_target" );
if ( g_iBombSiteEntity[ bsBombSiteB ] > 0 )
{
g_bIsBombSiteInfo[ bsBombSiteB ] = true;
entity_get_vector( g_iBombSiteEntity[ bsBombSiteB ] , EV_VEC_origin , g_flBombSiteInfoOrigins[ bsBombSiteB ] );
}
}
if ( g_iBombSiteEntity[ BOMBSITE_A ] <= 0 || g_iBombSiteEntity[ BOMBSITE_B ] <= 0 )
{
server_print( _T( "* BombSite Lock: Map ^"%s^" is not supported. Plugin uninitialized." ) , szMap );
return;
}
register_concmd( "amx_setbombsite" , "SetBombSiteConsole" , FLAG_AMX_SETBOMBSITE , _T( "<A|B> <0|1> - unlocks/locks the specified bombsite" ) );
register_concmd( "amx_bombsitemenu" , "ShowBombSiteMenu" , FLAG_AMX_BOMBSITEMENU , _T( "- displays bomb site lock menu" ) );
g_pCVarAllowPlantNum = register_cvar( "bl_allowplantctnum" , "0" );
g_pCVarLockSiteNum = register_cvar( "bl_locksitectnum" , "2" );
g_pCVarLockSite = register_cvar( "bl_locksite" , "b" );
register_event( "CurWeapon" , "fw_EvCurWeapon" , "b" , "1=1" );
register_event( "WeapPickup", "fw_EvWeapPickup" , "be" , "1=6" );
register_event( "BombDrop" , "fw_EvBombDrop" , "bc" );
register_logevent( "fw_EvRoundStart" , 2 , "1=Round_Start" );
register_menucmd( register_menuid( "\yBombSite Lock Menu" ) , (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<9) , "CommandBombSiteMenu" );
g_iHUDEntity = create_entity( "info_target" );
entity_set_string( g_iHUDEntity , EV_SZ_classname , "bl_hud_entity" );
}
public client_disconnect( id )
{
if ( g_iPlayerWithBomb == id )
{
g_iPlayerWithBomb = 0;
g_bPlayerHoldingBomb = false;
}
}
public fw_EvCurWeapon( id )
{
if ( id == g_iPlayerWithBomb )
{
if ( read_data( 2 ) == CSW_C4 )
{
g_bPlayerHoldingBomb = true;
entity_set_float( g_iHUDEntity , EV_FL_nextthink , get_gametime() + 1.0 );
}
else
{
g_bPlayerHoldingBomb = false;
}
}
}
public fw_EvWeapPickup( id )
{
g_iPlayerWithBomb = id;
}
public fw_EvBombDrop()
{
g_iPlayerWithBomb = 0;
g_bPlayerHoldingBomb = false;
}
public fw_EvRoundStart()
{
new iAllowPlantNum = get_cvarptr_num( g_pCVarAllowPlantNum );
new iLockSiteNum = get_cvarptr_num( g_pCVarLockSiteNum );
new iPlayers[ 32 ] , iNum , iCTCount;
get_players( iPlayers , iNum , "h" );
for ( new i = 0 ; i < iNum ; i++ )
if ( get_user_team( iPlayers[ i ] ) == 2 )
iCTCount++;
if ( iCTCount < iAllowPlantNum )
{
SetBombSiteLock( BOMBSITE_A , true );
SetBombSiteLock( BOMBSITE_B , true );
client_print( 0 , print_chat , _T( "* BombSites A & B are both locked since there are less than %d CTs." ) , iAllowPlantNum );
}
else if ( iCTCount < iLockSiteNum )
{
new szSite[ 2 ];
get_cvarptr_string( g_pCVarLockSite , szSite , charsmax( szSite ) );
szSite[ 0 ] = toupper( szSite[ 0 ] );
if ( !( 'A' <= szSite[ 0 ] <= 'B' ) )
return;
SetBombSiteLock( ( szSite[ 0 ] == 'A' ) ? BOMBSITE_A : BOMBSITE_B , true );
SetBombSiteLock( ( szSite[ 0 ] == 'A' ) ? BOMBSITE_B : BOMBSITE_A , false );
client_print( 0 , print_chat , _T( "* BombSite %s has been locked since there are less than %d CTs." ) , szSite , iLockSiteNum );
}
else
{
SetBombSiteLock( BOMBSITE_A , false );
SetBombSiteLock( BOMBSITE_B , false );
}
}
public SetBombSiteConsole( id , AdminLevel , CommandId )
{
if ( !cmd_access( id , AdminLevel , CommandId , 3 ) )
{
return PLUGIN_HANDLED;
}
/*if ( g_iBombSiteEntity[ BOMBSITE_A ] <= 0 || g_iBombSiteEntity[ BOMBSITE_B ] <= 0 )
{
console_print( id , _T( "* BombSite Lock: Sorry, this map is not supported." ) );
return PLUGIN_HANDLED;
}*/
new szSite[ 3 ] , szState[ 3 ] , iState , BombSites:bsSite;
read_argv( 1 , szSite , charsmax( szSite ) );
read_argv( 2 , szState , charsmax( szState ) );
iState = str_to_num( szState );
if ( strlen( szSite ) > 1 || !is_str_num( szState ) || !( 0 <= iState <= 1 ) )
szSite[ 0 ] = 'X';
else
szSite[ 0 ] = toupper( szSite[ 0 ] );
switch ( szSite[ 0 ] )
{
case 'A':
{
bsSite = BOMBSITE_A;
}
case 'B':
{
bsSite = BOMBSITE_B;
}
default:
{
console_print( id , _T( "Usage: amx_setbombsite <A|B> <0|1> - unlocks/locks the specified bombsite" ) );
return PLUGIN_HANDLED;
}
}
SetBombSiteLock( bsSite , bool:iState );
console_print( id , _T( "* BombSite %s has been %s." ) , szSite , iState ? _T( "locked" ) : _T( "unlocked" ) );
set_hudmessage( 255 , 165 , 000 , -1.0 , 0.65 , 0 , 3.0 , 3.0 , .channel = -1 );
show_hudmessage( 0 , _T( "BombSite %s has been %s..." ) , szSite , iState ? _T( "locked" ) : _T( "unlocked" ) );
return PLUGIN_HANDLED;
}
public ShowBombSiteMenu( id , AdminLevel )
{
if ( !access( id , AdminLevel ) )
{
console_print( id , _T( "You have no access to that command." ) );
return PLUGIN_HANDLED;
}
/*if ( g_iBombSiteEntity[ BOMBSITE_A ] <= 0 || g_iBombSiteEntity[ BOMBSITE_B ] <= 0 )
{
console_print( id , _T( "* BombSite Lock: Sorry, this map is not supported." ) );
return PLUGIN_HANDLED;
}*/
DisplayBombSiteMenu( id );
return PLUGIN_HANDLED;
}
DisplayBombSiteMenu( id )
{
new szMenu[ 256 ] , iKeys = (1<<9);
new iLen = copy( szMenu , charsmax( szMenu ) , _T( "\yBombSite Lock Menu\w" , id ) );
if ( g_bBombSiteStatus[ BOMBSITE_A ] )
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n^n\d1. Lock A" , id ) );
else
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n^n\w1. Lock A" , id ) );
iKeys |= (1<<0);
}
if ( g_bBombSiteStatus[ BOMBSITE_B ] )
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\d2. Lock B" , id ) );
else
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\w2. Lock B" , id ) );
iKeys |= (1<<1);
}
if ( g_bBombSiteStatus[ BOMBSITE_A ] )
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\w3. Unlock A" , id ) );
iKeys |= (1<<2);
}
else
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\d3. Unlock A" , id ) );
if ( g_bBombSiteStatus[ BOMBSITE_B ] )
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\w4. Unlock B" , id ) );
iKeys |= (1<<3);
}
else
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\d4. Unlock B" , id ) );
if ( g_bBombSiteStatus[ BOMBSITE_A ] && g_bBombSiteStatus[ BOMBSITE_B ] )
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\d5. Lock A & B" , id ) );
else
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\w5. Lock A & B" , id ) );
iKeys |= (1<<4);
}
if (g_bBombSiteStatus[ BOMBSITE_A ] || g_bBombSiteStatus[ BOMBSITE_B ] )
{
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\w6. Unlock A & B" , id ) );
iKeys |= (1<<5);
}
else
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n\d6. Unlock A & B" , id ) );
iLen += copy( szMenu[ iLen ] , charsmax( szMenu ) - iLen , _T( "^n^n\w0. Exit" , id ) );
show_menu( id , iKeys , szMenu , _ , "\yBombSite Lock Menu" );
}
public CommandBombSiteMenu( id , iKey )
{
set_hudmessage( 255 , 165 , 000 , -1.0 , 0.65 , 0 , 3.0 , 3.0 , .channel = -1 );
switch ( iKey )
{
case 0:
{
SetBombSiteLock( BOMBSITE_A , true );
show_hudmessage( 0 , _T( "BombSite A has been locked..." ) );
}
case 1:
{
SetBombSiteLock( BOMBSITE_B , true );
show_hudmessage( 0 , _T( "BombSite B has been locked..." ) );
}
case 2:
{
SetBombSiteLock( BOMBSITE_A , false );
show_hudmessage( 0 , _T( "BombSite A has been unlocked..." ) );
}
case 3:
{
SetBombSiteLock( BOMBSITE_B , false );
show_hudmessage( 0 , _T( "BombSite B has been unlocked..." ) );
}
case 4:
{
SetBombSiteLock( BOMBSITE_A , true );
SetBombSiteLock( BOMBSITE_B , true );
show_hudmessage( 0 , _T( "BombSites A & B have both been locked..." ) );
}
case 5:
{
SetBombSiteLock( BOMBSITE_A , false );
SetBombSiteLock( BOMBSITE_B , false );
show_hudmessage( 0 , _T( "BombSites A & B have both been unlocked..." ) );
}
}
if( 0 <= iKey <= 5 )
DisplayBombSiteMenu( id );
}
public entity_think( iEntity )
{
if ( iEntity == g_iHUDEntity )
{
if( g_bPlayerHoldingBomb &&
( g_bBombSiteStatus[ BOMBSITE_A ] || g_bBombSiteStatus[ BOMBSITE_B ] ) && is_user_alive( g_iPlayerWithBomb ) )
{
set_hudmessage( 255 , 165 , 000 , -1.0 , 0.87 , 0 , 1.0 , 1.0 , .channel = -1 );
show_hudmessage( g_iPlayerWithBomb , _T( "BombSite%s %s%s%s %s currently locked!" ) ,
g_bBombSiteStatus[ BOMBSITE_A ] && g_bBombSiteStatus[ BOMBSITE_B ] ? "s" : "" ,
g_bBombSiteStatus[ BOMBSITE_A ] ? "A" : "" ,
g_bBombSiteStatus[ BOMBSITE_A ] && g_bBombSiteStatus[ BOMBSITE_B ] ? " & " : "" ,
g_bBombSiteStatus[ BOMBSITE_B ] ? "B" : "" ,
g_bBombSiteStatus[ BOMBSITE_A ] && g_bBombSiteStatus[ BOMBSITE_B ] ? _T( "are" ) : _T( "is" ) );
entity_set_float( g_iHUDEntity , EV_FL_nextthink , ( get_gametime() + 1.0 ) );
}
}
}
SetBombSiteLock( BombSites:bsBombSite , bool:bLockState )
{
if ( g_bIsBombSiteInfo[ bsBombSite ] )
{
if( bLockState )
entity_set_origin( g_iBombSiteEntity[ bsBombSite ] , Float:{99999.0, 99999.0, 99999.0} );
else
entity_set_origin( g_iBombSiteEntity[ bsBombSite ] , g_flBombSiteInfoOrigins[ bsBombSite ] );
}
else
{
entity_set_int( g_iBombSiteEntity[ bsBombSite ] , EV_INT_solid , bLockState ? SOLID_NOT : SOLID_TRIGGER );
}
g_bBombSiteStatus[ bsBombSite ] = bLockState;
if ( bLockState )
entity_set_float( g_iHUDEntity , EV_FL_nextthink , ( get_gametime() + 1.0 ) );
}