Skip to content

Commit daa4a5d

Browse files
committed
Fix items in MP conflicting with some SP behavior (mapbase-source#464)
1 parent f0e5afa commit daa4a5d

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/game/server/ai_basenpc.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10472,6 +10472,17 @@ CBaseEntity *CAI_BaseNPC::DropItem ( const char *pszItemName, Vector vecPos, QAn
1047210472
pItem->ApplyLocalAngularVelocityImpulse( AngularImpulse( 0, random->RandomFloat( 0, 100 ), 0 ) );
1047310473
}
1047410474

10475+
// Fixes health vials, grenades, etc. respawning
10476+
if (pItem->IsCombatItem())
10477+
{
10478+
pItem->AddSpawnFlags(SF_NORESPAWN);
10479+
}
10480+
else if (pItem->IsBaseCombatWeapon())
10481+
{
10482+
// Adding SF_NORESPAWN directly to weapons causes them to be considered level-placed, which we don't want
10483+
pItem->MyCombatWeaponPointer()->Drop(vec3_origin);
10484+
}
10485+
1047510486
return pItem;
1047610487
}
1047710488
else

src/game/server/item_world.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ void CItem::ActivateWhenAtRest( float flTime /* = 0.5f */ )
240240
{
241241
RemoveSolidFlags( FSOLID_TRIGGER );
242242
m_bActivateWhenAtRest = true;
243-
SetThink( &CItem::ComeToRest );
244-
SetNextThink( gpGlobals->curtime + flTime );
243+
// HL2 entities (e.g. item_item_crate) often use ActivateWhenAtRest() before spawn, which is overridden by FallThink() in MP
244+
SetContextThink(&CItem::ComeToRest, gpGlobals->curtime + flTime, "ComeToRestThink");
245245
}
246246

247247

@@ -258,8 +258,7 @@ void CItem::OnEntityEvent( EntityEvent_t event, void *pEventData )
258258
{
259259
// Delay rest for a sec, to avoid changing collision
260260
// properties inside a collision callback.
261-
SetThink( &CItem::ComeToRest );
262-
SetNextThink( gpGlobals->curtime + 0.1f );
261+
SetContextThink(&CItem::ComeToRest, gpGlobals->curtime + 0.1f, "ComeToRestThink");
263262
}
264263
break;
265264
}
@@ -275,7 +274,7 @@ void CItem::ComeToRest( void )
275274
{
276275
m_bActivateWhenAtRest = false;
277276
AddSolidFlags( FSOLID_TRIGGER );
278-
SetThink( NULL );
277+
SetContextThink(NULL, TICK_NEVER_THINK, "ComeToRestThink");
279278
}
280279
}
281280

0 commit comments

Comments
 (0)