Skip to content

Commit 6507f41

Browse files
Feature: ConVars for weapon/item/ammo respawn time (#13)
* Fix: `ammo`/`weapons` respawn behavior (rehlds#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` * Feature: ConVars for `weapon`/`item`/`ammo` respawn time (rehlds#983) * `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` * new ConVars: `mp_item_respawn_time`, `mp_weapon_respawn_time`, `mp_ammo_respawn_time` --------- Co-authored-by: Sergey Shorokhov <wopox1337@ya.ru>
1 parent cbffd9d commit 6507f41

7 files changed

Lines changed: 65 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
117117
| mp_freezetime_jump | 1 | 0 | 1 | Allow players to jump during freezetime.<br/> `0` disabled<br/>`1` enabled |
118118
| mp_defuser_allocation | 0 | 0 | 2 | Give defuser on player spawn.<br/> `0` disabled<br/>`1` Random players. <br/>`2` All players. |
119119
| mp_location_area_info | 0 | 0 | 3 | Enable location area info.<br/> `0` disabled<br/>`1` show location below HUD radar.<br/>`2` show location in HUD chat. `NOT RECOMMENDED!` [:speech_balloon:](## "Not all client builds are compatible")<br/>`3` both displayed. `NOT RECOMMENDED!` [:speech_balloon:](## "Not all client builds are compatible")<br/><br/>`NOTE`: Navigation `maps/.nav` file required and should contain place names<br/>`NOTE`: If option `2` or `3` is enabled, be sure to enable `mp_chat_loc_fallback 1` |
120+
| mp_item_respawn_time | 30 | 0.0 | - | The respawn time for items (such as health packs, armor, etc.). |
121+
| mp_weapon_respawn_time | 20 | 0.0 | - | The respawn time for weapons. |
122+
| mp_ammo_respawn_time | 20 | 0.0 | - | The respawn time for ammunition. |
120123
| mp_scoreboard_fix | 0 | 0 | 1 | Enable ReGameDLL scoreboard bug fix(Dead players could see the bomb or defuse kit).<br/> `0` disabled<br/>`1` enabled<br/>`NOTE`: Absolutely cannot fix it in "CNCS😂" |
121124
</details>
122125

dist/game.cfg

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,24 @@ mp_defuser_allocation "0"
589589
// Default value: "0"
590590
mp_location_area_info "0"
591591
592+
// The respawn time for items (such as health packs, armor, etc.).
593+
// 0 - disable delay
594+
//
595+
// Default value: "30"
596+
mp_item_respawn_time "30"
597+
598+
// The respawn time for weapons.
599+
// 0 - disable delay
600+
//
601+
// Default value: "20"
602+
mp_weapon_respawn_time "20"
603+
604+
// The respawn time for ammunition.
605+
// 0 - disable delay
606+
//
607+
// Default value: "20"
608+
mp_ammo_respawn_time "20"
609+
592610
// Enable ReGameDLL scoreboard bug fix(Dead players could see the bomb or defuse kit)
593611
// 0 - disable
594612
// 1 - enabled

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/game.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ cvar_t defuser_allocation = { "mp_defuser_allocation", "0", 0, 0.0f, nullpt
181181
cvar_t location_area_info = { "mp_location_area_info", "0", 0, 0.0f, nullptr };
182182
cvar_t chat_loc_fallback = { "mp_chat_loc_fallback", "1", 1, 0.0f, nullptr };
183183

184+
cvar_t item_respawn_time = { "mp_item_respawn_time", "30", FCVAR_SERVER, 30.0f, nullptr };
185+
cvar_t weapon_respawn_time = { "mp_weapon_respawn_time", "20", FCVAR_SERVER, 20.0f, nullptr };
186+
cvar_t ammo_respawn_time = { "mp_ammo_respawn_time", "20", FCVAR_SERVER, 20.0f, nullptr };
187+
184188
cvar_t scoreboard_fix = { "mp_scoreboard_fix", "0", FCVAR_SERVER, 0.0f, nullptr };
185189

186190
void GameDLL_Version_f()
@@ -448,6 +452,10 @@ void EXT_FUNC GameDLLInit()
448452
CVAR_REGISTER(&location_area_info);
449453
CVAR_REGISTER(&chat_loc_fallback);
450454

455+
CVAR_REGISTER(&item_respawn_time);
456+
CVAR_REGISTER(&weapon_respawn_time);
457+
CVAR_REGISTER(&ammo_respawn_time);
458+
451459
CVAR_REGISTER(&scoreboard_fix);
452460

453461
// print version

regamedll/dlls/game.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ extern cvar_t defuser_allocation;
204204
extern cvar_t location_area_info;
205205
extern cvar_t chat_loc_fallback;
206206

207+
extern cvar_t item_respawn_time;
208+
extern cvar_t weapon_respawn_time;
209+
extern cvar_t ammo_respawn_time;
210+
207211
extern cvar_t scoreboard_fix;
208212

209213
#endif

regamedll/dlls/multiplay_gamerules.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4221,7 +4221,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerGotWeapon)(CBasePlayer *pPlay
42214221
// What is the time in the future at which this weapon may spawn?
42224222
float CHalfLifeMultiplay::FlWeaponRespawnTime(CBasePlayerItem *pWeapon)
42234223
{
4224+
#ifdef REGAMEDLL_ADD
4225+
return gpGlobals->time + weapon_respawn_time.value;
4226+
#else
42244227
return gpGlobals->time + WEAPON_RESPAWN_TIME;
4228+
#endif
42254229
}
42264230

42274231
// Returns 0 if the weapon can respawn now,
@@ -4289,7 +4293,11 @@ int CHalfLifeMultiplay::ItemShouldRespawn(CItem *pItem)
42894293
// At what time in the future may this Item respawn?
42904294
float CHalfLifeMultiplay::FlItemRespawnTime(CItem *pItem)
42914295
{
4296+
#ifdef REGAMEDLL_ADD;
4297+
return gpGlobals->time + item_respawn_time.value;
4298+
#else
42924299
return gpGlobals->time + ITEM_RESPAWN_TIME;
4300+
#endif
42934301
}
42944302

42954303
// Where should this item respawn?
@@ -4321,7 +4329,11 @@ int CHalfLifeMultiplay::AmmoShouldRespawn(CBasePlayerAmmo *pAmmo)
43214329

43224330
float CHalfLifeMultiplay::FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo)
43234331
{
4324-
return gpGlobals->time + 20.0f;
4332+
#ifdef REGAMEDLL_ADD
4333+
return gpGlobals->time + ammo_respawn_time.value;
4334+
#else
4335+
return gpGlobals->time + AMMO_RESPAWN_TIME;
4336+
#endif
43254337
}
43264338

43274339
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)