From a532bc15d8cc2d0bb5b22d3bb6b64f7847d7d66e Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Wed, 8 Mar 2023 05:32:03 -0800 Subject: [PATCH] Fix zombie bug (#1014) --- dGame/dGameMessages/GameMessages.cpp | 22 +++++++++++++++------- dScripts/ai/ACT/ActPlayerDeathTrigger.cpp | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index c8860283..8da37bf5 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -915,15 +915,23 @@ void GameMessages::SendSetJetPackMode(Entity* entity, bool use, bool bypassCheck } void GameMessages::SendResurrect(Entity* entity) { - DestroyableComponent* dest = static_cast(entity->GetComponent(eReplicaComponentType::DESTROYABLE)); + // Restore the players health after the animation for respawning has finished. + // This is when the health appered back in live, not immediately upon requesting respawn + // Add a half second in case someone decides to cheat and move during the death animation + // and just make sure the client has time to be ready. + constexpr float respawnTime = 3.66700005531311f + 0.5f; + entity->AddCallbackTimer(respawnTime, [=]() { + auto* destroyableComponent = entity->GetComponent(); - if (dest != nullptr && entity->GetLOT() == 1) { - auto* levelComponent = entity->GetComponent(); - if (levelComponent) { - dest->SetHealth(levelComponent->GetLevel() >= 45 ? 8 : 4); - dest->SetImagination(levelComponent->GetLevel() >= 45 ? 20 : 6); + if (destroyableComponent != nullptr && entity->GetLOT() == 1) { + auto* levelComponent = entity->GetComponent(); + if (levelComponent) { + destroyableComponent->SetHealth(levelComponent->GetLevel() >= 45 ? 8 : 4); + destroyableComponent->SetImagination(levelComponent->GetLevel() >= 45 ? 20 : 6); + } } - } + }); + auto cont = static_cast(entity->GetComponent(eReplicaComponentType::CONTROLLABLE_PHYSICS)); if (cont && entity->GetLOT() == 1) { diff --git a/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp b/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp index 28f1ef43..0674f0dd 100644 --- a/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp +++ b/dScripts/ai/ACT/ActPlayerDeathTrigger.cpp @@ -1,5 +1,7 @@ #include "ActPlayerDeathTrigger.h" +#include "Entity.h" + void ActPlayerDeathTrigger::OnCollisionPhantom(Entity* self, Entity* target) { if (!target->IsPlayer() || target->GetIsDead() || !target->GetPlayerReadyForUpdates()) return; //Don't kill already dead players or players not ready