2019-09-13 19:29:42 +00: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 18:39:36 +00:00
|
|
|
// Enable or Disable
|
|
|
|
|
// $Host::EnableTeamBalanceNotify = 1;
|
|
|
|
|
// Enable or Disable Autobalance
|
|
|
|
|
// $Host::EnableAutobalance = 1;
|
2018-11-04 21:59:10 +00:00
|
|
|
//
|
2019-09-13 19:29:42 +00:00
|
|
|
|
|
|
|
|
|
2019-12-11 21:30:37 +00:00
|
|
|
// Called in GetTeamCounts.cs
|
2020-08-18 22:21:44 +00:00
|
|
|
function TeamBalanceNotify(%game)
|
2018-06-28 18:34:52 +00:00
|
|
|
{
|
2020-08-18 17:58:49 +00:00
|
|
|
if( Game.numTeams > 1 && $TotalTeamPlayerCount !$= 0 )
|
2019-02-03 08:55:40 +00:00
|
|
|
{
|
2019-09-13 19:29:42 +00:00
|
|
|
//Uneven
|
2020-08-18 22:21:44 +00:00
|
|
|
if($TeamRank[1, count] !$= $TeamRank[2, count])
|
2019-12-11 21:30:37 +00:00
|
|
|
{
|
2020-08-18 23:59:56 +00:00
|
|
|
%team1difference = $TeamRank[1, count] - $TeamRank[2, count];
|
|
|
|
|
%team2difference = $TeamRank[2, count] - $TeamRank[1, count];
|
|
|
|
|
|
|
|
|
|
//echo("%Team1Difference " @ %team1difference);
|
|
|
|
|
//echo("%Team2Difference " @ %team2difference);
|
|
|
|
|
|
2019-12-11 21:30:37 +00:00
|
|
|
if( %team1difference >= 2 || %team2difference >= 2 ) //Teams are unbalanced
|
2019-02-03 08:55:40 +00:00
|
|
|
{
|
2019-12-11 21:30:37 +00:00
|
|
|
if( $TBNStatus !$= "NOTIFY" ) //Stops any new schedules
|
|
|
|
|
$TBNStatus = "UNBALANCED";
|
2019-01-31 07:07:19 +00:00
|
|
|
}
|
2019-12-11 21:30:37 +00:00
|
|
|
else
|
2020-08-18 17:58:49 +00:00
|
|
|
//Man down. 6vs7, 4vs3 etc
|
2019-12-11 21:30:37 +00:00
|
|
|
$TBNStatus = "UNEVEN";
|
2018-06-28 18:34:52 +00:00
|
|
|
}
|
2019-12-11 21:30:37 +00:00
|
|
|
//Teams are even
|
2020-08-18 22:21:44 +00:00
|
|
|
else if($TeamRank[1, count] == $TeamRank[2, count] && $TBNStatus !$= "PLAYEDEVEN" )
|
2019-12-11 21:30:37 +00:00
|
|
|
$TBNStatus = "EVEN";
|
|
|
|
|
|
|
|
|
|
switch$($TBNStatus)
|
2018-11-11 00:56:13 +00:00
|
|
|
{
|
2019-12-11 21:30:37 +00:00
|
|
|
case IDLE:
|
|
|
|
|
//Do Nothing
|
|
|
|
|
case UNEVEN:
|
|
|
|
|
//Do Nothing
|
|
|
|
|
case UNBALANCED:
|
|
|
|
|
//Start Schedule to Notify
|
|
|
|
|
$NotifySchedule = schedule(15000, 0, "NotifyUnbalanced", %game );
|
|
|
|
|
$TBNStatus = "NOTIFY";
|
|
|
|
|
case EVEN:
|
|
|
|
|
//messageAll('MsgTeamBalanceNotify', '\c1Teams are balanced.');
|
|
|
|
|
$TBNStatus = "PLAYEDEVEN";
|
|
|
|
|
case PLAYEDEVEN:
|
|
|
|
|
//Do Nothing
|
|
|
|
|
case NOTIFY:
|
|
|
|
|
//Do Nothing
|
2018-06-28 18:34:52 +00:00
|
|
|
}
|
2018-11-04 21:59:10 +00:00
|
|
|
}
|
2019-12-11 21:30:37 +00:00
|
|
|
//echo($TBNStatus);
|
2018-06-28 18:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-03 23:00:24 +00:00
|
|
|
//Check to see if teams are still unbalanced
|
2019-02-06 18:32:56 +00:00
|
|
|
//Fire AutoBalance in 30 sec if enabled
|
2019-12-11 21:30:37 +00:00
|
|
|
function NotifyUnbalanced( %game )
|
2019-01-01 18:34:41 +00:00
|
|
|
{
|
2019-12-11 21:30:37 +00:00
|
|
|
if(isEventPending($NotifySchedule))
|
|
|
|
|
cancel($NotifySchedule);
|
2020-08-18 17:58:49 +00:00
|
|
|
|
|
|
|
|
if( $TBNStatus !$= "NOTIFY" ) //If Status has changed to EVEN or anything else (GameOver reset).
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Difference Variables
|
|
|
|
|
%team1difference = $TeamRank[1, count] - $TeamRank[2, count];
|
|
|
|
|
%team2difference = $TeamRank[2, count] - $TeamRank[1, count];
|
2019-12-11 21:30:37 +00:00
|
|
|
|
2020-08-18 17:58:49 +00:00
|
|
|
if( %team1difference >= 2 || %team2difference >= 2 )
|
|
|
|
|
{
|
|
|
|
|
//Autobalance Warning
|
|
|
|
|
if( $Host::EnableAutobalance )
|
2019-09-13 19:29:42 +00:00
|
|
|
{
|
2020-08-18 17:58:49 +00:00
|
|
|
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance Initializing.~wgui/vote_nopass.wav');
|
|
|
|
|
$AutoBalanceSchedule = schedule(30000, 0, "Autobalance", %game );
|
2019-02-03 08:55:40 +00:00
|
|
|
}
|
2020-08-18 17:58:49 +00:00
|
|
|
//If Autobalance is disabled, message only.
|
|
|
|
|
else if( $Host::EnableTeamBalanceNotify )
|
|
|
|
|
{
|
2020-08-18 22:21:44 +00:00
|
|
|
%observers = $HostGamePlayerCount - ($TeamRank[1, count] + $TeamRank[2, count]);
|
|
|
|
|
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0%1 vs %2 with %3 observers.~wgui/vote_nopass.wav', $TeamRank[1, count], $TeamRank[2, count], %observers );
|
2020-08-18 17:58:49 +00:00
|
|
|
schedule(13000, 0, "ResetTBNStatus");
|
|
|
|
|
schedule(15000, 0, "ResetGetCountsStatus");
|
2019-02-03 08:55:40 +00:00
|
|
|
}
|
2019-01-26 15:44:53 +00:00
|
|
|
}
|
2020-08-18 17:58:49 +00:00
|
|
|
else
|
|
|
|
|
ResetTBNStatus();
|
2019-09-13 19:29:42 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 21:30:37 +00:00
|
|
|
// Reset TBNStatus
|
|
|
|
|
function ResetTBNStatus()
|
2019-09-13 19:29:42 +00:00
|
|
|
{
|
2019-12-11 21:30:37 +00:00
|
|
|
$TBNStatus = "IDLE";
|
2019-10-06 20:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Reset every map change
|
2019-12-11 21:30:37 +00:00
|
|
|
package ResetTBNGameOver
|
2019-10-06 20:30:41 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
function DefaultGame::gameOver(%game)
|
|
|
|
|
{
|
|
|
|
|
Parent::gameOver(%game);
|
|
|
|
|
|
2019-12-11 21:30:37 +00:00
|
|
|
//Reset TBNStatus
|
|
|
|
|
ResetTBNStatus();
|
2019-10-06 20:30:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Prevent package from being activated if it is already
|
2019-12-11 21:30:37 +00:00
|
|
|
if (!isActivePackage(ResetTBNGameOver))
|
|
|
|
|
activatePackage(ResetTBNGameOver);
|