Could someone help me adjust this team balancer, so it transfers the player with the highest frags instead of the lowest frags?
PHP Code:
#include < amxmodx >
#include < cstrike >
// This is a random number to define INVALID_PLAYER
#define INVALID_PLAYER -1
// Check whether server is running CSDM
new bool: g_bCsdmEnabled, g_iCsdmConVarPointer;
// Console variable to set check frequency in seconds
new g_iConVarCheckFrequency;
// Console variable to set maximum difference between terrorists and counter-terrorists
new g_iConVarTerroristsDifference;
// Console variable to set maximum difference between counter-terrorists and terrorists
new g_iConVarCTerroristsDifference;
// Console variable to set immune admin flag
new g_iConVarAdminFlag;
// Variable to store admin flag
new g_iFlag;
public plugin_init( )
{
register_plugin( "Team Balancer by Low Frags", "4.0", "Hattrick" );
g_iConVarCheckFrequency = register_cvar( "team_balancer_frequency", "10" );
g_iConVarTerroristsDifference = register_cvar( "team_balancer_te_difference", "1" );
g_iConVarCTerroristsDifference = register_cvar( "team_balancer_ct_difference", "1" );
g_iConVarAdminFlag = register_cvar( "team_balancer_admin_flag", "" );
set_task( get_pcvar_float( g_iConVarCheckFrequency ), "Task_CheckTeams", .flags = "b" );
new cFlag[ 2 ];
get_pcvar_string( g_iConVarAdminFlag, cFlag, 1 );
g_iFlag = read_flags( cFlag );
g_iCsdmConVarPointer = get_cvar_pointer( "csdm_active" );
g_bCsdmEnabled = g_iCsdmConVarPointer && get_pcvar_num( g_iCsdmConVarPointer );
}
public Task_CheckTeams( )
{
static iPlayers_TE[ 32 ], iPlayers_CT[ 32 ], iNum_TE, iNum_CT, iPlayer;
get_players( iPlayers_TE, iNum_TE, "e", "TERRORIST" );
get_players( iPlayers_CT, iNum_CT, "e", "CT" );
// Check whether teams should be balanced
if( iNum_TE == iNum_CT || !iNum_TE || !iNum_CT )
return;
// Is the difference between terrorists and counter-terrorists higher than the specified value?
if( iNum_TE - iNum_CT > get_pcvar_num( g_iConVarTerroristsDifference ) )
{
// Get a terrorist
iPlayer = GetLowestFragsTarget( CsTeams: CS_TEAM_T );
// Is this specified target a valid one?
if( iPlayer == INVALID_PLAYER )
return;
// Transfer him to the opposite team
cs_set_user_team( iPlayer, CsTeams: CS_TEAM_CT );
// Make sure the difference between players is alright
Task_CheckTeams( );
}
// Is the difference between counter-terrorists and terrorists higher than the specified value?
else if( iNum_CT - iNum_TE > get_pcvar_num( g_iConVarCTerroristsDifference ) )
{
// Get a counter-terrorist
iPlayer = GetLowestFragsTarget( CsTeams: CS_TEAM_CT );
// Is this specified target a valid one?
if( iPlayer == INVALID_PLAYER )
return;
// Transfer him to the opposite team
cs_set_user_team( iPlayer, CsTeams: CS_TEAM_T );
// Make sure the difference between players is alright
Task_CheckTeams( );
}
}
// This function will return the player with the lowest frags from one team or INVALID_PLAYER on invalid specified target found
GetLowestFragsTarget( CsTeams: iTeam )
{
static iTarget, iPlayers[ 32 ], iNum, iPlayer, i, iMinimumFrags, iFrags;
switch( CsTeams: iTeam )
{
case CS_TEAM_T: g_bCsdmEnabled ? get_players( iPlayers, iNum, "e", "TERRORIST" ) : get_players( iPlayers, iNum, "be", "TERRORIST" );
case CS_TEAM_CT: g_bCsdmEnabled ? get_players( iPlayers, iNum, "e", "CT" ) : get_players( iPlayers, iNum, "be", "CT" );
}
// The biggest number
iMinimumFrags = 0xFFFFFF;
// Invalid target
iTarget = INVALID_PLAYER;
for( i = 0; i < iNum; i++ )
{
iPlayer = iPlayers[ i ];
if( g_iFlag && get_user_flags( iPlayer ) & g_iFlag )
continue;
iFrags = get_user_frags( iPlayer );
if( iFrags < iMinimumFrags )
{
iMinimumFrags = iFrags;
iTarget = iPlayer;
}
}
return iTarget;
}