More Autobalance refinement

This commit is contained in:
ChocoTaco 2019-02-04 22:54:58 -05:00
parent 5a12658fa7
commit 6949d59010
3 changed files with 62 additions and 27 deletions

View file

@ -1,53 +1,96 @@
//Fire Autobalance //Fire Autobalance
function Autobalance( %game, %client, %respawn ) function Autobalance( %game, %AutobalanceSafetynetTrys )
{ {
if( $CurrentMissionType !$= "LakRabbit" && $Host::EnableTeamBalanceNotify && $StatsMsgPlayed $= 1 && !$Host::TournamentMode ) if( $CurrentMissionType !$= "LakRabbit" && $Host::EnableTeamBalanceNotify && $StatsMsgPlayed $= 1 && !$Host::TournamentMode )
{ {
//%AutobalanceDebug = true;
if( $Team1Difference == 1 || $Team2Difference == 1 || $PlayerCount[1] == $PlayerCount[2] ) if( $Team1Difference == 1 || $Team2Difference == 1 || $PlayerCount[1] == $PlayerCount[2] )
{ {
$StatsMsgPlayed = 0; $StatsMsgPlayed = 0;
return; return;
} }
//Safetynet //Safetynet
else if( $team1canidate $= "" || $team2canidate $= "" ) else if(( $team1canidate $= "" && $Team1Difference >= 2 )||( $team2canidate $= "" && $Team2Difference >= 2 ))
{ {
messageAll('MsgTeamBalanceNotify', '\c0Autobalance error.'); %AutobalanceSafetynetTrys++; if(%AutobalanceSafetynetTrys $= 3) return;
if( %AutobalanceDebug )
{
if( $team1canidate $= "" ) $team1canidate = "NULL"; if( $team2canidate $= "" ) $team2canidate = "NULL";
messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: %1, %2, %3, %4', $team1canidate, $team2canidate, $Team1Difference, $Team2Difference );
if( $team1canidate $= "NULL" ) $team1canidate = ""; if( $team2canidate $= "NULL" ) $team2canidate = "";
}
else if( $team1canidate $= "" && $team2canidate $= "" ) messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: Both Teams' );
else if( $team1canidate $= "" ) messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: Team1' );
else if( $team2canidate $= "" ) messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: Team2' );
//Trigger GetCounts //Trigger GetCounts
ResetClientChangedTeams(); ResetClientChangedTeams();
//Reset Stats. //Rerun in 10 secs
$StatsMsgPlayed = 0; schedule(10000, 0, "Autobalance", %game, %AutobalanceSafetynetTrys );
//Clear Canidates
$team1canidate = ""; $team2canidate = "";
return; return;
} }
//Team 1 //Team 1
else if( $Team1Difference >= 2 ) else if( $Team1Difference >= 2 )
{ {
if( %AutobalanceDebug )
{
if( $team1canidate $= "" ) $team1canidate = "NULL"; if( $team2canidate $= "" ) $team2canidate = "NULL";
messageAll('MsgTeamBalanceNotify', '\c0Autobalance stat: %1, %2, %3, %4', $team1canidate, $team2canidate, $Team1Difference, $Team2Difference );
if( $team1canidate $= "NULL" ) $team1canidate = ""; if( $team2canidate $= "NULL" ) $team2canidate = "";
}
%client = $team1canidate; %client = $team1canidate;
%team = $team1canidate.team; %team = $team1canidate.team;
%otherTeam = ( %team == 1 ) ? 2 : 1; %otherTeam = ( %team == 1 ) ? 2 : 1;
Game.clientChangeTeam( %client, %otherTeam, 0 ); if( $team1canidate.team $= 1 )
messageAll('MsgTeamBalanceNotify', '~wfx/powered/vehicle_screen_on.wav'); {
Game.clientChangeTeam( %client, %otherTeam, 0 );
messageAll('MsgTeamBalanceNotify', '~wfx/powered/vehicle_screen_on.wav');
}
else
messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: Team1 mismatch.' );
//Trigger GetCounts //Trigger GetCounts
ResetClientChangedTeams(); ResetClientChangedTeams();
//Reset Stats. //Reset Stats.
$StatsMsgPlayed = 0; $StatsMsgPlayed = 0;
//Clear Canidates
$team1canidate = ""; $team2canidate = "";
return; return;
} }
//Team 2 //Team 2
else if( $Team2Difference >= 2 ) else if( $Team2Difference >= 2 )
{ {
if( %AutobalanceDebug )
{
if( $team1canidate $= "" ) $team1canidate = "NULL"; if( $team2canidate $= "" ) $team2canidate = "NULL";
messageAll('MsgTeamBalanceNotify', '\c0Autobalance stat: %1, %2, %3, %4', $team1canidate, $team2canidate, $Team1Difference, $Team2Difference );
if( $team1canidate $= "NULL" ) $team1canidate = ""; if( $team2canidate $= "NULL" ) $team2canidate = "";
}
%client = $team2canidate; %client = $team2canidate;
%team = $team2canidate.team; %team = $team2canidate.team;
%otherTeam = ( %team == 1 ) ? 2 : 1; %otherTeam = ( %team == 1 ) ? 2 : 1;
Game.clientChangeTeam( %client, %otherTeam, 0 ); if( $team2canidate.team $= 2 )
messageAll('MsgTeamBalanceNotify', '~wfx/powered/vehicle_screen_on.wav'); {
Game.clientChangeTeam( %client, %otherTeam, 0 );
messageAll('MsgTeamBalanceNotify', '~wfx/powered/vehicle_screen_on.wav');
}
else
messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: Team2 mismatch.' );
//Trigger GetCounts //Trigger GetCounts
ResetClientChangedTeams(); ResetClientChangedTeams();
//Reset Stats. //Reset Stats.
$StatsMsgPlayed = 0; $StatsMsgPlayed = 0;
//Clear Canidates
$team1canidate = ""; $team2canidate = "";
return; return;
} }
} }

View file

@ -39,11 +39,9 @@ function GetTeamCounts( %game, %client, %respawn )
if( $GetCountsClientTeamChange && $countdownStarted && $MatchStarted ) if( $GetCountsClientTeamChange && $countdownStarted && $MatchStarted )
{ {
//Generate random to get random client for autobalance //Generate random to get random client for autobalance
%team1random = 1; %team1random = getRandom(1,$PlayerCount[1]); if(%team1random $= 0 || %team1random > $PlayerCount[1]) %team1random = 1;
%team2random = 1; %team2random = getRandom(1,$PlayerCount[2]); if(%team2random $= 0 || %team2random > $PlayerCount[2]) %team2random = 1;
//echo("team1random " @ %team1random); echo("team2random " @ %team2random);
%team1random = getRandom(1,$PlayerCount[1]);
%team2random = getRandom(1,$PlayerCount[2]);
//Team Count code by Keen //Team Count code by Keen
$PlayerCount[0] = 0; $PlayerCount[0] = 0;
@ -55,14 +53,8 @@ function GetTeamCounts( %game, %client, %respawn )
%client = ClientGroup.getObject(%i); %client = ClientGroup.getObject(%i);
//Pick a random client for autobalance //Pick a random client for autobalance
if( %client.team == 1 && %team1random == $PlayerCount[1] ) if( %client.team == 1 && %team1random == $PlayerCount[1] ) $team1canidate = %client;
$team1canidate = %client; if( %client.team == 2 && %team2random == $PlayerCount[2] ) $team2canidate = %client;
else if( $team1canidate $= "" && %client.team == 1 )
$team1canidate = %client;
if( %client.team == 2 && %team2random == $PlayerCount[2] )
$team2canidate = %client;
else if( $team2canidate $= "" && %client.team == 2 )
$team2canidate = %client;
//if(!%client.isAIControlled()) //if(!%client.isAIControlled())
$PlayerCount[%client.team]++; $PlayerCount[%client.team]++;
@ -83,7 +75,7 @@ function GetTeamCounts( %game, %client, %respawn )
//Start Base Rape Notify //Start Base Rape Notify
schedule(500, 0, "NBRStatusNotify", %game); schedule(500, 0, "NBRStatusNotify", %game);
//Start Team Balance Notify //Start Team Balance Notify
schedule(1000, 0, "TeamBalanceNotify", %game, %client, %respawn ); schedule(1000, 0, "TeamBalanceNotify", %game );
//Start AntiCloak //Start AntiCloak
schedule(1500, 0, "ActivateAntiCloak", %game); schedule(1500, 0, "ActivateAntiCloak", %game);

View file

@ -3,7 +3,7 @@
// //
//Give the client a notification on the current state of balancing. //Give the client a notification on the current state of balancing.
//This function is in GetTeamCounts.cs //This function is in GetTeamCounts.cs
function TeamBalanceNotify( %game, %client, %respawn ) function TeamBalanceNotify( %game )
{ {
if( $CurrentMissionType !$= "LakRabbit" && $TotalTeamPlayerCount !$= 0 && $Host::EnableTeamBalanceNotify && !$Host::TournamentMode ) if( $CurrentMissionType !$= "LakRabbit" && $TotalTeamPlayerCount !$= 0 && $Host::EnableTeamBalanceNotify && !$Host::TournamentMode )
{ {
@ -22,7 +22,7 @@ function TeamBalanceNotify( %game, %client, %respawn )
//Run once. //Run once.
$StatsMsgPlayed = 1; $StatsMsgPlayed = 1;
//Start Sound Schedule for 60 secs //Start Sound Schedule for 60 secs
schedule(15000, 0, "StatsUnbalanceSound", %game, %client, %respawn ); schedule(15000, 0, "StatsUnbalanceSound", %game );
} }
} }
} }
@ -48,7 +48,7 @@ function ResetTeamBalanceNotifyGameOver()
//Check to see if teams are still unbalanced //Check to see if teams are still unbalanced
//Fire AutoBalance in 30 sec //Fire AutoBalance in 30 sec
function StatsUnbalanceSound( %game, %client, %respawn ) function StatsUnbalanceSound( %game )
{ {
if( $CurrentMissionType !$= "LakRabbit" && $Host::EnableTeamBalanceNotify && $StatsMsgPlayed $= 1 && !$Host::TournamentMode ) if( $CurrentMissionType !$= "LakRabbit" && $Host::EnableTeamBalanceNotify && $StatsMsgPlayed $= 1 && !$Host::TournamentMode )
{ {
@ -62,7 +62,7 @@ function StatsUnbalanceSound( %game, %client, %respawn )
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance Initializing.~wgui/vote_nopass.wav'); messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance Initializing.~wgui/vote_nopass.wav');
//Schedule a GetCounts update before the autobalance fire //Schedule a GetCounts update before the autobalance fire
schedule(22000, 0, "ResetClientChangedTeams"); schedule(22000, 0, "ResetClientChangedTeams");
schedule(30000, 0, "Autobalance", %game, %client, %respawn); schedule(30000, 0, "Autobalance", %game );
} }
} }
} }