#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >
#include < reapi >
#define gmsgDamage 71
#define TD_GIVE_HEALTH 50.0 // How many health will be give
#define TD_LOSE_HEALTH 10.0 // How many health will be lose
#define TD_MAX_HEALTH 100.0 // Max HP can be on player
#define TD_MIN_HEALTH 1.0 // Min health points (HP) on player
new const ENABLED_CMDS[ ][ ] = { "sv_restart 1" }; // Executed commands turn on mode
new const DISABLED_CMDS[ ][ ] = { "sv_restart 1" }; // Executed commands turn off mode
new bool: g_bModeEnabled;
new HookChain: g_hCBasePlayerTraceAttackPost;
new HookChain: g_hCBasePlayerTakeDamagePost;
new HookChain: g_hCBasePlayerKilledPost;
new HamHook: g_hPrimariesPrimaryAttackPre[ 18 ];
new HamHook: g_hPrimariesPrimaryAttackPost[ 18 ];
new HamHook: g_hSecondariesPrimaryAttackPre[ 6 ];
new HamHook: g_hSecondariesPrimaryAttackPost[ 6 ];
public plugin_init( )
{
register_plugin( "Mode: Trigger Discipline", "0.0.2b", "wopox1337 @ Dev-Cs.Ru" );
new cvar_toogle = create_cvar( "mp_gamemode_trigger_discipline", "0", FCVAR_PROTECTED, "Toggle Trigger Discipline mode.", true, 0.0, true, 1.0 );
hook_cvar_change( cvar_toogle, "@CCvar_HookChange" );
bind_pcvar_num( cvar_toogle, g_bModeEnabled );
DisableHookChain( g_hCBasePlayerTraceAttackPost = RegisterHookChain( RG_CBasePlayer_TraceAttack, "@CBasePlayer_TraceAttack_Post", true ) );
DisableHookChain( g_hCBasePlayerTakeDamagePost = RegisterHookChain( RG_CBasePlayer_TakeDamage, "@CBasePlayer_TakeDamage_Post", true ) );
DisableHookChain( g_hCBasePlayerKilledPost = RegisterHookChain( RG_CBasePlayer_Killed, "@CBasePlayer_Killed_Post", true ) );
new const szPrimaries[ 18 ][ ] = { "weapon_scout", "weapon_xm1014", "weapon_mac10", "weapon_aug", "weapon_ump45", "weapon_sg550", "weapon_galil", "weapon_famas", "weapon_awp", "weapon_mp5navy", "weapon_m249", "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_sg552", "weapon_ak47", "weapon_p90" };
new const szSecondaries[ 6 ][ ] = { "weapon_p228", "weapon_elite", "weapon_fiveseven", "weapon_usp", "weapon_glock18", "weapon_deagle" };
new i;
for( i = 0; i < sizeof szPrimaries; i++ )
{
DisableHamForward( g_hPrimariesPrimaryAttackPre[ i ] = RegisterHam( Ham_Weapon_PrimaryAttack, szPrimaries[ i ], "@CPrimaries_PrimaryAttack_Pre", false ) );
DisableHamForward( g_hPrimariesPrimaryAttackPost[ i ] = RegisterHam( Ham_Weapon_PrimaryAttack, szPrimaries[ i ], "@CPrimaries_PrimaryAttack_Post", true ) );
}
for( i = 0; i < sizeof szSecondaries; i++ )
{
DisableHamForward( g_hSecondariesPrimaryAttackPre[ i ] = RegisterHam( Ham_Weapon_PrimaryAttack, szSecondaries[ i ], "@CSecondaries_PrimaryAttack_Pre", false ) );
DisableHamForward( g_hSecondariesPrimaryAttackPost[ i ] = RegisterHam( Ham_Weapon_PrimaryAttack, szSecondaries[ i ], "@CSecondaries_PrimaryAttack_Post", true ) );
}
}
@CCvar_HookChange( iCvar )
{
CTriggerDiscipline__ToogleStatus( g_bModeEnabled );
log_amx( "[Trigger Discipline] Mode is %s.", g_bModeEnabled ? "enabled" : "disabled" );
}
@CBasePlayer_Killed_Post( iVictim, iAttacker, iGib )
{
if( !is_user_connected( iAttacker ) || iVictim == iAttacker )
return;
set_entvar( iAttacker, var_health, floatmin( Float: get_entvar( iAttacker, var_health ) + TD_GIVE_HEALTH, TD_MAX_HEALTH ) );
}
@CBasePlayer_TraceAttack_Post( iVictim, iAttacker, Float: flDamage, Float: vecDir[ 3 ], iTrace, iBitsDamage )
{
DisableHookChain( g_hCBasePlayerTraceAttackPost );
if( !is_user_connected( iAttacker ) || iVictim == iAttacker )
return;
if( !rg_is_player_can_takedamage( iVictim, iAttacker ) )
return;
for( new i = 0; i < 6; i++ )
DisableHamForward( g_hSecondariesPrimaryAttackPost[ i ] );
}
@CBasePlayer_TakeDamage_Post( iVictim, iInflictor, iAttacker, Float: flDamage, iBitsDamage )
{
DisableHookChain( g_hCBasePlayerTakeDamagePost );
if( !is_user_connected( iAttacker ) || iVictim == iAttacker )
return;
if( !rg_is_player_can_takedamage( iVictim, iAttacker ) )
return;
for( new i = 0; i < 18; i++ )
DisableHamForward( g_hPrimariesPrimaryAttackPost[ i ] );
}
@CPrimaries_PrimaryAttack_Pre( iEntity )
{
EnableHookChain( g_hCBasePlayerTakeDamagePost );
if( get_member( iEntity, m_Weapon_fFireOnEmpty ) )
return HAM_IGNORED;
for( new i = 0; i < 18; i++ )
EnableHamForward( g_hPrimariesPrimaryAttackPost[ i ] );
return HAM_IGNORED;
}
@CPrimaries_PrimaryAttack_Post( iEntity )
{
for( new i = 0; i < 18; i++ )
DisableHamForward( g_hPrimariesPrimaryAttackPost[ i ] );
CTriggerDiscipline_InflictDamage( get_member( iEntity, m_pPlayer ) );
}
@CSecondaries_PrimaryAttack_Pre( iEntity )
{
EnableHookChain( g_hCBasePlayerTraceAttackPost );
if( get_member( iEntity, m_Weapon_fFireOnEmpty ) || get_member( iEntity, m_Weapon_iShotsFired ) )
return HAM_IGNORED;
for( new i = 0; i < 6; i++ )
EnableHamForward( g_hSecondariesPrimaryAttackPost[ i ] );
return HAM_IGNORED;
}
@CSecondaries_PrimaryAttack_Post( iEntity )
{
for( new i = 0; i < 6; i++ )
DisableHamForward( g_hSecondariesPrimaryAttackPost[ i ] );
CTriggerDiscipline_InflictDamage( get_member( iEntity, m_pPlayer ) );
}
CTriggerDiscipline__ToogleStatus( iStatus )
{
new i;
switch( iStatus )
{
case true:
{
EnableHookChain( g_hCBasePlayerTraceAttackPost );
EnableHookChain( g_hCBasePlayerTakeDamagePost );
EnableHookChain( g_hCBasePlayerKilledPost );
for( i = 0; i < 18; i++ )
{
EnableHamForward( g_hPrimariesPrimaryAttackPre[ i ] );
EnableHamForward( g_hPrimariesPrimaryAttackPost[ i ] );
}
for( i = 0; i < 6; i++ )
{
EnableHamForward( g_hSecondariesPrimaryAttackPre[ i ] );
EnableHamForward( g_hSecondariesPrimaryAttackPost[ i ] );
}
CTriggerDiscipline__ExecCmds( ENABLED_CMDS, sizeof ENABLED_CMDS );
}
case false:
{
DisableHookChain( g_hCBasePlayerTraceAttackPost );
DisableHookChain( g_hCBasePlayerTakeDamagePost );
DisableHookChain( g_hCBasePlayerKilledPost );
for( i = 0; i < 18; i++ )
{
DisableHamForward( g_hPrimariesPrimaryAttackPre[ i ] );
DisableHamForward( g_hPrimariesPrimaryAttackPost[ i ] );
}
for( i = 0; i < 6; i++ )
{
DisableHamForward( g_hSecondariesPrimaryAttackPre[ i ] );
DisableHamForward( g_hSecondariesPrimaryAttackPost[ i ] );
}
CTriggerDiscipline__ExecCmds( DISABLED_CMDS, sizeof DISABLED_CMDS );
}
}
}
CTriggerDiscipline_InflictDamage( iPlayer )
{
new Float: vecOrigin[ 3 ];
get_entvar( iPlayer, var_origin, vecOrigin );
message_begin( MSG_ONE_UNRELIABLE, gmsgDamage, _, iPlayer );
write_byte( 0 );
write_byte( 1 );
write_long( DMG_BULLET );
engfunc( EngFunc_WriteCoord, vecOrigin[ 0 ] );
engfunc( EngFunc_WriteCoord, vecOrigin[ 1 ] );
engfunc( EngFunc_WriteCoord, vecOrigin[ 2 ] );
message_end( );
set_entvar( iPlayer, var_health, floatmax( Float: get_entvar( iPlayer, var_health ) - TD_LOSE_HEALTH, TD_MIN_HEALTH ) );
}
CTriggerDiscipline__ExecCmds( const szBuffer[ ][ ], iLen )
{
for( new i = 0; i < iLen; i++ )
server_cmd( szBuffer[ i ] );
}