From c90f12473526d1d8657e91b3f17619203ab8daa8 Mon Sep 17 00:00:00 2001 From: Lyberta Date: Sun, 2 Apr 2017 18:00:33 +0300 Subject: [PATCH] Added JoinBestTeam hook. --- qcsrc/server/mutators/events.qh | 8 ++++++++ qcsrc/server/teamplay.qc | 14 ++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 6f5feb87c..5a748d881 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -124,6 +124,14 @@ MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS); /**/ MUTATOR_HOOKABLE(CheckAllowedTeams, EV_CheckAllowedTeams); +/** allows overriding best team */ +#define EV_JoinBestTeam(i, o) \ + /** player checked */ i(entity, MUTATOR_ARGV_0_entity) \ + /** team number */ i(float, MUTATOR_ARGV_1_float) \ + /**/ o(float, MUTATOR_ARGV_1_float) \ + /**/ +MUTATOR_HOOKABLE(JoinBestTeam, EV_JoinBestTeam); + /** copies variables for spectating "spectatee" to "this" */ #define EV_SpectateCopy(i, o) \ /** spectatee */ i(entity, MUTATOR_ARGV_0_entity) \ diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 70dc937e5..beb516902 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -532,7 +532,7 @@ float FindSmallestTeam(entity pl, float ignore_pl) int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) { - float smallest, selectedteam; + float bestteam, selectedteam; // don't join a team if we're not playing a team game if(!teamplay) @@ -571,15 +571,17 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) // otherwise end up on the smallest team (handled below) } - smallest = FindSmallestTeam(this, true); + bestteam = FindSmallestTeam(this, true); + MUTATOR_CALLHOOK(JoinBestTeam, this, bestteam); + bestteam = M_ARGV(1, float); if(!only_return_best && !this.bot_forced_team) { - smallest = Team_NumberToTeam(smallest); - if (smallest != -1) + bestteam = Team_NumberToTeam(bestteam); + if (bestteam != -1) { TeamchangeFrags(this); - SetPlayerTeamSimple(this, smallest); + SetPlayerTeamSimple(this, bestteam); } else { @@ -592,7 +594,7 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) Damage(this, this, this, 100000, DEATH_TEAMCHANGE.m_id, this.origin, '0 0 0'); } - return smallest; + return bestteam; } //void() ctf_playerchanged; -- 2.39.2