Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: ConVars for weapon/item/ammo respawn time #13

Merged
merged 3 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_freezetime_jump | 1 | 0 | 1 | Allow players to jump during freezetime.<br/> `0` disabled<br/>`1` enabled |
| mp_defuser_allocation | 0 | 0 | 2 | Give defuser on player spawn.<br/> `0` disabled<br/>`1` Random players. <br/>`2` All players. |
| 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` |
| mp_item_respawn_time | 30 | 0.0 | - | The respawn time for items (such as health packs, armor, etc.). |
| mp_weapon_respawn_time | 20 | 0.0 | - | The respawn time for weapons. |
| mp_ammo_respawn_time | 20 | 0.0 | - | The respawn time for ammunition. |
| 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😂" |
</details>

Expand Down
18 changes: 18 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,24 @@ mp_defuser_allocation "0"
// Default value: "0"
mp_location_area_info "0"

// The respawn time for items (such as health packs, armor, etc.).
// 0 - disable delay
//
// Default value: "30"
mp_item_respawn_time "30"

// The respawn time for weapons.
// 0 - disable delay
//
// Default value: "20"
mp_weapon_respawn_time "20"

// The respawn time for ammunition.
// 0 - disable delay
//
// Default value: "20"
mp_ammo_respawn_time "20"

// Enable ReGameDLL scoreboard bug fix(Dead players could see the bomb or defuse kit)
// 0 - disable
// 1 - enabled
Expand Down
6 changes: 5 additions & 1 deletion regamedll/dlls/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ void CBasePlayerAmmo::Spawn()

SetTouch(&CBasePlayerAmmo::DefaultTouch);

if (g_pGameRules->IsMultiplayer())
if (g_pGameRules->IsMultiplayer()
#ifdef REGAMEDLL_FIXES
&& g_pGameRules->AmmoShouldRespawn(this) == GR_AMMO_RESPAWN_NO
#endif
)
{
SetThink(&CBaseEntity::SUB_Remove);
pev->nextthink = gpGlobals->time + 2.0f;
Expand Down
8 changes: 8 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ cvar_t defuser_allocation = { "mp_defuser_allocation", "0", 0, 0.0f, nullpt
cvar_t location_area_info = { "mp_location_area_info", "0", 0, 0.0f, nullptr };
cvar_t chat_loc_fallback = { "mp_chat_loc_fallback", "1", 1, 0.0f, nullptr };

cvar_t item_respawn_time = { "mp_item_respawn_time", "30", FCVAR_SERVER, 30.0f, nullptr };
cvar_t weapon_respawn_time = { "mp_weapon_respawn_time", "20", FCVAR_SERVER, 20.0f, nullptr };
cvar_t ammo_respawn_time = { "mp_ammo_respawn_time", "20", FCVAR_SERVER, 20.0f, nullptr };

cvar_t scoreboard_fix = { "mp_scoreboard_fix", "0", FCVAR_SERVER, 0.0f, nullptr };

void GameDLL_Version_f()
Expand Down Expand Up @@ -448,6 +452,10 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&location_area_info);
CVAR_REGISTER(&chat_loc_fallback);

CVAR_REGISTER(&item_respawn_time);
CVAR_REGISTER(&weapon_respawn_time);
CVAR_REGISTER(&ammo_respawn_time);

CVAR_REGISTER(&scoreboard_fix);

// print version
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ extern cvar_t defuser_allocation;
extern cvar_t location_area_info;
extern cvar_t chat_loc_fallback;

extern cvar_t item_respawn_time;
extern cvar_t weapon_respawn_time;
extern cvar_t ammo_respawn_time;

extern cvar_t scoreboard_fix;

#endif
Expand Down
14 changes: 13 additions & 1 deletion regamedll/dlls/multiplay_gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4221,7 +4221,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerGotWeapon)(CBasePlayer *pPlay
// What is the time in the future at which this weapon may spawn?
float CHalfLifeMultiplay::FlWeaponRespawnTime(CBasePlayerItem *pWeapon)
{
#ifdef REGAMEDLL_ADD
return gpGlobals->time + weapon_respawn_time.value;
#else
return gpGlobals->time + WEAPON_RESPAWN_TIME;
#endif
}

// Returns 0 if the weapon can respawn now,
Expand Down Expand Up @@ -4289,7 +4293,11 @@ int CHalfLifeMultiplay::ItemShouldRespawn(CItem *pItem)
// At what time in the future may this Item respawn?
float CHalfLifeMultiplay::FlItemRespawnTime(CItem *pItem)
{
#ifdef REGAMEDLL_ADD;
return gpGlobals->time + item_respawn_time.value;
#else
return gpGlobals->time + ITEM_RESPAWN_TIME;
#endif
}

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

float CHalfLifeMultiplay::FlAmmoRespawnTime(CBasePlayerAmmo *pAmmo)
{
return gpGlobals->time + 20.0f;
#ifdef REGAMEDLL_ADD
return gpGlobals->time + ammo_respawn_time.value;
#else
return gpGlobals->time + AMMO_RESPAWN_TIME;
#endif
}

Vector CHalfLifeMultiplay::VecAmmoRespawnSpot(CBasePlayerAmmo *pAmmo)
Expand Down
16 changes: 14 additions & 2 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ void CBasePlayerItem::Materialize()
UTIL_SetOrigin(pev, pev->origin);
SetTouch(&CBasePlayerItem::DefaultTouch);

if (g_pGameRules->IsMultiplayer())
if (g_pGameRules->IsMultiplayer()
#ifdef REGAMEDLL_FIXES
&& g_pGameRules->WeaponShouldRespawn(this) == GR_WEAPON_RESPAWN_NO
#endif
)
{
if (!CanDrop())
{
Expand Down Expand Up @@ -555,8 +559,12 @@ void CBasePlayerItem::CheckRespawn()
{
switch (g_pGameRules->WeaponShouldRespawn(this))
{
case GR_WEAPON_RESPAWN_YES:
case GR_WEAPON_RESPAWN_YES: {
#ifdef REGAMEDLL_FIXES
Respawn();
#endif
return;
}
case GR_WEAPON_RESPAWN_NO:
return;
}
Expand All @@ -575,6 +583,10 @@ CBaseEntity *CBasePlayerItem::Respawn()
// invisible for now
pNewWeapon->pev->effects |= EF_NODRAW;

#ifdef REGAMEDLL_ADD
pNewWeapon->pev->spawnflags &= ~SF_NORESPAWN;
#endif

// no touch
pNewWeapon->SetTouch(nullptr);
pNewWeapon->SetThink(&CBasePlayerItem::AttemptToMaterialize);
Expand Down