From c24e4b36dd13ae92289d670a4460e8fe54ea79d7 Mon Sep 17 00:00:00 2001 From: drjaska Date: Sat, 24 Aug 2024 00:19:34 +0300 Subject: [PATCH] Rewrite --- qcsrc/server/client.qc | 15 +++------------ qcsrc/server/client.qh | 1 + qcsrc/server/player.qc | 35 +++++++++++++++++++++++------------ qcsrc/server/player.qh | 2 ++ xonotic-server.cfg | 1 + 5 files changed, 30 insertions(+), 24 deletions(-) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 1336aef59..6057d0dd5 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1470,19 +1470,10 @@ void respawn(entity this) bool damagedbycontents_prev = this.damagedbycontents; if(this.alpha >= 0) { - if(autocvar_g_respawn_ghosts && !(this.effects & EF_NODRAW)) + if(autocvar_g_respawn_ghosts + && !(this.effects & EF_NODRAW)) // only spawn one ghost { - this.solid = SOLID_NOT; - this.takedamage = DAMAGE_NO; - this.damagedbycontents = false; - set_movetype(this, MOVETYPE_FLY); - this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed; - this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3; - this.effects |= CSQCMODEL_EF_RESPAWNGHOST; - this.alpha = min(this.alpha, autocvar_g_respawn_ghosts_alpha); - Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1); - if(autocvar_g_respawn_ghosts_time > 0) - SUB_SetFade(this, time + autocvar_g_respawn_ghosts_time, autocvar_g_respawn_ghosts_fadetime); + SpawnGhost(this); } else SUB_SetFade (this, time, 1); // fade out the corpse immediately diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index d7fb94837..d7240d952 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -26,6 +26,7 @@ int autocvar_g_respawn_delay_large_count; float autocvar_g_respawn_delay_max; bool autocvar_g_respawn_delay_forced; bool autocvar_g_respawn_ghosts; +bool autocvar_g_respawn_ghosts_gib; float autocvar_g_respawn_ghosts_alpha = 1; float autocvar_g_respawn_ghosts_fadetime = 1.5; float autocvar_g_respawn_ghosts_time = 4.5; diff --git a/qcsrc/server/player.qc b/qcsrc/server/player.qc index 9bf43125d..faaec731c 100644 --- a/qcsrc/server/player.qc +++ b/qcsrc/server/player.qc @@ -225,19 +225,11 @@ void PlayerCorpseDamage(entity this, entity inflictor, entity attacker, float da IL_REMOVE(g_damagedbycontents, this); this.damagedbycontents = false; - if (autocvar_g_respawn_ghosts) + if(autocvar_g_respawn_ghosts + && autocvar_g_respawn_ghosts_gib + && !(this.effects & EF_NODRAW)) // only spawn one ghost { - //this.solid = SOLID_NOT; // already set above - //this.takedamage = DAMAGE_NO; - //this.damagedbycontents = false; - set_movetype(this, MOVETYPE_FLY); - this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed; - this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3; - this.effects |= CSQCMODEL_EF_RESPAWNGHOST; - this.alpha = min(this.alpha, autocvar_g_respawn_ghosts_alpha); - Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1); - if(autocvar_g_respawn_ghosts_time > 0) - SUB_SetFade(this, time + autocvar_g_respawn_ghosts_time, autocvar_g_respawn_ghosts_fadetime); + SpawnGhost(this); CopyBody(this, 1); this.effects |= EF_NODRAW; // prevent another CopyBody and 2nd ghost spawns @@ -636,6 +628,25 @@ bool PlayerHeal(entity targ, entity inflictor, float amount, float limit) return true; } +void SpawnGhost(entity this) +{ + // effects are disabled or one ghost was already spawned + if (this.effects & EF_NODRAW) + return; + + this.solid = SOLID_NOT; + this.takedamage = DAMAGE_NO; + this.damagedbycontents = false; + set_movetype(this, MOVETYPE_FLY); + this.velocity = '0 0 1' * autocvar_g_respawn_ghosts_speed; + this.avelocity = randomvec() * autocvar_g_respawn_ghosts_speed * 3 - randomvec() * autocvar_g_respawn_ghosts_speed * 3; + this.effects |= CSQCMODEL_EF_RESPAWNGHOST; + this.alpha = min(this.alpha, autocvar_g_respawn_ghosts_alpha); + Send_Effect(EFFECT_RESPAWN_GHOST, this.origin, '0 0 0', 1); + if(autocvar_g_respawn_ghosts_time > 0) + SUB_SetFade(this, time + autocvar_g_respawn_ghosts_time, autocvar_g_respawn_ghosts_fadetime); +} + void precache_playermodel(string m) { int globhandle, i, n; diff --git a/qcsrc/server/player.qh b/qcsrc/server/player.qh index 34c8fdbdf..10b394502 100644 --- a/qcsrc/server/player.qh +++ b/qcsrc/server/player.qh @@ -44,5 +44,7 @@ bool PlayerHeal(entity targ, entity inflictor, float amount, float limit); void precache_all_playermodels(string pattern); +void SpawnGhost(entity this); + IntrusiveList g_clones; STATIC_INIT(g_clones) { g_clones = IL_NEW(); } diff --git a/xonotic-server.cfg b/xonotic-server.cfg index 327abe3f3..7d62a345a 100644 --- a/xonotic-server.cfg +++ b/xonotic-server.cfg @@ -60,6 +60,7 @@ set g_teleport_maxspeed 0 "maximum speed that a player can keep when going throu set g_teleport_minspeed 0 "minimum speed that a player can keep when going through a teleporter which affects speed" set g_respawn_ghosts 1 "if 1 dead bodies become ghosts and float away when the player respawns" +set g_respawn_ghosts_gib 0 "spawn a ghost for gibbed players instantly" set g_respawn_ghosts_speed 5 "the speed with which respawn ghosts float and rotate" set g_respawn_ghosts_time 4.5 "amount of time a respawn ghost lasts before it starts fading out. 0 disables and ghosts fade when the body would" set g_respawn_ghosts_fadetime 1.5 "amount of time a respawn ghost takes to fade out" -- 2.39.2