From: Lyberta Date: Sat, 3 Jun 2017 19:56:15 +0000 (+0300) Subject: Added Player_ChangeTeamKill and ClientKill_Now hooks. X-Git-Tag: xonotic-v0.8.5~2482^2~26 X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=1c61b2c73d8e23c5a052c89c406e29938ff623e0 Added Player_ChangeTeamKill and ClientKill_Now hooks. --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index db9b4a8d9b..7245d63084 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -883,8 +883,10 @@ void ClientKill_Now(entity 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'); + } // now I am sure the player IS dead } diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 5a748d8811..eca689e41a 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -730,6 +730,12 @@ MUTATOR_HOOKABLE(Race_FinalCheckpoint, EV_Race_FinalCheckpoint); /**/ 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) \ /**/ @@ -892,11 +898,19 @@ MUTATOR_HOOKABLE(Player_ChangeTeam, EV_Player_ChangeTeam); */ #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); +/** + * 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) \ diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index beb5169020..d434571011 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -532,18 +532,20 @@ float FindSmallestTeam(entity pl, float ignore_pl) 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 - 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; @@ -556,9 +558,9 @@ int JoinBestTeam(entity this, bool only_return_best, bool forcebestteam) else selectedteam = -1; - if(selectedteam > 0) + if (selectedteam > 0) { - if(!only_return_best) + if (!only_return_best) { 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) } - bestteam = 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) { - 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; } @@ -676,12 +679,16 @@ void SV_ChangeTeam(entity this, float _color) 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) @@ -816,7 +823,10 @@ 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); }