TacoServer/Classic/scripts/autoexec/Autobalance.cs

83 lines
2.3 KiB
C#
Raw Normal View History

2019-09-13 15:29:42 -04:00
// Team Autobalance Script
//
2020-08-29 14:39:32 -04:00
// Determines which team needs players and proceeds to switch them
// Goon style: At respawn
2019-09-13 15:29:42 -04:00
//
2019-02-06 13:39:36 -05:00
// Enable or Disable Autobalance
// $Host::EnableAutobalance = 1;
2020-08-29 14:39:32 -04:00
//
// exec("scripts/autoexec/Autobalance.cs");
2019-09-13 15:29:42 -04:00
2020-08-29 14:39:32 -04:00
// Run from TeamBalanceNotify.cs via NotifyUnbalanced
function Autobalance( %game )
2019-09-13 15:29:42 -04:00
{
if(isEventPending($AutoBalanceSchedule))
cancel($AutoBalanceSchedule);
if( $TBNStatus !$= "NOTIFY" ) //If Status has changed to EVEN or anything else (GameOver reset).
return;
2019-09-13 15:29:42 -04:00
//Difference Variables
2020-03-25 23:26:45 -04:00
%team1difference = $TeamRank[1, count] - $TeamRank[2, count];
%team2difference = $TeamRank[2, count] - $TeamRank[1, count];
2019-09-13 15:29:42 -04:00
2020-08-29 14:39:32 -04:00
//Determine BigTeam
2020-08-18 13:58:49 -04:00
if( %team1difference >= 2 )
2020-08-29 14:39:32 -04:00
$BigTeam = 1;
2019-09-13 15:29:42 -04:00
else if( %team2difference >= 2 )
2020-08-29 14:39:32 -04:00
$BigTeam = 2;
2020-08-18 13:58:49 -04:00
else
return;
2020-08-29 14:39:32 -04:00
%otherteam = $BigTeam == 1 ? 2 : 1;
if($TeamRank[$BigTeam, count] - $TeamRank[%otherteam, count] >= 3)
%s = "s";
//Warning message
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance will switch the next respawning player%2 on Team %1.', $TeamName[$BigTeam], %s);
}
package Autobalance
{
// called from player scripts
function DefaultGame::onClientKilled(%game, %clVictim, %clKiller, %damageType, %implement, %damageLocation)
{
parent::onClientKilled(%game, %clVictim, %clKiller, %damageType, %implement, %damageLocation);
if($BigTeam !$= "" && %clVictim.team == $BigTeam)
{
%otherteam = $BigTeam == 1 ? 2 : 1;
if($TeamRank[$BigTeam, count] - $TeamRank[%otherteam, count] >= 2)
2020-09-01 11:56:44 -04:00
{
//If someone switches to observer or disconnects
if(%damageType !$= 0)
{
echo(%clVictim.nameBase @ " has been moved to Team " @ %otherTeam @ " for balancing.");
messageClient(%clVictim, 'MsgTeamBalanceNotify', '\c0You were switched to Team %1 for balancing.~wfx/powered/vehicle_screen_on.wav', $TeamName[%otherteam]);
messageAllExcept(%clVictim, -1, 'MsgTeamBalanceNotify', '~wfx/powered/vehicle_screen_on.wav');
Game.clientChangeTeam( %clVictim, %otherTeam, 0 );
}
}
2020-08-29 14:39:32 -04:00
else
{
2020-08-29 14:39:32 -04:00
$BigTeam = "";
ResetTBNStatus();
}
2020-08-29 14:39:32 -04:00
}
2019-09-27 12:48:11 -04:00
}
2020-08-29 14:39:32 -04:00
function DefaultGame::gameOver(%game)
2019-09-27 12:48:11 -04:00
{
2020-08-29 14:39:32 -04:00
Parent::gameOver(%game);
2020-08-29 14:39:32 -04:00
//Reset Autobalance
$BigTeam = "";
}
};
// Prevent package from being activated if it is already
if (!isActivePackage(Autobalance))
activatePackage(Autobalance);