public override void OnPlayerTeamChange(String soldierName, int teamId, int squadId)
{
if (!fIsEnabled) return;
DebugWrite("^9^bGot OnPlayerTeamChange^n: " + soldierName + " " + teamId + " " + squadId, 6);
if (fPluginState == PluginState.Disabled || fPluginState == PluginState.Error) return;
try {
// Only teamId is valid for BF3, squad change is sent on separate event
// Handle team change event
if (fReassigned.Contains(soldierName)) {
// We reassigned this new player
fReassigned.Remove(soldierName);
IncrementTotal();
fReassignedRound = fReassignedRound + 1;
AddNewPlayer(soldierName, teamId);
UpdateTeams();
DebugWrite("^4New player^0: ^b" + soldierName + "^n, reassigned to " + GetTeamName(teamId) + " team by " + GetPluginName(), 4);
} else if (!IsKnownPlayer(soldierName)) {
int diff = 0;
bool mustMove = false; // don't have a player model yet, can't determine if must move
int reassignTo = ToTeam(soldierName, teamId, true, out diff, ref mustMove);
if (!ReassignNewPlayers) {
DebugWrite("^4New player^0: ^b" + soldierName + "^n not reassigned, Reassign New Players set to False", 5);
reassignTo = 0;
}
if ((reassignTo == 0 || reassignTo == teamId) && !fWhileScrambling) {
// New player was going to the right team anyway
IncrementTotal(); // no matching stat, reflects non-reassigment joins
AddNewPlayer(soldierName, teamId);
UpdateTeams();
DebugWrite("^4New player^0: ^b" + soldierName + "^n, assigned to " + GetTeamName(teamId) + " team by game server", 4);
if (EnableAdminKillForFastBalance) {
FastBalance("New Player: ");
}
} else {
Reassign(soldierName, teamId, reassignTo, diff);
}
} else if (fGameState == GameState.Playing) {
// If this was an MB move, finish it
bool wasPluginMove = FinishMove(soldierName, teamId);
// Handle remote disabling of unswitcher
bool dontDoubleCount = false;
if (fDisableUnswitcherByRemote) {
DebugWrite("^nPlayer ^b" + soldierName + "^n moved to team " + teamId + ": ^8another plugin DISABLED the unswitcher!^0^n", 4);
PlayerModel lucky = GetPlayer(soldierName);
if (lucky != null) {
lucky.MovesRound = lucky.MovesRound + 1;
UpdateMoveTime(soldierName);
UpdatePlayerTeam(soldierName, teamId);
UpdateTeams();
dontDoubleCount = true;
// Do not increment stats
}
}
/*
* We need to determine if this team change was instigated by a player or by an admin (plugin).
* We want to ignore moves by admin. This is tricky due to the events possibly being
* in reverse order (team change first, then moved by admin). Use player.isAlive
* to force a round trip with the game server, to insure that we get the admin move
* event, if it exists.
*/
if (fPendingTeamChange.ContainsKey(soldierName)) {
// This is an admin move in correct order, do not treat it as a team switch
fPendingTeamChange.Remove(soldierName);
DebugWrite("Moved by admin: ^b" + soldierName + "^n to team " + teamId, 6);
if (!wasPluginMove) {
// Some other admin.movePlayer, so update to account for it
DebugWrite("^4^bADMIN^n moved player ^b" + soldierName + "^n, " + GetPluginName() + " will respect this move", 2);
if (dontDoubleCount) {
ConditionalIncrementMoves(soldierName);
UpdatePlayerTeam(soldierName, teamId);
UpdateTeams();
}
} // MB moves incremented by FinishMove, so nothing to do here
return;
}
// Remember the pending move in a table
fPendingTeamChange[soldierName] = teamId;
// Admin move event may still be on its way, so do a round-trip to check
ServerCommand("player.isAlive", soldierName);
} else if (fGameState == GameState.RoundStarting || fGameState == GameState.RoundEnding) {
UpdatePlayerTeam(soldierName, teamId);
UpdateTeams();
}
} catch (Exception e) {
ConsoleException(e);
}
}