TacoServer/Classic/scripts/autoexec/TeamBalanceNotify.cs

125 lines
3.2 KiB
C#
Raw Normal View History

2019-09-13 15:29:42 -04:00
// Team Balance Notify Script
//
// Give the client a notification on the current state of balancing
// Furthermore if Autobalance is enabled. Proceed to Autobalancing
// Autobalance does not need TeamBalanceNotify to be enabled to run
//
2019-02-06 13:39:36 -05:00
// Enable or Disable
// $Host::EnableTeamBalanceNotify = 1;
// Enable or Disable Autobalance
// $Host::EnableAutobalance = 1;
//
2019-09-13 15:29:42 -04:00
// This function is called in GetTeamCounts.cs
function TeamBalanceNotify( %game, %team1difference, %team2difference )
2018-06-28 14:34:52 -04:00
{
2019-09-13 15:29:42 -04:00
if( $CurrentMissionType !$= "LakRabbit" && $TotalTeamPlayerCount !$= 0 && !$Host::TournamentMode )
2019-02-03 03:55:40 -05:00
{
2018-11-10 19:56:13 -05:00
//echo ("%Team1Difference " @ %Team1Difference);
//echo ("%Team2Difference " @ %Team2Difference);
2019-09-13 15:29:42 -04:00
//Uneven
2018-11-10 19:56:13 -05:00
if( $PlayerCount[1] !$= $PlayerCount[2] )
{
2019-09-13 15:29:42 -04:00
//Reset Balanced.
2018-11-11 01:38:18 -05:00
$BalancedMsgPlayed = 0;
2019-09-13 15:29:42 -04:00
if( %team1difference >= 2 || %team2difference >= 2 )
2019-02-03 03:55:40 -05:00
{
2019-09-13 15:29:42 -04:00
if( $UnbalancedMsgPlayed !$= 1)
2019-01-26 10:44:53 -05:00
{
//Run once.
2019-09-13 15:29:42 -04:00
$UnbalancedMsgPlayed = 1;
//Start Sound Schedule
schedule(15000, 0, "UnbalancedSound", %game );
2019-01-26 10:44:53 -05:00
}
2019-01-31 02:07:19 -05:00
}
2018-06-28 14:34:52 -04:00
}
2019-09-13 15:29:42 -04:00
//If teams are balanced
2018-11-11 01:38:18 -05:00
else if( $PlayerCount[1] == $PlayerCount[2] && $TotalTeamPlayerCount !$= 0 && $BalancedMsgPlayed !$= 1 )
2018-11-10 19:56:13 -05:00
{
2019-09-13 15:29:42 -04:00
//messageAll('MsgTeamBalanceNotify', '\c1Teams are balanced.');
//Once per cycle.
$BalancedMsgPlayed = 1;
//Reset Unbalanced.
$UnbalancedMsgPlayed = 0;
2018-06-28 14:34:52 -04:00
}
}
2018-06-28 14:34:52 -04:00
}
2019-02-03 18:00:24 -05:00
//Check to see if teams are still unbalanced
//Fire AutoBalance in 30 sec if enabled
2019-09-13 15:29:42 -04:00
function UnbalancedSound( %game )
2019-01-01 13:34:41 -05:00
{
2019-09-13 15:29:42 -04:00
if( $UnbalancedMsgPlayed $= 1 )
2019-01-26 10:44:53 -05:00
{
2019-09-13 15:29:42 -04:00
//Team Count code by Keen
$PlayerCount[0] = 0;
$PlayerCount[1] = 0;
$PlayerCount[2] = 0;
for(%i = 0; %i < ClientGroup.getCount(); %i++)
2019-02-03 03:55:40 -05:00
{
2019-09-13 15:29:42 -04:00
%client = ClientGroup.getObject(%i);
//if(!%client.isAIControlled())
$PlayerCount[%client.team]++;
}
//Difference Variables
%team1difference = $PlayerCount[1] - $PlayerCount[2];
%team2difference = $PlayerCount[2] - $PlayerCount[1];
if( %team1difference == 1 || %team2difference == 1 || $PlayerCount[1] == $PlayerCount[2] )
{
//Reset
$UnbalancedMsgPlayed = 0;
2019-02-03 03:55:40 -05:00
return;
}
2019-09-13 15:29:42 -04:00
//Continue
else if( %team1difference >= 2 || %team2difference >= 2 )
2019-02-03 03:55:40 -05:00
{
2019-09-13 15:29:42 -04:00
//Autobalance Warning
if( $Host::EnableAutobalance )
{
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance Initializing.~wgui/vote_nopass.wav');
schedule(30000, 0, "Autobalance", %game );
}
2019-09-13 15:29:42 -04:00
//If Autobalance is disabled, message only.
else if( $Host::EnableTeamBalanceNotify )
{
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0%1 vs %2 with %3 observers.~wgui/vote_nopass.wav', $PlayerCount[1], $PlayerCount[2], $PlayerCount[0] );
schedule(13000, 0, "ResetTeamBalanceNotifyGameOver");
2019-09-13 15:29:42 -04:00
schedule(15000, 0, "ResetClientChangedTeams");
}
2019-02-03 03:55:40 -05:00
}
2019-01-26 10:44:53 -05:00
}
2019-09-13 15:29:42 -04:00
}
// Reset Notify
2019-09-13 15:29:42 -04:00
function ResetTeamBalanceNotifyGameOver()
{
//Reset All TeamBalance Variables
$BalancedMsgPlayed = -1;
$UnbalancedMsgPlayed = -1;
}
// Reset every map change
package ResetTeamBalanceNotify
{
function DefaultGame::gameOver(%game)
{
Parent::gameOver(%game);
//Reset All TeamBalance Variables
ResetTeamBalanceNotifyGameOver();
}
};
// Prevent package from being activated if it is already
if (!isActivePackage(ResetTeamBalanceNotify))
activatePackage(ResetTeamBalanceNotify);