Fix weapon respawn

► Fixed an issue where weapons can improperly respawn when their collision box intersects brushes or other objects causing them to perpetually fall in the void.
This commit is contained in:
speedvoltage 2025-03-10 22:01:00 +01:00
parent a62efecf62
commit 54e5a5fc8d
2 changed files with 27 additions and 1 deletions

View file

@ -206,6 +206,31 @@ int CWeaponHL2MPBase::ObjectCaps()
#endif
#ifdef GAME_DLL
void CWeaponHL2MPBase::FallThink( void )
{
// Prevent the common HL2DM weapon respawn bug from happening
// When a weapon is spawned, the following chain of events occurs:
// - Spawn() is called, which then calls FallInit()
// - FallInit() is called, and prepares the weapon's 'Think' function (CBaseCombatWeapon::FallThink())
// - FallThink() is called, and performs several checks before deciding whether the weapon should Materialize()
// - Materialize() is called (the HL2DM version above), which sets the weapon's respawn location.
// The problem occurs when a weapon isn't placed properly by a level designer.
// If the weapon is unable to move from its location (e.g. if its bounding box is halfway inside a wall), Materialize() never gets called.
// Since Materialize() never gets called, the weapon's respawn location is never set, so if a person picks it up, it respawns forever at
// 0 0 0 on the map (infinite loop of fall, wait, respawn, not nice at all for performance and bandwidth!)
if ( HasSpawnFlags( SF_NORESPAWN ) == false )
{
if ( GetOriginalSpawnOrigin() == vec3_origin )
{
m_vOriginalSpawnOrigin = GetAbsOrigin();
m_vOriginalSpawnAngles = GetAbsAngles();
}
}
return BaseClass::FallThink();
}
#endif // GAME_DLL
void CWeaponHL2MPBase::FallInit( void )
{
#ifndef CLIENT_DLL
@ -262,7 +287,7 @@ void CWeaponHL2MPBase::FallInit( void )
SetPickupTouch();
SetThink( &CBaseCombatWeapon::FallThink );
SetThink( &CWeaponHL2MPBase::FallThink );
SetNextThink( gpGlobals->curtime + 0.1f );

View file

@ -45,6 +45,7 @@ public:
void Materialize( void );
virtual int ObjectCaps( void );
virtual void FallThink( void );
#endif
// All predicted weapons need to implement and return true