mirror of
https://github.com/ChocoTaco1/TacoServer.git
synced 2026-07-14 07:34:36 +00:00
Goon Style: onClientKilled Autobalance
This commit is contained in:
parent
32a196d5f6
commit
fc4a37bd3f
1 changed files with 51 additions and 116 deletions
|
|
@ -1,19 +1,15 @@
|
||||||
// Team Autobalance Script
|
// Team Autobalance Script
|
||||||
//
|
//
|
||||||
// Determines which team needs players and proceeds to find candidates
|
// Determines which team needs players and proceeds to switch them
|
||||||
// Candidates are based on low scores then switches the candidate
|
// Goon style: At respawn
|
||||||
//
|
//
|
||||||
// Enable or Disable Autobalance
|
// Enable or Disable Autobalance
|
||||||
// $Host::EnableAutobalance = 1;
|
// $Host::EnableAutobalance = 1;
|
||||||
|
//
|
||||||
|
// exec("scripts/autoexec/Autobalance.cs");
|
||||||
|
|
||||||
// How far behind littleTeam must be to use All Mode.
|
// Run from TeamBalanceNotify.cs via NotifyUnbalanced
|
||||||
// Meaning picking from a pool of all players on the bigTeam instead of just the lowest scoring player.
|
function Autobalance( %game )
|
||||||
// 400 equals 400 points. 4 caps behind.
|
|
||||||
$AllModeThreshold = 300;
|
|
||||||
|
|
||||||
|
|
||||||
// Run from TeamBalanceNotify.cs via UnbalancedSound( %game )
|
|
||||||
function Autobalance( %game, %AutobalanceSafetynetTrys )
|
|
||||||
{
|
{
|
||||||
if(isEventPending($AutoBalanceSchedule))
|
if(isEventPending($AutoBalanceSchedule))
|
||||||
cancel($AutoBalanceSchedule);
|
cancel($AutoBalanceSchedule);
|
||||||
|
|
@ -21,123 +17,62 @@ function Autobalance( %game, %AutobalanceSafetynetTrys )
|
||||||
if( $TBNStatus !$= "NOTIFY" ) //If Status has changed to EVEN or anything else (GameOver reset).
|
if( $TBNStatus !$= "NOTIFY" ) //If Status has changed to EVEN or anything else (GameOver reset).
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Debug: Uncomment to enable
|
|
||||||
//%AutobalanceDebug = true;
|
|
||||||
|
|
||||||
//Difference Variables
|
//Difference Variables
|
||||||
%team1difference = $TeamRank[1, count] - $TeamRank[2, count];
|
%team1difference = $TeamRank[1, count] - $TeamRank[2, count];
|
||||||
%team2difference = $TeamRank[2, count] - $TeamRank[1, count];
|
%team2difference = $TeamRank[2, count] - $TeamRank[1, count];
|
||||||
|
|
||||||
//Determine bigTeam
|
//Determine BigTeam
|
||||||
if( %team1difference >= 2 )
|
if( %team1difference >= 2 )
|
||||||
%bigTeam = 1;
|
$BigTeam = 1;
|
||||||
else if( %team2difference >= 2 )
|
else if( %team2difference >= 2 )
|
||||||
%bigTeam = 2;
|
$BigTeam = 2;
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
||||||
%littleTeam = ( %bigTeam == 1 ) ? 2 : 1;
|
%otherteam = $BigTeam == 1 ? 2 : 1;
|
||||||
|
if($TeamRank[$BigTeam, count] - $TeamRank[%otherteam, count] >= 3)
|
||||||
|
%s = "s";
|
||||||
|
|
||||||
//Toggle for All Mode
|
//Warning message
|
||||||
//If a team is behind pick anyone, not just a low scoring player
|
messageAll('MsgTeamBalanceNotify', '\c1Teams are unbalanced: \c0Autobalance will switch the next respawning player%2 on Team %1.', $TeamName[$BigTeam], %s);
|
||||||
if( $TeamScore[%bigTeam] > ($TeamScore[%littleTeam] + $AllModeThreshold))
|
|
||||||
{
|
|
||||||
%UseAllMode = 1;
|
|
||||||
//Find if anyone is holding a flag for exceptions for the loop
|
|
||||||
for(%i = 0; %i < ClientGroup.getCount(); %i++)
|
|
||||||
{
|
|
||||||
%client = ClientGroup.getObject(%i);
|
|
||||||
%team = %client.team;
|
|
||||||
|
|
||||||
if(%team $= %bigTeam)
|
|
||||||
{
|
|
||||||
//Holding flag?
|
|
||||||
if(%client.player.holdingFlag !$= "")
|
|
||||||
%exception = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
%autobalanceRandom = getRandom(1,($TeamRank[%bigTeam, count] - %exception));
|
|
||||||
}
|
|
||||||
|
|
||||||
//Pick a client for autobalance
|
|
||||||
for(%i = 0; %i < ClientGroup.getCount(); %i++)
|
|
||||||
{
|
|
||||||
%client = ClientGroup.getObject(%i);
|
|
||||||
%team = %client.team;
|
|
||||||
|
|
||||||
if(%team $= %bigTeam)
|
|
||||||
{
|
|
||||||
//Holding flag?
|
|
||||||
if(%client.player.holdingFlag !$= "")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(%UseAllMode)
|
|
||||||
{
|
|
||||||
//Pick our random
|
|
||||||
if(%autobalanceRandom == %AllmodeLoop || %canidate $= "")
|
|
||||||
%canidate = %client;
|
|
||||||
|
|
||||||
%AllmodeLoop++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//Try to pick a low scoring player
|
|
||||||
if(%client.score < %canidate.score || %canidate $= "")
|
|
||||||
%canidate = %client;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Debug
|
|
||||||
if( %AutobalanceDebug )
|
|
||||||
AutobalanceDebug(%canidate, %team1difference, %team2difference, %bigTeam, %AutobalanceSafetynetTrys, %UseAllMode);
|
|
||||||
|
|
||||||
%client = %canidate;
|
|
||||||
%team = %canidate.team;
|
|
||||||
%otherTeam = ( %team == 1 ) ? 2 : 1;
|
|
||||||
|
|
||||||
//Fire Autobalance
|
|
||||||
Game.clientChangeTeam( %client, %otherTeam, 0 );
|
|
||||||
messageClient(%client, 'MsgTeamBalanceNotify', "\c0You were switched to the other team for balancing.~wfx/powered/vehicle_screen_on.wav");
|
|
||||||
messageAllExcept(%client, -1, 'MsgTeamBalanceNotify', "~wfx/powered/vehicle_screen_on.wav");
|
|
||||||
|
|
||||||
//Trigger GetCounts
|
|
||||||
ResetGetCountsStatus();
|
|
||||||
//Reset TBN
|
|
||||||
ResetTBNStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function AutobalanceDebug(%canidate, %team1difference, %team2difference, %bigTeam, %AutobalanceSafetynetTrys, %UseAllMode)
|
package Autobalance
|
||||||
{
|
{
|
||||||
if( %teamcanidate[%bigTeam] $= "" )
|
|
||||||
{
|
|
||||||
%AutobalanceSafetynetTrys++;
|
|
||||||
if(%AutobalanceSafetynetTrys $= 3)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if( %canidate $= "" )
|
// called from player scripts
|
||||||
%error = "Team " @ %bigTeam;
|
function DefaultGame::onClientKilled(%game, %clVictim, %clKiller, %damageType, %implement, %damageLocation)
|
||||||
|
{
|
||||||
|
parent::onClientKilled(%game, %clVictim, %clKiller, %damageType, %implement, %damageLocation);
|
||||||
|
|
||||||
if( %error !$= "" )
|
if($BigTeam !$= "" && %clVictim.team == $BigTeam)
|
||||||
messageAll('MsgTeamBalanceNotify', '\c0Autobalance error: %1', %error );
|
{
|
||||||
|
%otherteam = $BigTeam == 1 ? 2 : 1;
|
||||||
//Trigger GetCounts
|
if($TeamRank[$BigTeam, count] - $TeamRank[%otherteam, count] >= 2)
|
||||||
ResetGetCountsStatus();
|
{
|
||||||
//Rerun in 10 secs
|
Game.clientChangeTeam( %clVictim, %otherTeam, 0 );
|
||||||
schedule(10000, 0, "Autobalance", %game, %AutobalanceSafetynetTrys );
|
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');
|
||||||
if(%UseAllMode)
|
}
|
||||||
%mode = "All";
|
else
|
||||||
else
|
{
|
||||||
%mode = "Low";
|
$BigTeam = "";
|
||||||
|
ResetTBNStatus();
|
||||||
if( %teamcanidate1 $= "" )
|
}
|
||||||
%teamcanidate1 = "NULL";
|
}
|
||||||
if( %teamcanidate2 $= "" )
|
|
||||||
%teamcanidate2 = "NULL";
|
|
||||||
|
|
||||||
messageAll('MsgTeamBalanceNotify', '\c0Autobalance stat: %1, %2, %3, %4', %canidate, %team1difference, %team2difference, %mode );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function DefaultGame::gameOver(%game)
|
||||||
|
{
|
||||||
|
Parent::gameOver(%game);
|
||||||
|
|
||||||
|
//Reset Autobalance
|
||||||
|
$BigTeam = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Prevent package from being activated if it is already
|
||||||
|
if (!isActivePackage(Autobalance))
|
||||||
|
activatePackage(Autobalance);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue