]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Added Player_ChangeTeamKill and ClientKill_Now hooks.
authorLyberta <lyberta@lyberta.net>
Sat, 3 Jun 2017 19:56:15 +0000 (22:56 +0300)
committerLyberta <lyberta@lyberta.net>
Sat, 3 Jun 2017 19:56:15 +0000 (22:56 +0300)
qcsrc/server/client.qc
qcsrc/server/mutators/events.qh
qcsrc/server/teamplay.qc

index db9b4a8d9b6670a6ee952b5565adfac58008b1a6..7245d630842250237c799eaa1148ed0807380274 100644 (file)
@@ -883,8 +883,10 @@ void ClientKill_Now(entity this)
        if(this.killindicator_teamchange)
                ClientKill_Now_TeamChange(this);
 
        if(this.killindicator_teamchange)
                ClientKill_Now_TeamChange(this);
 
-       if(!IS_SPEC(this) && !IS_OBSERVER(this))
+       if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
+       {
                Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
                Damage(this, this, this, 100000, DEATH_KILL.m_id, this.origin, '0 0 0');
+       }
 
        // now I am sure the player IS dead
 }
 
        // now I am sure the player IS dead
 }
index 5a748d8811271a41aa40abb4b6a95086e8a32706..eca689e41a9e315172493dae132e410dd9233a9b 100644 (file)
@@ -730,6 +730,12 @@ MUTATOR_HOOKABLE(Race_FinalCheckpoint, EV_Race_FinalCheckpoint);
     /**/
 MUTATOR_HOOKABLE(ClientKill, EV_ClientKill);
 
     /**/
 MUTATOR_HOOKABLE(ClientKill, EV_ClientKill);
 
+/** called when player is about to be killed during kill command or changing teams */
+#define EV_ClientKill_Now(i, o) \
+    /** player */        i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(ClientKill_Now, EV_ClientKill_Now);
+
 #define EV_FixClientCvars(i, o) \
     /** player */        i(entity, MUTATOR_ARGV_0_entity) \
     /**/
 #define EV_FixClientCvars(i, o) \
     /** player */        i(entity, MUTATOR_ARGV_0_entity) \
     /**/
@@ -892,11 +898,19 @@ MUTATOR_HOOKABLE(Player_ChangeTeam, EV_Player_ChangeTeam);
  */
 #define EV_Player_ChangedTeam(i, o) \
     /** player */         i(entity, MUTATOR_ARGV_0_entity) \
  */
 #define EV_Player_ChangedTeam(i, o) \
     /** player */         i(entity, MUTATOR_ARGV_0_entity) \
-       /** old team */   i(float, MUTATOR_ARGV_1_float) \
-       /** current team */       i(float, MUTATOR_ARGV_2_float) \
+       /** old team */       i(float, MUTATOR_ARGV_1_float) \
+       /** current team */   i(float, MUTATOR_ARGV_2_float) \
     /**/
 MUTATOR_HOOKABLE(Player_ChangedTeam, EV_Player_ChangedTeam);
 
     /**/
 MUTATOR_HOOKABLE(Player_ChangedTeam, EV_Player_ChangedTeam);
 
+/**
+ * Called when player is about to be killed when changing teams. Return true to block killing.
+ */
+#define EV_Player_ChangeTeamKill(i, o) \
+    /** player */    i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(Player_ChangeTeamKill, EV_Player_ChangeTeamKill);
+
 /**/
 #define EV_URI_GetCallback(i, o) \
        /** id */       i(float, MUTATOR_ARGV_0_float) \
 /**/
 #define EV_URI_GetCallback(i, o) \
        /** id */       i(float, MUTATOR_ARGV_0_float) \
index beb5169020565eb5d316487e72a343f6491ea0f7..d434571011d1eaea0b93a29d5fec62b42b24f42a 100644 (file)
@@ -532,18 +532,20 @@ float FindSmallestTeam(entity pl, float ignore_pl)
 
 int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
 {
 
 int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
 {
-       float bestteam, selectedteam;
-
        // don't join a team if we're not playing a team game
        // don't join a team if we're not playing a team game
-       if(!teamplay)
+       if (!teamplay)
+       {
                return 0;
                return 0;
+       }
 
        // find out what teams are available
        CheckAllowedTeams(this);
 
 
        // 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 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;
        {
                if(     c1 >= 0 && this.team == NUM_TEAM_1)
                        selectedteam = this.team;
@@ -556,9 +558,9 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
                else
                        selectedteam = -1;
 
                else
                        selectedteam = -1;
 
-               if(selectedteam > 0)
+               if (selectedteam > 0)
                {
                {
-                       if(!only_return_best)
+                       if (!only_return_best)
                        {
                                SetPlayerTeamSimple(this, selectedteam);
 
                        {
                                SetPlayerTeamSimple(this, selectedteam);
 
@@ -571,29 +573,30 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam)
                // otherwise end up on the smallest team (handled below)
        }
 
                // otherwise end up on the smallest team (handled below)
        }
 
-       bestteam = FindSmallestTeam(this, true);
+       float bestteam = FindSmallestTeam(this, true);
        MUTATOR_CALLHOOK(JoinBestTeam, this, bestteam);
        bestteam = M_ARGV(1, float);
 
        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)
        {
        {
-               bestteam = Team_NumberToTeam(bestteam);
-               if (bestteam != -1)
-               {
-                       TeamchangeFrags(this);
-                       SetPlayerTeamSimple(this, bestteam);
-               }
-               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');
+               return bestteam;
+       }
+       bestteam = Team_NumberToTeam(bestteam);
+       if (bestteam != -1)
+       {
+               TeamchangeFrags(this);
+               SetPlayerTeamSimple(this, bestteam);
+       }
+       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;
 }
 
        return bestteam;
 }
 
@@ -676,12 +679,16 @@ void SV_ChangeTeam(entity this, float _color)
 
        SetPlayerTeam(this, dteam, steam, !IS_CLIENT(this));
 
 
        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)
 }
 
 void ShufflePlayerOutOfTeam (float source_team)
@@ -816,7 +823,10 @@ void ShufflePlayerOutOfTeam (float source_team)
        TeamchangeFrags(selected);
        SetPlayerTeam(selected, smallestteam, source_team, false);
 
        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);
 }
        Send_Notification(NOTIF_ONE, selected, MSG_CENTER, CENTER_DEATH_SELF_AUTOTEAMCHANGE, selected.team);
 }