|
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
|

04-25-2020
, 11:47
Re: CT AFK Slayer
|
#8
|
Not thoroughly tested. I am thinking chat may be better over HUD since the AFK HUDs can appear at random as people go AFK.
Cvars: - as_slaytime - Seconds until player is slayed. Default: 30
- as_slaymode - 0=all, 1=T only, 2=CT only. Default: 2
- as_spectatorslays - Number of slays until player moved to spectator. Players counter gets reset to 0 when the player moves. This would cover if the player got moved to spec but continued to be AFK, he'd get moved back right away. This makes it essentially work as a consecutive AFK move to spectator, instead of tracking instances in random rounds. Default: 5
- as_verbosemode - 0=silent, 1=show HUD. Default: 1
PHP Code:
#include <amxmodx> #include <cstrike> #include <fakemeta> #include <hamsandwich>
new const Version[] = "0.5";
#define MAX_PLAYERS 32
const ButtonBits = ( IN_FORWARD | IN_BACK | IN_MOVELEFT | IN_MOVERIGHT | IN_JUMP | IN_DUCK | IN_USE | IN_ATTACK | IN_ATTACK2 | IN_SCORE );
enum PlayerData { LastMoveTime, SlayCount }
new g_pdData[ MAX_PLAYERS + 1 ][ PlayerData ]; new g_iSysTime , bool:g_bInRound; new g_pSlayTime , g_pSlayMode , g_pSpecSlays , g_pVerboseMode , g_pFreezeTime;
public plugin_init() { register_plugin( "AFK Slay" , Version , "bugsy" );
g_pSlayTime = register_cvar( "as_slaytime" , "30" ); g_pSlayMode = register_cvar( "as_slaymode" , "2" ); g_pSpecSlays = register_cvar( "as_spectatorslays" , "5" ); g_pVerboseMode = register_cvar( "as_verbosemode" , "1" ); g_pFreezeTime = get_cvar_pointer( "mp_freezetime" ); RegisterHam( Ham_Spawn , "player" , "HamSpawn_Post" , true ); register_forward( FM_CmdStart , "CmdStart" ); register_logevent( "RoundStart" , 2 , "1=Round_Start" ); register_logevent( "RoundEnd" , 2 , "1=Round_End" ); set_task( 1.0 , "CheckAFK" , .flags="b" ); }
public client_connect( id ) { g_pdData[ id ][ SlayCount ] = 0; }
public HamSpawn_Post( iPlayer ) { if ( is_user_alive( iPlayer ) ) { g_pdData[ iPlayer ][ LastMoveTime ] = g_iSysTime + ( g_bInRound ? 0 : get_pcvar_num( g_pFreezeTime ) ); } }
public RoundStart() { g_bInRound = true; }
public RoundEnd() { g_bInRound = false; }
public CmdStart( id , handle , seed ) { if ( g_bInRound && ( get_uc( handle , UC_Buttons ) & ButtonBits ) ) { g_pdData[ id ][ LastMoveTime ] = g_iSysTime; g_pdData[ id ][ SlayCount ] = 0; } }
public CheckAFK() { new iPlayers[ 32 ] , iNum , iPlayer , szName[32 ] , iSlayPos , iSpecPos , iVerbose; static szSlayNames[ 512 ] , szSpecNames[ 512 ]; iVerbose = get_pcvar_num( g_pVerboseMode ); g_iSysTime = get_systime(); switch ( get_pcvar_num( g_pSlayMode ) ) { case 1: get_players( iPlayers , iNum , "ae" , "TERRORIST" ); case 2: get_players( iPlayers , iNum , "ae" , "CT" ); default: get_players( iPlayers , iNum , "a" ); } szSlayNames[ 0 ] = EOS; szSpecNames[ 0 ] = EOS; for ( new i = 0 ; i < iNum ; i++ ) { iPlayer = iPlayers[ i ]; if ( g_pdData[ iPlayer ][ LastMoveTime ] && ( ( g_iSysTime - g_pdData[ iPlayer ][ LastMoveTime ] ) >= get_pcvar_num( g_pSlayTime ) ) ) { user_kill( iPlayer ); if ( iVerbose ) get_user_name( iPlayer , szName , charsmax( szName ) ); if ( ++g_pdData[ iPlayer ][ SlayCount ] >= get_pcvar_num( g_pSpecSlays ) ) { cs_set_user_team( iPlayer , CS_TEAM_SPECTATOR ); if ( iVerbose ) iSpecPos += formatex( szSpecNames[ iSpecPos ] , charsmax( szSpecNames ) - iSpecPos , "%s^n" , szName ); } else { if ( iVerbose ) iSlayPos += formatex( szSlayNames[ iSlayPos ] , charsmax( szSlayNames ) - iSlayPos , "%s^n" , szName ); } } } if ( iVerbose && ( iSlayPos || iSpecPos ) ) { set_hudmessage( 255 , 255 , 255 , 0.05 , 0.3 , 0 , 0.0 , 3.0 ); show_hudmessage( 0 , "%s%s%s%s" , iSlayPos ? "AFK - Slayed:^n^n" : "" , szSlayNames , iSpecPos ? "AFK - Slayed / Moved to Spec:^n^n" : "" , szSpecNames ); } }
__________________
Last edited by Bugsy; 04-25-2020 at 14:43.
|
|