From e1c890a011cdd33de6f2de46800b8baccc5496f9 Mon Sep 17 00:00:00 2001 From: "ALLEN-PC\\acj30" Date: Fri, 5 Jan 2024 13:19:33 -0600 Subject: [PATCH] New response context-based check for TLK_SPOTTED_HEADCRAB_LEAVING_ZOMBIE (because some death types, such as serverside ragdolling, remove the zombie instantly) --- sp/src/game/server/hl2/npc_BaseZombie.cpp | 3 +++ sp/src/game/server/hl2/npc_playercompanion.cpp | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sp/src/game/server/hl2/npc_BaseZombie.cpp b/sp/src/game/server/hl2/npc_BaseZombie.cpp index fee51dd7..4bd4b475 100644 --- a/sp/src/game/server/hl2/npc_BaseZombie.cpp +++ b/sp/src/game/server/hl2/npc_BaseZombie.cpp @@ -2544,6 +2544,9 @@ void CNPC_BaseZombie::ReleaseHeadcrab( const Vector &vecOrigin, const Vector &ve #ifdef MAPBASE // Inherit some misc. properties pGib->m_iViewHideFlags = m_iViewHideFlags; + + // Add response context for companion response (more reliable than checking for post-death zombie entity) + pCrab->AddContext( "from_zombie", "1", 2.0f ); #endif pGib->SetOwnerEntity( this ); diff --git a/sp/src/game/server/hl2/npc_playercompanion.cpp b/sp/src/game/server/hl2/npc_playercompanion.cpp index a1bd6e26..37246915 100644 --- a/sp/src/game/server/hl2/npc_playercompanion.cpp +++ b/sp/src/game/server/hl2/npc_playercompanion.cpp @@ -659,10 +659,15 @@ void CNPC_PlayerCompanion::DoCustomSpeechAI( void ) { SpeakIfAllowed( "TLK_SPOTTED_INCOMING_HEADCRAB" ); } - // If we see a headcrab leaving a zombie that just died, mention it - else if ( pHC->GetOwnerEntity() && ( pHC->GetOwnerEntity()->Classify() == CLASS_ZOMBIE ) && !pHC->GetOwnerEntity()->IsAlive() ) + else { - SpeakIfAllowed( "TLK_SPOTTED_HEADCRAB_LEAVING_ZOMBIE" ); + // If we see a headcrab leaving a zombie that just died, mention it + // (Note that this is now a response context since some death types remove the zombie instantly) + int nContext = pHC->FindContextByName( "from_zombie" ); + if ( nContext > -1 && !ContextExpired( nContext ) ) // pHC->GetOwnerEntity() && ( pHC->GetOwnerEntity()->Classify() == CLASS_ZOMBIE ) && !pHC->GetOwnerEntity()->IsAlive() + { + SpeakIfAllowed( "TLK_SPOTTED_HEADCRAB_LEAVING_ZOMBIE" ); + } } } }