From: terencehill Date: Wed, 24 Aug 2016 11:41:12 +0000 (+0200) Subject: CA: Forbid spawning players in a more correct way, adding a hook for it; visually... X-Git-Tag: xonotic-v0.8.2~620^2~15 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=87db1635a8541571c00f913bc951031b08140391;p=xonotic%2Fxonotic-data.pk3dir.git CA: Forbid spawning players in a more correct way, adding a hook for it; visually, it fixes gun alignment reverted back to default (right) just when you try to spawn while spectating someone --- diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index ed2faee72..0c4832425 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1698,7 +1698,7 @@ void SpectateCopy(entity this, entity spectatee) bool SpectateUpdate(entity this) { if(!this.enemy) - return false; + return false; if(!IS_PLAYER(this.enemy) || this == this.enemy) { @@ -1861,12 +1861,8 @@ void ShowRespawnCountdown(entity this) } } -.float caplayer; - void LeaveSpectatorMode(entity this) { - if(this.caplayer) - return; if(nJoinAllowed(this, this)) { if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0) @@ -2009,8 +2005,9 @@ void ObserverThink(entity this) MinigameImpulse(this, this.impulse); this.impulse = 0; } + if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) { + if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) { @@ -2049,8 +2046,9 @@ void SpectatorThink(entity this) return; } } + if (this.flags & FL_JUMPRELEASED) { - if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch) { + if (PHYS_INPUT_BUTTON_JUMP(this) && !this.version_mismatch && !MUTATOR_CALLHOOK(ForbidSpawn, this)) { this.flags &= ~FL_JUMPRELEASED; this.flags |= FL_SPAWNING; } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) { diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 7e40b1af1..c8c341556 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -16,6 +16,14 @@ MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver) /**/ MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer); +/** + * return true to prevent a spectator/observer to spawn as player + */ + #define EV_ForbidSpawn(i, o) \ + /** player */ i(entity, MUTATOR_ARGV_0_entity) \ + /**/ +MUTATOR_HOOKABLE(ForbidSpawn, EV_ForbidSpawn); + /** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */ #define EV_PlayerSpawn(i, o) \ /** player spawning */ i(entity, MUTATOR_ARGV_0_entity) \ diff --git a/qcsrc/server/mutators/mutator/gamemode_ca.qc b/qcsrc/server/mutators/mutator/gamemode_ca.qc index 75c9d6008..8dda62f0b 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ca.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ca.qc @@ -166,6 +166,22 @@ MUTATOR_HOOKFUNCTION(ca, PlayerSpawn) eliminatedPlayers.SendFlags |= 1; } +MUTATOR_HOOKFUNCTION(ca, ForbidSpawn) +{ + entity player = M_ARGV(0, entity); + + if (!allowed_to_spawn) + { + if (player.jointime != time && !player.caplayer) // not when connecting + { + player.caplayer = 0.5; + Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE); + } + return true; + } + return false; +} + MUTATOR_HOOKFUNCTION(ca, PutClientInServer) { entity player = M_ARGV(0, entity);