TacoServer/Classic/scripts/autoexec/GetTeamCounts.cs

167 lines
4.1 KiB
C#
Raw Normal View History

2019-09-13 15:29:42 -04:00
// GetTeamCounts Script
//
// GetTeamCounts was made to accurately keep track of how many players
// are on teams, on the server, on each team, observer, etc.
// AntiTurrets, Team Balance Notify, AntiCloak, AutoBalance, Base Rape and Base Rape Notify all rely on this.
2019-02-03 02:52:11 -05:00
// It runs every 5 seconds.
2019-01-21 12:21:59 -05:00
//
2019-09-13 15:29:42 -04:00
// Whether or not a portion of the script is run or not depends on
// if a player has switched teams or not. Or if a team changing event has occurred.
// This is triggered via various event functions throughout the game.
//
2018-06-28 14:34:52 -04:00
2019-09-13 15:29:42 -04:00
// Set reset string
2019-04-01 16:01:02 -04:00
$GetCountsClientTeamChange = true;
2018-11-10 20:52:29 -05:00
package StartTeamCounts
{
function CreateServer( %mission, %missionType )
2018-06-28 14:34:52 -04:00
{
parent::CreateServer( %mission, %missionType );
2019-01-21 12:21:59 -05:00
//Call for a GetTeamCount update
GetTeamCounts( %game, %client, %respawn );
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 )
{
2018-11-10 20:52:29 -05:00
//Get teamcounts
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
2018-06-28 14:34:52 -04:00
for(%i = 0; %i < ClientGroup.getCount(); %i++)
{
%client = ClientGroup.getObject(%i);
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
}
//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
2019-09-13 15:29:42 -04:00
%team1difference = $PlayerCount[1] - $PlayerCount[2];
%team2difference = $PlayerCount[2] - $PlayerCount[1];
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-09-13 15:29:42 -04:00
schedule(1000, 0, "TeamBalanceNotify", %game, %team1difference, %team2difference);
2019-01-31 02:07:19 -05:00
//Start AntiCloak
schedule(1500, 0, "CheckAntiCloak", %game);
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.
$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-11-10 20:52:29 -05:00
// Triggers a Full run
2018-11-10 20:52:29 -05:00
function ResetClientChangedTeams()
{
$GetCountsClientTeamChange = true;
}
// Proper Overrides
// Events that determine a TeamGetCounts update
package TeamCountsTriggers
{
function DefaultGame::clientJoinTeam( %game, %client, %team, %respawn )
{
Parent::clientJoinTeam( %game, %client, %team, %respawn );
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::clientChangeTeam(%game, %client, %team, %fromObs, %respawned)
{
Parent::clientChangeTeam(%game, %client, %team, %fromObs, %respawned);
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::assignClientTeam(%game, %client, %respawn )
{
Parent::assignClientTeam(%game, %client, %respawn );
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::onClientEnterObserverMode( %game, %client )
{
Parent::onClientEnterObserverMode( %game, %client );
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::AIChangeTeam(%game, %client, %newTeam)
{
Parent::AIChangeTeam(%game, %client, %newTeam);
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::onClientLeaveGame(%game, %client)
{
Parent::onClientLeaveGame(%game, %client);
//Trigger GetCounts
ResetClientChangedTeams();
}
function DefaultGame::forceObserver(%game, %client, %reason)
{
Parent::forceObserver(%game, %client, %reason);
//Trigger GetCounts
ResetClientChangedTeams();
}
function GameConnection::onConnect(%client, %name, %raceGender, %skin, %voice, %voicePitch)
{
Parent::onConnect(%client, %name, %raceGender, %skin, %voice, %voicePitch);
//Reset GetCounts
ResetClientChangedTeams();
}
function DefaultGame::gameOver(%game)
{
Parent::gameOver(%game);
//Reset GetCounts
ResetClientChangedTeams();
}
};
// Prevent package from being activated if it is already
if (!isActivePackage(TeamCountsTriggers))
activatePackage(TeamCountsTriggers);