Skip to content

Commit

Permalink
Implemented rarity of kill and assist for extended user message DeathMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Sep 7, 2023
1 parent ee34b06 commit 3df37bd
Show file tree
Hide file tree
Showing 16 changed files with 623 additions and 27 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_give_c4_frags | 3 | - | - | How many bonuses (frags) will get the player who defused or exploded the bomb. |
| mp_hostages_rescued_ratio | 1.0 | 0.0 | 1.0 | Ratio of hostages rescued to win the round. |
| mp_legacy_vehicle_block | 1 | 0 | 1 | Legacy func_vehicle behavior when blocked by another entity.<br/>`0` New behavior <br/>`1` Legacy behavior |
| 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.|
| 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. |
| 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. |
| mp_assist_damage_threshold | 40 | 0 | 100 | Sets the percentage of damage needed to score an assist. |
</details>

## How to install zBot for CS 1.6?
Expand Down
16 changes: 16 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,19 @@ mp_legacy_vehicle_block "1"
//
// Default value: "3.0"
mp_dying_time "3.0"
// Sets a bitsum for extra information in the player's death message
//
// 1 Position where the victim died
// 2 Index of the assistant who helped the attacker kill the victim
// 4 Rarity classification bits, e.g., blinkill, noscope, penetrated, etc
//
// Set to "0" to send no extra information about death
//
// Default value: "7"
mp_deathmsg_flags "7"

// Sets the percentage of damage needed to score an assist
//
// Default value: "40"
mp_assist_damage_threshold "40"
31 changes: 31 additions & 0 deletions regamedll/dlls/API/CSPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ void CCSPlayer::OnSpawn()
{
m_bGameForcingRespawn = false;
m_flRespawnPending = 0.0f;
m_DamageList.Clear();
}

void CCSPlayer::OnKilled()
Expand All @@ -587,3 +588,33 @@ void CCSPlayer::OnKilled()
}
#endif
}

void CCSPlayer::OnConnect()
{
ResetVars();
m_iUserID = GETPLAYERUSERID(BasePlayer()->edict());
}

// Remember this amount of damage that we dealt for stats
void CCSPlayer::RecordDamage(CBasePlayer *pAttacker, float flDamage, float flFlashDurationTime)
{
if (!pAttacker || !pAttacker->IsPlayer())
return;

int attackerIndex = pAttacker->entindex() - 1;
if (attackerIndex < 0 || attackerIndex >= MAX_CLIENTS)
return;

CCSPlayer *pCSAttacker = pAttacker->CSPlayer();

// Accumulate damage
CDamageRecord_t &record = m_DamageList[attackerIndex];
if (record.flDamage > 0 && record.userId != pCSAttacker->m_iUserID)
record.flDamage = 0; // reset damage if attacker became another client

record.flDamage += flDamage;
record.userId = pCSAttacker->m_iUserID;

if (flFlashDurationTime > 0)
record.flFlashDurationTime = gpGlobals->time + flFlashDurationTime;
}
6 changes: 5 additions & 1 deletion regamedll/dlls/cbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ bool EXT_FUNC IsPenetrableEntity_default(Vector &vecSrc, Vector &vecEnd, entvars


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)

// Go to the trouble of combining multiple pellets into a single damage call.
// This version is used by Players, uses the random seed generator to sync client and server side shots.
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)
Expand Down Expand Up @@ -1340,6 +1340,7 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD

float flDamageModifier = 0.5;

int iStartPenetration = iPenetration;
while (iPenetration != 0)
{
ClearMultiDamage();
Expand Down Expand Up @@ -1400,9 +1401,11 @@ VectorRef CBaseEntity::__API_HOOK(FireBullets3)(VectorRef vecSrc, VectorRef vecD
default:
break;
}

if (tr.flFraction != 1.0f)
{
CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
int iPenetrationCur = iPenetration;
iPenetration--;

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

pEntity->SetDmgPenetrationLevel(iStartPenetration - iPenetrationCur);
pEntity->TraceAttack(pevAttacker, iCurrentDamage, vecDir, &tr, (DMG_BULLET | DMG_NEVERGIB));
iCurrentDamage *= flDamageModifier;
}
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/cbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ class CBaseEntity {
void SetBlocked(void (T::*pfn)(CBaseEntity *pOther));
void SetBlocked(std::nullptr_t);

void SetDmgPenetrationLevel(int iPenetrationLevel);
void ResetDmgPenetrationLevel();
int GetDmgPenetrationLevel() const;

#ifdef REGAMEDLL_API
CCSEntity *m_pEntity;
CCSEntity *CSEntity() const;
Expand Down
2 changes: 1 addition & 1 deletion regamedll/dlls/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ void EXT_FUNC ClientPutInServer(edict_t *pEntity)
}

#ifdef REGAMEDLL_API
pPlayer->CSPlayer()->ResetVars();
pPlayer->CSPlayer()->OnConnect();
#endif

UTIL_ClientPrintAll(HUD_PRINTNOTIFY, "#Game_connected", (sName[0] != '\0') ? sName : "<unconnected>");
Expand Down
24 changes: 21 additions & 3 deletions regamedll/dlls/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,29 @@ void PlayerBlind(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAt
}
}

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

if (TheBots)
{
TheBots->OnEvent(EVENT_PLAYER_BLINDED_BY_FLASHBANG, pPlayer);
}

#if defined(REGAMEDLL_API) && defined(REGAMEDLL_ADD)
float flAdjustedDamage;
if (alpha > 200)
{
flAdjustedDamage = fadeTime / 3;
flAdjustedDamage = fadeHold * 1.5;
}
else
{
flAdjustedDamage = fadeTime / 1.75;
flAdjustedDamage = fadeHold * 3.5;
}

pPlayer->CSPlayer()->RecordDamage(CBasePlayer::Instance(pevAttacker), flAdjustedDamage * 16.0f, flDurationTime);
#endif
}

void RadiusFlash_TraceLine_hook(CBasePlayer *pPlayer, entvars_t *pevInflictor, entvars_t *pevAttacker, Vector &vecSrc, Vector &vecSpot, TraceResult *tr)
Expand Down Expand Up @@ -101,7 +118,7 @@ void RadiusFlash(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker,
if (pPlayer->pev == pevAttacker || g_pGameRules->PlayerRelationship(pPlayer, CBaseEntity::Instance(pevAttacker)) == GR_TEAMMATE)
continue;
break;
}
}
#endif
if (tr.fStartSolid)
{
Expand All @@ -110,7 +127,6 @@ void RadiusFlash(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker,
}

flAdjustedDamage = flDamage - (vecSrc - tr.vecEndPos).Length() * falloff;

if (flAdjustedDamage < 0)
flAdjustedDamage = 0;

Expand Down Expand Up @@ -303,6 +319,8 @@ void RadiusDamage(Vector vecSrc, entvars_t *pevInflictor, entvars_t *pevAttacker

if (tr.flFraction != 1.0f)
flAdjustedDamage = 0.0f;
else
pEntity->SetDmgPenetrationLevel(1);
}
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ cvar_t sv_autobunnyhopping = { "sv_autobunnyhopping", "0", 0, 0.0f
cvar_t sv_enablebunnyhopping = { "sv_enablebunnyhopping", "0", 0, 0.0f, nullptr };
cvar_t plant_c4_anywhere = { "mp_plant_c4_anywhere", "0", 0, 0.0f, nullptr };
cvar_t give_c4_frags = { "mp_give_c4_frags", "3", 0, 3.0f, nullptr };
cvar_t deathmsg_flags = { "mp_deathmsg_flags", "7", 0, 7.0f, nullptr };
cvar_t assist_damage_threshold = { "mp_assist_damage_threshold", "40", 0, 40.0f, nullptr };

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

Expand Down Expand Up @@ -423,6 +425,8 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&legacy_vehicle_block);

CVAR_REGISTER(&dying_time);
CVAR_REGISTER(&deathmsg_flags);
CVAR_REGISTER(&assist_damage_threshold);

// print version
CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n");
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ extern cvar_t give_c4_frags;
extern cvar_t hostages_rescued_ratio;
extern cvar_t legacy_vehicle_block;
extern cvar_t dying_time;
extern cvar_t deathmsg_flags;
extern cvar_t assist_damage_threshold;

#endif

Expand Down
32 changes: 32 additions & 0 deletions regamedll/dlls/gamerules.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,34 @@ enum
GR_NEUTRAL,
};

enum DeathMessageFlags
{
// float[3]
// Position where the victim died
PLAYERDEATH_POSITION = 0x001,

// byte
// Index of the assistant who helped the attacker kill the victim
PLAYERDEATH_ASSISTANT = 0x002,

// short
// Rarity classification bitsums
// 0x001 - Attacker was blind
// 0x002 - Attacker killed victim from sniper rifle without scope
// 0x004 - Attacker killed victim through walls
PLAYERDEATH_KILLRARITY = 0x004
};

enum KillRarity
{
KILLRARITY_HEADSHOT = 0x001, // The killer player kills the victim with a headshot
KILLRARITY_KILLER_BLIND = 0x002, // The killer player was blind
KILLRARITY_NOSCOPE = 0x004, // The killer player kills the victim with a sniper rifle with no scope
KILLRARITY_PENETRATED = 0x008, // The killer player kills the victim through walls
KILLRARITY_THROUGH_SMOKE = 0x010, // The killer player kills the victim through smoke
KILLRARITY_ASSIST_FLASH = 0x020 // The killer player kills the victim with an assistant flashbang grenade
};

class CItem;

class CGameRules
Expand Down Expand Up @@ -698,6 +726,10 @@ class CHalfLifeMultiplay: public CGameRules
VFUNC bool HasRoundTimeExpired();
VFUNC bool IsBombPlanted();

void SendDeathMessage(CBasePlayer *pAttacker, CBasePlayer *pVictim, CBasePlayer *pAssister, const char *killerWeaponName, int iDeathMessageFlags, int iRarityOfKill);
int GetRarityOfKill(CBasePlayer *pKiller, CBasePlayer *pVictim, CBasePlayer *pAssister, const char *killerWeaponName, bool bAssistWithFlashbang);
CBasePlayer *CheckAssistsToKill(CBasePlayer *pVictim, CBasePlayer *pKiller, bool &bAssistWithFlashbang);

private:
void MarkLivingPlayersOnTeamAsNotReceivingMoneyNextRound(int iTeam);

Expand Down
Loading

0 comments on commit 3df37bd

Please sign in to comment.