I had a problem when I tried to hook change team menu, so I will share the main code until I find the solution for the problem
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#if !defined MAX_PLAYERS
const MAX_PLAYERS = 32
#endif
#if !defined MAX_AUTHID_LENGTH
const MAX_AUTHID_LENGTH = 64
#endif
new Trie:g_tBanTeam
const TASK_TEAM_JOIN = 115514;
const iDateSeconds = 60; /* Minute = 60 , Hour = 3600 , Day = 86400 */
new g_szSteamID[ MAX_PLAYERS + 1 ][ MAX_AUTHID_LENGTH ];
public plugin_init( )
{
register_plugin( "AMX Ban Team", "1.0", "Supremache" )
register_cvar("AMXBanTeam", "1.0", FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
g_tBanTeam = TrieCreate( );
register_concmd( "amx_banct", "@BanTeam");
register_concmd( "amx_bant", "@BanTeam" );
register_concmd( "amx_unbanct", "@UnBanTeam" );
register_concmd( "amx_unbant", "@UnBanTeam" );
}
public client_connect( id )
{
get_user_authid( id, g_szSteamID[ id ], charsmax( g_szSteamID[ ] ) )
}
@BanTeam( id )
{
new szCommand[ 10 ], szTeam[ 10 ], szPlayer[ 32 ], szValue[ 3 ], iPlayers[ MAX_PLAYERS ], iPnum;
read_argv( 0, szCommand, charsmax( szCommand ) )
read_argv( 1, szPlayer, charsmax( szPlayer ) )
copy( szTeam, charsmax( szTeam ), szCommand[ 7 ] == 'c' ? "CT" : "TERRORIST" )
new iPlayer = cmd_target( id, szPlayer, CMDTARGET_ALLOW_SELF )
if( ! iPlayer )
{
get_players( iPlayers, iPnum, "e", szTeam )
for( new i; i < iPnum; i++ )
{
ReadFile( iPlayers[ i ], szTeam, str_to_num( szPlayer ), 1 );
}
}
else
{
read_argv( 2, szValue, charsmax( szValue ) )
ReadFile( iPlayer, szTeam, str_to_num( szValue ), 1 );
}
ReadFile( _, szTeam );
client_print( id, print_chat, "banned" )
return PLUGIN_HANDLED;
}
@UnBanTeam( id )
{
static szSteamID[ MAX_AUTHID_LENGTH ], szCommand[ 10 ], szTeam[ 10 ], szPlayer[ 32 ], szExpireDate[ 32 ];
read_argv( 0, szCommand, charsmax( szCommand ) )
read_argv( 1, szPlayer, charsmax( szPlayer ) )
copy( szTeam, charsmax( szTeam ), szCommand[ 9 ] == 'c' ? "CT" : "TERRORIST" )
new iPlayer = cmd_target( id, szPlayer );
ReadFile( _, szTeam )
if( iPlayer )
{
if( TrieGetString( g_tBanTeam, g_szSteamID[ id ], szExpireDate, charsmax( szExpireDate ) ) )
{
TrieDeleteKey( g_tBanTeam, szSteamID );
}
client_print( id, print_chat, "Player %s has been unbanned", szSteamID )
}
else
{
ReadFile( _, szTeam, _, 2 )
client_print( id, print_chat, "All %s has been unbanned", szTeam )
}
client_print( id, print_chat, "unbanned" )
return PLUGIN_HANDLED;
}
ReadFile( id = -1, const szTeam[ ] = "", const iTime = 0, iType = 0)
{
new szConfigs[ 64 ], szFile[ 96 ], szData[ MAX_AUTHID_LENGTH ], szSteamID[ MAX_AUTHID_LENGTH ], szExpireDate[ 32 ], iFile;
get_configsdir( szConfigs, charsmax( szConfigs ) )
formatex( szFile, charsmax( szFile ), "%s/BanList_%s.ini", szConfigs, szTeam )
switch( iType )
{
case 0:
{
iFile = fopen( szFile, "rt" );
if( iFile )
{
while( fgets( iFile, szData, charsmax( szData ) ) )
{
trim( szData );
switch( szData[ 0 ] )
{
case EOS, ';', '#', '/': continue;
default:
{
parse( szData, szSteamID, charsmax( szSteamID ), szExpireDate, charsmax( szExpireDate ) );
if( !szExpireDate[ 0 ] || szExpireDate[ 0 ] == '0' || !HasDateExpired( szExpireDate ) )
{
TrieSetString( g_tBanTeam, szSteamID, szExpireDate );
}
}
}
}
fclose( iFile );
}
}
case 1:
{
iFile = fopen( szFile, "wt")
if( iFile && pev_valid( id ) && iTime )
{
get_time( "%m-%d-%Y", szExpireDate, charsmax( szExpireDate ) );
AddToDate( szExpireDate, iTime, szExpireDate, charsmax( szExpireDate ) );
trim( szExpireDate );
fprintf( iFile, "%s %s^n", g_szSteamID[ id ], szExpireDate );
fclose( iFile );
}
}
case 2: delete_file( szConfigs );
}
}
bool:HasDateExpired( const szDate[ ] )
{
return get_systime( ) >= parse_time( szDate, "%m-%d-%Y" );
}
AddToDate( const szDate[ ], const iMinutes, szReturnDate[ ], const iSize )
{
new const szFormatRule[ ] = "%m-%d-%Y";
new const iSecondsInMinute = iDateSeconds;
new iCurrentTimeStamp = parse_time( szDate, szFormatRule );
iCurrentTimeStamp = iCurrentTimeStamp + ( iMinutes * iSecondsInMinute );
format_time( szReturnDate, iSize, szFormatRule, iCurrentTimeStamp );
}