2019-01-21 12:21:59 -05:00
// GetCounts was made to accurately keep track of how many players
// are on teams, on the server, on each team, spectator, etc.
2019-02-03 02:52:11 -05:00
// It runs every 5 seconds.
2019-01-21 12:21:59 -05:00
// It has since evolved into the place to inject other services
// and aspects within the server.
//
2018-11-10 19:55:31 -05:00
//
2019-01-21 12:21:59 -05:00
// To control whether the server auto resets when empty
// $Host::EmptyServerReset = 0;
2018-06-28 14:34:52 -04:00
2019-04-01 16:01:02 -04:00
$ GetCountsClientTeamChange = true ;
2018-11-10 20:52:29 -05:00
package StartTeamCounts
{
2018-11-13 15:30:41 -05:00
function CreateServer ( % mission , % missionType )
2018-06-28 14:34:52 -04:00
{
2018-11-13 15:30:41 -05:00
parent : : CreateServer ( % mission , % missionType ) ;
2019-01-21 12:21:59 -05:00
//Call for a GetTeamCount update
GetTeamCounts ( % game , % client , % respawn ) ;
2018-11-10 20:52:29 -05:00
//Whether the server auto restarts when empty or not
2018-11-10 19:55:31 -05:00
$ Host : : Dedicated = $ Host : : EmptyServerReset ;
2018-06-28 14:34:52 -04:00
}
} ;
// Prevent package from being activated if it is already
if ( ! isActivePackage ( StartTeamCounts ) )
activatePackage ( StartTeamCounts ) ;
function GetTeamCounts ( % game , % client , % respawn )
2019-03-31 17:16:43 -04:00
{
2019-02-24 05:03:49 -05:00
//Run MissionTypeOptions
MissionTypeOptions ( ) ;
2018-10-25 20:36:34 -04:00
2018-11-10 20:52:29 -05:00
//Get teamcounts
2018-11-13 15:30:41 -05:00
if ( $ GetCountsClientTeamChange & & $ countdownStarted & & $ MatchStarted )
2019-03-31 17:16:43 -04:00
{
2018-11-10 20:52:29 -05:00
//Team Count code by Keen
$ PlayerCount [ 0 ] = 0 ;
$ PlayerCount [ 1 ] = 0 ;
$ PlayerCount [ 2 ] = 0 ;
2019-03-31 17:16:43 -04:00
//For autobalance
% lastclient1 = "" ;
% lastclient2 = "" ;
2018-06-28 14:34:52 -04:00
for ( % i = 0 ; % i < ClientGroup . getCount ( ) ; % i + + )
{
% client = ClientGroup . getObject ( % i ) ;
2019-03-31 17:16:43 -04:00
//Pick a client for autobalance
2019-03-31 17:49:13 -04:00
% team = % client . team ;
2019-03-31 18:01:49 -04:00
if ( % client . score < % lastclient [ % team ] . score | | % lastclient [ % team ] $ = "" ) {
% teamcanidate [ % team ] = % client ;
}
% lastclient [ % team ] = % client ;
2019-02-04 15:22:33 -05:00
2019-02-22 19:25:53 -05:00
//Check ver
2019-02-23 01:05:31 -05:00
if ( ! % client . isAIControlled ( ) ) //No bots
CheckVerObserver ( % client ) ;
2019-02-22 19:25:53 -05:00
2018-06-28 14:34:52 -04:00
//if(!%client.isAIControlled())
2019-02-23 01:05:31 -05:00
$ PlayerCount [ % client . team ] + + ;
2018-06-28 14:34:52 -04:00
}
2019-03-31 17:49:13 -04:00
$ team1canidate = % teamcanidate1 ;
$ team2canidate = % teamcanidate2 ;
2018-09-16 11:07:47 -04:00
//echo ("$PlayerCount[0] " @ $PlayerCount[0]);
//echo ("$PlayerCount[1] " @ $PlayerCount[1]);
//echo ("$PlayerCount[2] " @ $PlayerCount[2]);
2019-02-03 18:00:37 -05:00
2018-11-10 20:52:29 -05:00
//Amount of players on teams
$ TotalTeamPlayerCount = $ PlayerCount [ 1 ] + $ PlayerCount [ 2 ] ;
//Amount of all players including observers
$ AllPlayerCount = $ PlayerCount [ 1 ] + $ PlayerCount [ 2 ] + $ PlayerCount [ 0 ] ;
2019-02-03 02:52:11 -05:00
//Difference Variables
$ Team1Difference = $ PlayerCount [ 1 ] - $ PlayerCount [ 2 ] ;
$ Team2Difference = $ PlayerCount [ 2 ] - $ PlayerCount [ 1 ] ;
2018-09-16 11:07:47 -04:00
2018-11-10 20:52:29 -05:00
//Start Base Rape Notify
2019-02-03 02:52:11 -05:00
schedule ( 500 , 0 , "NBRStatusNotify" , % game ) ;
2019-01-31 02:07:19 -05:00
//Start Team Balance Notify
2019-02-04 22:54:58 -05:00
schedule ( 1000 , 0 , "TeamBalanceNotify" , % game ) ;
2019-01-31 02:07:19 -05:00
//Start AntiCloak
2019-02-03 02:52:11 -05:00
schedule ( 1500 , 0 , "ActivateAntiCloak" , % game ) ;
2019-02-17 18:36:49 -05:00
//Start MapRepetitionChecker
schedule ( 2000 , 0 , "MapRepetitionChecker" , % game ) ;
2019-01-26 10:44:11 -05:00
2019-02-22 19:25:53 -05:00
2018-11-10 23:10:39 -05:00
//Set so counter wont run when it doesnt need to.
2018-09-16 11:07:47 -04:00
$ GetCountsClientTeamChange = false ;
2018-11-10 20:52:29 -05:00
}
2018-06-28 14:34:52 -04:00
2019-02-03 02:52:11 -05:00
//Call itself again. Every 5 seconds.
schedule ( 5000 , 0 , "GetTeamCounts" ) ;
2018-06-28 14:34:52 -04:00
}
2018-09-16 11:07:47 -04:00
//Run at DefaultGame::clientJoinTeam, DefaultGame::clientChangeTeam, DefaultGame::assignClientTeam in evo defaultgame.ovl
//Also Run at DefaultGame::onClientEnterObserverMode, DefaultGame::AIChangeTeam, DefaultGame::onClientLeaveGame, DefaultGame::forceObserver in evo defaultgame.ovl
2019-01-26 10:44:11 -05:00
//And finally GameConnection::onConnect in evo server.ovl
2018-09-16 11:07:47 -04:00
//Added so the bulk of GetCounts doesnt run when it doesnt need to causing unnecessary latency that may or may not have existed, but probably is good practice.
2019-02-03 02:52:11 -05:00
//GetCounts still runs every 5 seconds as it did, but whether or not someone has changed teams, joined obs, left, etc etc will decide whether or not the bulk of it runs.
2018-11-10 20:52:29 -05:00
//Let GetTeamCounts run if there is a Teamchange.
function ResetClientChangedTeams ( )
{
2018-09-16 11:07:47 -04:00
$ GetCountsClientTeamChange = true ;
}