}
}
-void SetPlayerTeam(entity pl, float t, float s, float noprint)
+bool SetPlayerTeamSimple(entity player, int teamnum)
{
- float _color;
-
- if(t == 4)
- _color = NUM_TEAM_4 - 1;
- else if(t == 3)
- _color = NUM_TEAM_3 - 1;
- else if(t == 2)
- _color = NUM_TEAM_2 - 1;
- else
- _color = NUM_TEAM_1 - 1;
-
- SetPlayerColors(pl,_color);
-
- if(t != s) {
- LogTeamchange(pl.playerid, pl.team, 3); // log manual team join
-
- if(!noprint)
- bprint(playername(pl, false), "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n");
+ if (player.team == teamnum)
+ {
+ return true;
}
+ if (MUTATOR_CALLHOOK(Player_ChangeTeam, player, Team_TeamToNumber(
+ player.team), Team_TeamToNumber(teamnum)) == true)
+ {
+ // Mutator has blocked team change.
+ return false;
+ }
+ int oldteam = player.team;
+ SetPlayerColors(player, teamnum - 1);
+ MUTATOR_CALLHOOK(Player_ChangedTeam, player, oldteam, player.team);
+ return true;
+}
+void SetPlayerTeam(entity pl, float t, float s, float noprint)
+{
+ if (t == s)
+ {
+ return;
+ }
+ float teamnum = Team_NumberToTeam(t);
+ SetPlayerTeamSimple(pl, teamnum);
+ LogTeamchange(pl.playerid, pl.team, 3); // log manual team join
+ if (noprint)
+ {
+ return;
+ }
+ bprint(playername(pl, false), "^7 has changed from ", Team_NumberToColoredFullName(s), "^7 to ", Team_NumberToColoredFullName(t), "\n");
}
// set c1...c4 to show what teams are allowed
int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
{
- float smallest, selectedteam;
-
// don't join a team if we're not playing a team game
- if(!teamplay)
+ if (!teamplay)
+ {
return 0;
+ }
// find out what teams are available
CheckAllowedTeams(this);
+ float selectedteam;
+
// if we don't care what team he ends up on, put him on whatever team he entered as.
// if he's not on a valid team, then let other code put him on the smallest team
- if(!forcebestteam)
+ if (!forcebestteam)
{
if( c1 >= 0 && this.team == NUM_TEAM_1)
selectedteam = this.team;
else
selectedteam = -1;
- if(selectedteam > 0)
+ if (selectedteam > 0)
{
- if(!only_return_best)
+ if (!only_return_best)
{
- SetPlayerColors(this, selectedteam - 1);
+ SetPlayerTeamSimple(this, selectedteam);
// when JoinBestTeam is called by client.qc/ClientKill_Now_TeamChange the players team is -1 and thus skipped
// when JoinBestTeam is called by client.qc/ClientConnect the player_id is 0 the log attempt is rejected
// otherwise end up on the smallest team (handled below)
}
- smallest = FindSmallestTeam(this, true);
+ float bestteam = FindSmallestTeam(this, true);
+ MUTATOR_CALLHOOK(JoinBestTeam, this, bestteam);
+ bestteam = M_ARGV(1, float);
- if(!only_return_best && !this.bot_forced_team)
+ if (only_return_best || this.bot_forced_team)
+ {
+ return bestteam;
+ }
+ bestteam = Team_NumberToTeam(bestteam);
+ if (bestteam != -1)
{
TeamchangeFrags(this);
- if(smallest == 1)
- {
- SetPlayerColors(this, NUM_TEAM_1 - 1);
- }
- else if(smallest == 2)
- {
- SetPlayerColors(this, NUM_TEAM_2 - 1);
- }
- else if(smallest == 3)
- {
- SetPlayerColors(this, NUM_TEAM_3 - 1);
- }
- else if(smallest == 4)
- {
- SetPlayerColors(this, NUM_TEAM_4 - 1);
- }
- else
- {
- error("smallest team: invalid team\n");
- }
-
- LogTeamchange(this.playerid, this.team, 2); // log auto join
-
- if(!IS_DEAD(this))
- Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
+ SetPlayerTeamSimple(this, bestteam);
}
-
- return smallest;
+ else
+ {
+ error("JoinBestTeam: invalid team\n");
+ }
+ LogTeamchange(this.playerid, this.team, 2); // log auto join
+ if (!IS_DEAD(this) && (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) ==
+ false))
+ {
+ Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
+ }
+ return bestteam;
}
//void() ctf_playerchanged;
// not changing teams
if(scolor == dcolor)
{
- //bprint("same team change\n");
SetPlayerTeam(this, dteam, steam, true);
return;
}
TeamchangeFrags(this);
}
- MUTATOR_CALLHOOK(Player_ChangeTeam, this, steam, dteam);
-
SetPlayerTeam(this, dteam, steam, !IS_CLIENT(this));
- if(IS_PLAYER(this) && steam != dteam)
+ if(!IS_PLAYER(this) || (steam == dteam))
{
- // kill player when changing teams
- if(!IS_DEAD(this))
- Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
+ return;
}
+ // kill player when changing teams
+ if(IS_DEAD(this) || (MUTATOR_CALLHOOK(Player_ChangeTeamKill, this) == true))
+ {
+ return;
+ }
+ Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0');
}
void ShufflePlayerOutOfTeam (float source_team)
TeamchangeFrags(selected);
SetPlayerTeam(selected, smallestteam, source_team, false);
- if(!IS_DEAD(selected))
- Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
+ if (IS_DEAD(selected) || MUTATOR_CALLHOOK(Player_ChangeTeamKill, selected) == true)
+ {
+ return;
+ }
+ Damage(selected, selected, selected, 100000, DEATH_AUTOTEAMCHANGE.m_id, selected.origin, '0 0 0');
Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
}