Skip to content

Commit a202425

Browse files
authored
Fix: ammo/weapons respawn behavior (#982)
* `CBasePlayerAmmo`: check spawnflags on `Spawn()` * `CBasePlayerItem`: check spawnflags on `Materialize()` * `CBasePlayerItem`: Add `Respawn()` item when hasn't specific spawnflags * `CBasePlayerItem`: remove `SF_NORESPAWN` flag on `Respawn()` * Use forgotten `AMMO_RESPAWN_TIME`
1 parent 576e967 commit a202425

3 files changed

Lines changed: 20 additions & 4 deletions

File tree

regamedll/dlls/ammo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ void CBasePlayerAmmo::Spawn()
1010

1111
SetTouch(&CBasePlayerAmmo::DefaultTouch);
1212

13-
if (g_pGameRules->IsMultiplayer())
13+
if (g_pGameRules->IsMultiplayer()
14+
#ifdef REGAMEDLL_FIXES
15+
&& g_pGameRules->AmmoShouldRespawn(this) == GR_AMMO_RESPAWN_NO
16+
#endif
17+
)
1418
{
1519
SetThink(&CBaseEntity::SUB_Remove);
1620
pev->nextthink = gpGlobals->time + 2.0f;

regamedll/dlls/multiplay_gamerules.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4321,7 +4321,7 @@ int CHalfLifeMultiplay::AmmoShouldRespawn(CBasePlayerAmmo *pAmmo)
43214321

43224322
float CHalfLifeMultiplay::FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo)
43234323
{
4324-
return gpGlobals->time + 20.0f;
4324+
return gpGlobals->time + AMMO_RESPAWN_TIME;
43254325
}
43264326

43274327
Vector CHalfLifeMultiplay::VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo)

regamedll/dlls/weapons.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,11 @@ void CBasePlayerItem::Materialize()
518518
UTIL_SetOrigin(pev, pev->origin);
519519
SetTouch(&CBasePlayerItem::DefaultTouch);
520520

521-
if (g_pGameRules->IsMultiplayer())
521+
if (g_pGameRules->IsMultiplayer()
522+
#ifdef REGAMEDLL_FIXES
523+
&& g_pGameRules->WeaponShouldRespawn(this) == GR_WEAPON_RESPAWN_NO
524+
#endif
525+
)
522526
{
523527
if (!CanDrop())
524528
{
@@ -555,8 +559,12 @@ void CBasePlayerItem::CheckRespawn()
555559
{
556560
switch (g_pGameRules->WeaponShouldRespawn(this))
557561
{
558-
case GR_WEAPON_RESPAWN_YES:
562+
case GR_WEAPON_RESPAWN_YES: {
563+
#ifdef REGAMEDLL_FIXES
564+
Respawn();
565+
#endif
559566
return;
567+
}
560568
case GR_WEAPON_RESPAWN_NO:
561569
return;
562570
}
@@ -575,6 +583,10 @@ CBaseEntity *CBasePlayerItem::Respawn()
575583
// invisible for now
576584
pNewWeapon->pev->effects |= EF_NODRAW;
577585

586+
#ifdef REGAMEDLL_ADD
587+
pNewWeapon->pev->spawnflags &= ~SF_NORESPAWN;
588+
#endif
589+
578590
// no touch
579591
pNewWeapon->SetTouch(nullptr);
580592
pNewWeapon->SetThink(&CBasePlayerItem::AttemptToMaterialize);

0 commit comments

Comments
 (0)