Skip to content

Commit bc2c317

Browse files
wopox1337In-line
authored andcommitted
Spawn protection API and cvar (mp_respawn_immunitytime). (#266)
1 parent cbbda5e commit bc2c317

File tree

12 files changed

+87
-2
lines changed

12 files changed

+87
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Archive's bin directory contains 2 subdirectories, 'bugfixed' and 'pure'
4949
| bot_quota_mode | normal | - | - | Determines the type of quota.<br/>`normal` default behaviour<br/>`fill` the server will adjust bots to keep `N` players in the game, where `N` is bot_quota |
5050
| mp_item_staytime | 300 | - | - | Time to remove item that have been dropped from the players. |
5151
| mp_legacy_bombtarget_touch | 1 | 0 | 1 | Legacy func_bomb_target touch. New one is more strict. <br/>`0` New behavior<br/>`1` Legacy behavior|
52+
| mp_respawn_immunitytime | 0 | 0 | - | Specifies the players defense time after respawn. (in seconds).<br/>`0` disabled<br/>`>0.00001` time delay to remove protection |
5253

5354
## How to install zBot for CS 1.6?
5455
* Extract all the files from an [archive](regamedll/extra/zBot/bot_profiles.zip?raw=true)

dist/game.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,10 @@ mp_item_staytime 300
186186
//
187187
// Default value: "1"
188188
mp_legacy_bombtarget_touch "1"
189+
190+
// Specifies the players defense time after respawn. (in seconds).
191+
// 0 - disabled
192+
// >0.00001 - time delay to remove protection
193+
//
194+
// Default value: "0"
195+
mp_respawn_immunitytime "0"

regamedll/dlls/API/CAPI_Impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ GAMEHOOK_REGISTRY(ThrowHeGrenade);
157157
GAMEHOOK_REGISTRY(ThrowFlashbang);
158158
GAMEHOOK_REGISTRY(ThrowSmokeGrenade);
159159
GAMEHOOK_REGISTRY(PlantBomb);
160+
GAMEHOOK_REGISTRY(CBasePlayer_SetSpawnProtection);
161+
GAMEHOOK_REGISTRY(CBasePlayer_RemoveSpawnProtection);
160162

161163
int CReGameApi::GetMajorVersion() {
162164
return REGAMEDLL_API_VERSION_MAJOR;

regamedll/dlls/API/CAPI_Impl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ typedef IHookChainRegistryImpl<CGrenade *, entvars_t *, Vector &, Vector &, floa
521521
typedef IHookChainImpl<CGrenade *, entvars_t *, Vector &, Vector &> CReGameHook_PlantBomb;
522522
typedef IHookChainRegistryImpl<CGrenade *, entvars_t *, Vector &, Vector &> CReGameHookRegistry_PlantBomb;
523523

524+
// CBasePlayer::SetSpawnProtection hook
525+
typedef IHookChainClassImpl<void, CBasePlayer, float> CReGameHook_CBasePlayer_SetSpawnProtection;
526+
typedef IHookChainRegistryClassImpl<void, CBasePlayer, float> CReGameHookRegistry_CBasePlayer_SetSpawnProtection;
527+
528+
// CBasePlayer::RemoveSpawnProtection hook
529+
typedef IHookChainImpl<void, CBasePlayer> CReGameHook_CBasePlayer_RemoveSpawnProtection;
530+
typedef IHookChainRegistryClassImpl<void, CBasePlayer> CReGameHookRegistry_CBasePlayer_RemoveSpawnProtection;
531+
524532
class CReGameHookchains: public IReGameHookchains {
525533
public:
526534
// CBasePlayer virtual
@@ -625,6 +633,8 @@ class CReGameHookchains: public IReGameHookchains {
625633
CReGameHookRegistry_ThrowFlashbang m_ThrowFlashbang;
626634
CReGameHookRegistry_ThrowSmokeGrenade m_ThrowSmokeGrenade;
627635
CReGameHookRegistry_PlantBomb m_PlantBomb;
636+
CReGameHookRegistry_CBasePlayer_SetSpawnProtection m_CBasePlayer_SetSpawnProtection;
637+
CReGameHookRegistry_CBasePlayer_RemoveSpawnProtection m_CBasePlayer_RemoveSpawnProtection;
628638
public:
629639
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
630640
virtual IReGameHookRegistry_CBasePlayer_Precache *CBasePlayer_Precache();
@@ -727,6 +737,8 @@ class CReGameHookchains: public IReGameHookchains {
727737
virtual IReGameHookRegistry_ThrowFlashbang *ThrowFlashbang();
728738
virtual IReGameHookRegistry_ThrowSmokeGrenade *ThrowSmokeGrenade();
729739
virtual IReGameHookRegistry_PlantBomb *PlantBomb();
740+
virtual IReGameHookRegistry_CBasePlayer_SetSpawnProtection *CBasePlayer_SetSpawnProtection();
741+
virtual IReGameHookRegistry_CBasePlayer_RemoveSpawnProtection *CBasePlayer_RemoveSpawnProtection();
730742
};
731743

732744
extern CReGameHookchains g_ReGameHookchains;

regamedll/dlls/API/CSPlayer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,13 @@ EXT_FUNC void CCSPlayer::StartDeathCam()
489489
{
490490
BasePlayer()->StartDeathCam();
491491
}
492+
493+
EXT_FUNC void CCSPlayer::SetSpawnProtection(float flProtectionTime)
494+
{
495+
BasePlayer()->SetSpawnProtection(flProtectionTime);
496+
}
497+
498+
EXT_FUNC void CCSPlayer::RemoveSpawnProtection()
499+
{
500+
BasePlayer()->RemoveSpawnProtection();
501+
}

regamedll/dlls/game.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ cvar_t show_radioicon = { "mp_show_radioicon", "1", FCVAR_SERVER, 1.0f,
116116
cvar_t old_bomb_defused_sound = { "mp_old_bomb_defused_sound", "1", FCVAR_SERVER, 1.0f, nullptr };
117117
cvar_t item_staytime = { "mp_item_staytime", "300", FCVAR_SERVER, 300.0f, nullptr };
118118
cvar_t legacy_bombtarget_touch = { "mp_legacy_bombtarget_touch", "1", FCVAR_SERVER, 1.0f, nullptr };
119+
cvar_t respawn_immunitytime = { "mp_respawn_immunitytime", "0", FCVAR_SERVER, 0.0f, nullptr };
119120

120121
void GameDLL_Version_f()
121122
{
@@ -270,6 +271,7 @@ void EXT_FUNC GameDLLInit()
270271
CVAR_REGISTER(&old_bomb_defused_sound);
271272
CVAR_REGISTER(&item_staytime);
272273
CVAR_REGISTER(&legacy_bombtarget_touch);
274+
CVAR_REGISTER(&respawn_immunitytime);
273275

274276
// print version
275277
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

regamedll/dlls/game.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ extern cvar_t show_radioicon;
153153
extern cvar_t old_bomb_defused_sound;
154154
extern cvar_t item_staytime;
155155
extern cvar_t legacy_bombtarget_touch;
156+
extern cvar_t respawn_immunitytime;
156157

157158
#endif
158159

regamedll/dlls/multiplay_gamerules.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,6 +3635,11 @@ void EXT_FUNC CHalfLifeMultiplay::__API_HOOK(PlayerSpawn)(CBasePlayer *pPlayer)
36353635
pPlayer->pev->weapons |= (1 << WEAPON_SUIT);
36363636
pPlayer->OnSpawnEquip();
36373637
pPlayer->SetPlayerModel(false);
3638+
3639+
#ifdef REGAMEDLL_ADD
3640+
if (respawn_immunitytime.value > 0)
3641+
pPlayer->SetSpawnProtection(respawn_immunitytime.value);
3642+
#endif
36383643
}
36393644

36403645
LINK_HOOK_CLASS_CUSTOM_CHAIN(BOOL, CHalfLifeMultiplay, CSGameRules, FPlayerCanRespawn, (CBasePlayer *pPlayer), pPlayer)

regamedll/dlls/player.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4376,6 +4376,13 @@ void EXT_FUNC CBasePlayer::__API_HOOK(PreThink)()
43764376
}
43774377

43784378
UpdateLocation();
4379+
4380+
#ifdef REGAMEDLL_ADD
4381+
if (CSPlayer()->m_flSpawnProtectionEndTime > 0 && gpGlobals->time > CSPlayer()->m_flSpawnProtectionEndTime)
4382+
{
4383+
RemoveSpawnProtection();
4384+
}
4385+
#endif
43794386
}
43804387

43814388
// If player is taking time based damage, continue doing damage to player -
@@ -9516,3 +9523,24 @@ bool CBasePlayer::__API_HOOK(CanSwitchTeam)(TeamName teamToSwap)
95169523

95179524
return true;
95189525
}
9526+
9527+
LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayer, SetSpawnProtection, (float flProtectionTime), flProtectionTime)
9528+
9529+
void EXT_FUNC CBasePlayer::__API_HOOK(SetSpawnProtection)(float flProtectionTime)
9530+
{
9531+
pev->takedamage = DAMAGE_NO;
9532+
pev->rendermode = kRenderTransAdd;
9533+
pev->renderamt = 100.0;
9534+
9535+
CSPlayer()->m_flSpawnProtectionEndTime = gpGlobals->time + flProtectionTime;
9536+
}
9537+
9538+
LINK_HOOK_CLASS_VOID_CHAIN2(CBasePlayer, RemoveSpawnProtection)
9539+
9540+
void CBasePlayer::__API_HOOK(RemoveSpawnProtection)()
9541+
{
9542+
pev->takedamage = DAMAGE_AIM;
9543+
pev->rendermode = kRenderNormal;
9544+
9545+
CSPlayer()->m_flSpawnProtectionEndTime = 0.0f;
9546+
}

regamedll/dlls/player.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,6 @@ class CBasePlayer: public CBaseMonster {
343343
virtual BOOL AddPlayerItem(CBasePlayerItem *pItem);
344344
virtual BOOL RemovePlayerItem(CBasePlayerItem *pItem);
345345
virtual int GiveAmmo(int iAmount, const char *szName, int iMax = -1);
346-
347346
#ifndef REGAMEDLL_API
348347
virtual void StartSneaking() { m_tSneaking = gpGlobals->time - 1; }
349348
virtual void StopSneaking() { m_tSneaking = gpGlobals->time + 30; }
@@ -420,6 +419,8 @@ class CBasePlayer: public CBaseMonster {
420419
CGrenade *ThrowGrenade_OrigFunc(CBasePlayerWeapon *pWeapon, VectorRef vecSrc, VectorRef vecThrow, float time, unsigned short usEvent = 0);
421420
void SwitchTeam_OrigFunc();
422421
bool CanSwitchTeam_OrigFunc(TeamName teamToSwap);
422+
void SetSpawnProtection_OrigFunc(float flProtectionTime);
423+
void RemoveSpawnProtection_OrigFunc();
423424

424425
CCSPlayer *CSPlayer() const;
425426
#endif // REGAMEDLL_API
@@ -609,6 +610,9 @@ class CBasePlayer: public CBaseMonster {
609610
CBasePlayerItem *GetItemByName(const char *itemName);
610611
CBasePlayerItem *GetItemById(WeaponIdType weaponID);
611612

613+
void SetSpawnProtection(float flProtectionTime);
614+
void RemoveSpawnProtection();
615+
612616
// templates
613617
template<typename T = CBasePlayerItem, typename Functor>
614618
T *ForEachItem(int slot, const Functor &func) const

0 commit comments

Comments
 (0)