Skip to content

Commit 4bb0ac1

Browse files
s1lentqyohimik
authored andcommitted
Add an extended player's DeathMsg message (rehlds#858)
* Implemented rarity of kill and assist for extended user message DeathMsg * Add hookchain CGameRules::SendDeathMessage * Add domination and revenge
1 parent 31b28ca commit 4bb0ac1

22 files changed

+809
-145
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
110110
| mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. |
111111
| mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. |
112112
| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.<br/>`0` New behavior <br/>`1` Legacy behavior |
113-
| mp_dying_time | 3.0 | 0.0 | - | Time for switch to free observing after death.<br/>`0` - disable spectating around death.<br/>`>0.00001` - time delay to start spectate.<br/>`NOTE`: The countdown starts when the player’s death animation is finished.|
113+
| mp_dying_time | 3.0 | 0.0 | - | Time for switch to free observing after death.<br/>`0` - disable spectating around death.<br/>`>0.00001` - time delay to start spectate.<br/>`NOTE`: The countdown starts when the player’s death animation is finished. |
114+
| mp_deathmsg_flags | 7 | 0 | 7 | Sets a bitsum for extra information in the player's death message.<br/>`0` disabled<br/>`1` position where the victim died<br/>`2` index of the assistant who helped the attacker kill the victim<br/>`4` rarity classification bits, e.g., `blinkill`, `noscope`, `penetrated`, etc. |
115+
| mp_assist_damage_threshold | 40 | 0 | 100 | Sets the percentage of damage needed to score an assist. |
114116
</details>
115117

116118
## How to install zBot for CS 1.6?

dist/game.cfg

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,19 @@ mp_legacy_vehicle_block "1"
537537
//
538538
// Default value: "3.0"
539539
mp_dying_time "3.0"
540+
541+
// Sets a bitsum for extra information in the player's death message
542+
//
543+
// 1 Position where the victim died
544+
// 2 Index of the assistant who helped the attacker kill the victim
545+
// 4 Rarity classification bits, e.g., blinkill, noscope, penetrated, etc
546+
//
547+
// Set to "0" to send no extra information about death
548+
//
549+
// Default value: "7"
550+
mp_deathmsg_flags "7"
551+
552+
// Sets the percentage of damage needed to score an assist
553+
//
554+
// Default value: "40"
555+
mp_assist_damage_threshold "40"

regamedll/dlls/API/CAPI_Impl.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,37 @@ void EXT_FUNC AddMultiDamage_api(entvars_t *pevInflictor, CBaseEntity *pEntity,
6161
AddMultiDamage(pevInflictor, pEntity, flDamage, bitsDamageType);
6262
}
6363

64-
int EXT_FUNC Cmd_Argc_api()
64+
int EXT_FUNC Cmd_Argc_api()
6565
{
6666
return CMD_ARGC_();
6767
}
6868

69-
const char *EXT_FUNC Cmd_Argv_api(int i)
69+
const char *EXT_FUNC Cmd_Argv_api(int i)
7070
{
7171
return CMD_ARGV_(i);
7272
}
7373

74-
CGrenade *EXT_FUNC PlantBomb_api(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity)
74+
CGrenade *EXT_FUNC PlantBomb_api(entvars_t *pevOwner, Vector &vecStart, Vector &vecVelocity)
7575
{
7676
return CGrenade::ShootSatchelCharge(pevOwner, vecStart, vecVelocity);
7777
}
7878

79-
CGib *EXT_FUNC SpawnHeadGib_api(entvars_t *pevVictim)
79+
CGib *EXT_FUNC SpawnHeadGib_api(entvars_t *pevVictim)
8080
{
8181
return CGib::SpawnHeadGib(pevVictim);
8282
}
8383

84-
void EXT_FUNC SpawnRandomGibs_api(entvars_t *pevVictim, int cGibs, int human)
84+
void EXT_FUNC SpawnRandomGibs_api(entvars_t *pevVictim, int cGibs, int human)
8585
{
8686
CGib::SpawnRandomGibs(pevVictim, cGibs, human);
8787
}
8888

89-
void EXT_FUNC UTIL_RestartOther_api(const char *szClassname)
89+
void EXT_FUNC UTIL_RestartOther_api(const char *szClassname)
9090
{
9191
UTIL_RestartOther(szClassname);
9292
}
9393

94-
void EXT_FUNC UTIL_ResetEntities_api()
94+
void EXT_FUNC UTIL_ResetEntities_api()
9595
{
9696
UTIL_ResetEntities();
9797
}
@@ -130,11 +130,11 @@ CGrenade *EXT_FUNC SpawnGrenade_api(WeaponIdType weaponId, entvars_t *pevOwner,
130130
{
131131
switch (weaponId)
132132
{
133-
case WEAPON_HEGRENADE:
133+
case WEAPON_HEGRENADE:
134134
return CGrenade::ShootTimed2(pevOwner, vecSrc, vecThrow, time, iTeam, usEvent);
135-
case WEAPON_FLASHBANG:
135+
case WEAPON_FLASHBANG:
136136
return CGrenade::ShootTimed(pevOwner, vecSrc, vecThrow, time);
137-
case WEAPON_SMOKEGRENADE:
137+
case WEAPON_SMOKEGRENADE:
138138
return CGrenade::ShootSmokeGrenade(pevOwner, vecSrc, vecThrow, time, usEvent);
139139
case WEAPON_C4:
140140
return CGrenade::ShootSatchelCharge(pevOwner, vecSrc, vecThrow);
@@ -331,6 +331,7 @@ GAMEHOOK_REGISTRY(CBasePlayer_EntSelectSpawnPoint);
331331
GAMEHOOK_REGISTRY(CBasePlayerWeapon_ItemPostFrame);
332332
GAMEHOOK_REGISTRY(CBasePlayerWeapon_KickBack);
333333
GAMEHOOK_REGISTRY(CBasePlayerWeapon_SendWeaponAnim);
334+
GAMEHOOK_REGISTRY(CSGameRules_SendDeathMessage);
334335

335336
int CReGameApi::GetMajorVersion() {
336337
return REGAMEDLL_API_VERSION_MAJOR;

regamedll/dlls/API/CAPI_Impl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,10 @@ typedef IHookChainRegistryClassEmptyImpl<BOOL, class CHalfLifeMultiplay, int, in
709709
typedef IHookChainClassImpl<void, class CHalfLifeMultiplay, CBasePlayer *, CBasePlayerItem *> CReGameHook_CSGameRules_PlayerGotWeapon;
710710
typedef IHookChainRegistryClassEmptyImpl<void, class CHalfLifeMultiplay, CBasePlayer *, CBasePlayerItem *> CReGameHookRegistry_CSGameRules_PlayerGotWeapon;
711711

712+
// CHalfLifeMultiplay::SendDeathMessage hook
713+
typedef IHookChainClassImpl<void, class CHalfLifeMultiplay, CBaseEntity *, CBasePlayer *, CBasePlayer *, entvars_t *, const char *, int, int> CReGameHook_CSGameRules_SendDeathMessage;
714+
typedef IHookChainRegistryClassEmptyImpl<void, class CHalfLifeMultiplay, CBaseEntity *, CBasePlayer *, CBasePlayer *, entvars_t *, const char *, int, int> CReGameHookRegistry_CSGameRules_SendDeathMessage;
715+
712716
// CBotManager::OnEvent hook
713717
typedef IHookChainClassImpl<void, CBotManager, GameEventType, CBaseEntity *, CBaseEntity *> CReGameHook_CBotManager_OnEvent;
714718
typedef IHookChainRegistryClassEmptyImpl<void, CBotManager, GameEventType, CBaseEntity*, CBaseEntity*> CReGameHookRegistry_CBotManager_OnEvent;
@@ -865,7 +869,7 @@ class CReGameHookchains: public IReGameHookchains {
865869
CReGameHookRegistry_CBasePlayer_Pain m_CBasePlayer_Pain;
866870
CReGameHookRegistry_CBasePlayer_DeathSound m_CBasePlayer_DeathSound;
867871
CReGameHookRegistry_CBasePlayer_JoiningThink m_CBasePlayer_JoiningThink;
868-
872+
869873
CReGameHookRegistry_FreeGameRules m_FreeGameRules;
870874
CReGameHookRegistry_PM_LadderMove m_PM_LadderMove;
871875
CReGameHookRegistry_PM_WaterJump m_PM_WaterJump;
@@ -889,6 +893,7 @@ class CReGameHookchains: public IReGameHookchains {
889893
CReGameHookRegistry_CBasePlayerWeapon_ItemPostFrame m_CBasePlayerWeapon_ItemPostFrame;
890894
CReGameHookRegistry_CBasePlayerWeapon_KickBack m_CBasePlayerWeapon_KickBack;
891895
CReGameHookRegistry_CBasePlayerWeapon_SendWeaponAnim m_CBasePlayerWeapon_SendWeaponAnim;
896+
CReGameHookRegistry_CSGameRules_SendDeathMessage m_CSGameRules_SendDeathMessage;
892897

893898
public:
894899
virtual IReGameHookRegistry_CBasePlayer_Spawn *CBasePlayer_Spawn();
@@ -1044,6 +1049,7 @@ class CReGameHookchains: public IReGameHookchains {
10441049
virtual IReGameHookRegistry_CBasePlayerWeapon_ItemPostFrame *CBasePlayerWeapon_ItemPostFrame();
10451050
virtual IReGameHookRegistry_CBasePlayerWeapon_KickBack *CBasePlayerWeapon_KickBack();
10461051
virtual IReGameHookRegistry_CBasePlayerWeapon_SendWeaponAnim *CBasePlayerWeapon_SendWeaponAnim();
1052+
virtual IReGameHookRegistry_CSGameRules_SendDeathMessage *CSGameRules_SendDeathMessage();
10471053
};
10481054

10491055
extern CReGameHookchains g_ReGameHookchains;

regamedll/dlls/API/CSPlayer.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,22 @@ void CCSPlayer::ResetVars()
550550
m_bSpawnProtectionEffects = false;
551551
}
552552

553+
// Resets all stats
554+
void CCSPlayer::ResetAllStats()
555+
{
556+
// Resets the kill history for this player
557+
for (int i = 0; i < MAX_CLIENTS; i++)
558+
{
559+
m_iNumKilledByUnanswered[i] = 0;
560+
m_bPlayerDominated[i] = false;
561+
}
562+
}
563+
553564
void CCSPlayer::OnSpawn()
554565
{
555566
m_bGameForcingRespawn = false;
556567
m_flRespawnPending = 0.0f;
568+
m_DamageList.Clear();
557569
}
558570

559571
void CCSPlayer::OnKilled()
@@ -571,3 +583,33 @@ void CCSPlayer::OnKilled()
571583
}
572584
#endif
573585
}
586+
587+
void CCSPlayer::OnConnect()
588+
{
589+
ResetVars();
590+
m_iUserID = GETPLAYERUSERID(BasePlayer()->edict());
591+
}
592+
593+
// Remember this amount of damage that we dealt for stats
594+
void CCSPlayer::RecordDamage(CBasePlayer *pAttacker, float flDamage, float flFlashDurationTime)
595+
{
596+
if (!pAttacker || !pAttacker->IsPlayer())
597+
return;
598+
599+
int attackerIndex = pAttacker->entindex() - 1;
600+
if (attackerIndex < 0 || attackerIndex >= MAX_CLIENTS)
601+
return;
602+
603+
CCSPlayer *pCSAttacker = pAttacker->CSPlayer();
604+
605+
// Accumulate damage
606+
CDamageRecord_t &record = m_DamageList[attackerIndex];
607+
if (record.flDamage > 0 && record.userId != pCSAttacker->m_iUserID)
608+
record.flDamage = 0; // reset damage if attacker became another client
609+
610+
record.flDamage += flDamage;
611+
record.userId = pCSAttacker->m_iUserID;
612+
613+
if (flFlashDurationTime > 0)
614+
record.flFlashDurationTime = gpGlobals->time + flFlashDurationTime;
615+
}

regamedll/dlls/cbase.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ bool EXT_FUNC IsPenetrableEntity_default(Vector &vecSrc, Vector &vecEnd, entvars
12421242

12431243

12441244
LINK_HOOK_CLASS_CHAIN(VectorRef, CBaseEntity, FireBullets3, (VectorRef vecSrc, VectorRef vecDirShooting, float vecSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand), vecSrc, vecDirShooting, vecSpread, flDistance, iPenetration, iBulletType, iDamage, flRangeModifier, pevAttacker, bPistol, shared_rand)
1245-
1245+
12461246
// Go to the trouble of combining multiple pellets into a single damage call.
12471247
// This version is used by Players, uses the random seed generator to sync client and server side shots.
12481248
VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecDirShooting, float vecSpread, float flDistance, int iPenetration, int iBulletType, int iDamage, float flRangeModifier, entvars_t *pevAttacker, bool bPistol, int shared_rand)
@@ -1340,6 +1340,7 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD
13401340

13411341
float flDamageModifier = 0.5;
13421342

1343+
int iStartPenetration = iPenetration;
13431344
while (iPenetration != 0)
13441345
{
13451346
ClearMultiDamage();
@@ -1400,9 +1401,11 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD
14001401
default:
14011402
break;
14021403
}
1404+
14031405
if (tr.flFraction != 1.0f)
14041406
{
14051407
CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
1408+
int iPenetrationCur = iPenetration;
14061409
iPenetration--;
14071410

14081411
flCurrentDistance = tr.flFraction * flDistance;
@@ -1459,6 +1462,7 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD
14591462
flDistance = (flDistance - flCurrentDistance) * flDistanceModifier;
14601463
vecEnd = vecSrc + (vecDir * flDistance);
14611464

1465+
pEntity->SetDmgPenetrationLevel(iStartPenetration - iPenetrationCur);
14621466
pEntity->TraceAttack(pevAttacker, iCurrentDamage, vecDir, &tr, (DMG_BULLET | DMG_NEVERGIB));
14631467
iCurrentDamage *= flDamageModifier;
14641468
}

regamedll/dlls/cbase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ class CBaseEntity {
242242
void SetBlocked(void (T::*pfn)(CBaseEntity *pOther));
243243
void SetBlocked(std::nullptr_t);
244244

245+
void SetDmgPenetrationLevel(int iPenetrationLevel);
246+
void ResetDmgPenetrationLevel();
247+
int GetDmgPenetrationLevel() const;
248+
245249
#ifdef REGAMEDLL_API
246250
CCSEntity *m_pEntity;
247251
CCSEntity *CSEntity() const;

regamedll/dlls/client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
730730
}
731731

732732
#ifdef REGAMEDLL_API
733-
pPlayer->CSPlayer()->ResetVars();
733+
pPlayer->CSPlayer()->OnConnect();
734734
#endif
735735

736736
UTIL_ClientPrintAll(HUD_PRINTNOTIFY, "#Game_connected", (sName[0] != '\0') ? sName : "<unconnected>");

regamedll/dlls/combat.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
1616
}
1717
}
1818

19-
pPlayer->Blind(fadeTime * 0.33, fadeHold, fadeTime, alpha);
19+
float flDurationTime = fadeTime * 0.33;
20+
pPlayer->Blind(flDurationTime, fadeHold, fadeTime, alpha);
2021

2122
if (TheBots)
2223
{
2324
TheBots->OnEvent(EVENT_PLAYER_BLINDED_BY_FLASHBANG, pPlayer);
2425
}
26+
27+
#if defined(REGAMEDLL_API) && defined(REGAMEDLL_ADD)
28+
float flAdjustedDamage;
29+
if (alpha > 200)
30+
flAdjustedDamage = fadeTime / 3;
31+
else
32+
flAdjustedDamage = fadeTime / 1.75;
33+
34+
pPlayer->CSPlayer()->RecordDamage(CBasePlayer::Instance(pevAttacker), flAdjustedDamage * 16.0f, flDurationTime);
35+
#endif
2536
}
2637

2738
void RadiusFlash_TraceLine_hook(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, Vector &vecSrc, Vector &vecSpot, TraceResult *tr)
@@ -101,7 +112,7 @@ void RadiusFlash(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker,
101112
if (pPlayer->pev == pevAttacker || g_pGameRules->PlayerRelationship(pPlayer, CBaseEntity::Instance(pevAttacker)) == GR_TEAMMATE)
102113
continue;
103114
break;
104-
}
115+
}
105116
#endif
106117
if (tr.fStartSolid)
107118
{
@@ -110,7 +121,6 @@ void RadiusFlash(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker,
110121
}
111122

112123
flAdjustedDamage = flDamage - (vecSrc - tr.vecEndPos).Length() * falloff;
113-
114124
if (flAdjustedDamage < 0)
115125
flAdjustedDamage = 0;
116126

@@ -303,6 +313,8 @@ void RadiusDamage(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker
303313

304314
if (tr.flFraction != 1.0f)
305315
flAdjustedDamage = 0.0f;
316+
else
317+
pEntity->SetDmgPenetrationLevel(1);
306318
}
307319
#endif
308320
}

regamedll/dlls/game.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ cvar_t sv_autobunnyhopping = { "sv_autobunnyhopping", "0", 0, 0.0f
166166
cvar_t sv_enablebunnyhopping = { "sv_enablebunnyhopping", "0", 0, 0.0f, nullptr };
167167
cvar_t plant_c4_anywhere = { "mp_plant_c4_anywhere", "0", 0, 0.0f, nullptr };
168168
cvar_t give_c4_frags = { "mp_give_c4_frags", "3", 0, 3.0f, nullptr };
169+
cvar_t deathmsg_flags = { "mp_deathmsg_flags", "7", 0, 7.0f, nullptr };
170+
cvar_t assist_damage_threshold = { "mp_assist_damage_threshold", "40", 0, 40.0f, nullptr };
169171

170172
cvar_t hostages_rescued_ratio = { "mp_hostages_rescued_ratio", "1.0", 0, 1.0f, nullptr };
171173

@@ -423,6 +425,8 @@ void EXT_FUNC GameDLLInit()
423425
CVAR_REGISTER(&legacy_vehicle_block);
424426

425427
CVAR_REGISTER(&dying_time);
428+
CVAR_REGISTER(&deathmsg_flags);
429+
CVAR_REGISTER(&assist_damage_threshold);
426430

427431
// print version
428432
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");

0 commit comments

Comments
 (0)