Skip to content

Commit

Permalink
add top defender message on round end
Browse files Browse the repository at this point in the history
  • Loading branch information
Poggicek authored and xen-000 committed Oct 18, 2023
1 parent 0365b43 commit 57b502f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "entity/cbaseplayercontroller.h"

#include "tier0/memdbgon.h"
#include "playermanager.h"

extern IGameEventManager2 *g_gameEventManager;
extern IServerGameClients *g_pSource2GameClients;
Expand Down Expand Up @@ -88,6 +89,7 @@ CON_COMMAND_F(c_toggle_team_messages, "toggle team messages", FCVAR_SPONLY | FCV
{
g_bBlockTeamMessages = !g_bBlockTeamMessages;
}

GAME_EVENT_F(player_team)
{
// Remove chat message for team changes
Expand Down Expand Up @@ -123,3 +125,66 @@ GAME_EVENT_F(player_spawn)
pPawn->CollisionRulesChanged();
});
}

GAME_EVENT_F(player_hurt)
{
CBasePlayerController* pController = (CBasePlayerController*)pEvent->GetPlayerController("attacker");

if (!pController)
return;

ZEPlayer* pPlayer = g_playerManager->GetPlayer(pController->GetPlayerSlot());

if (!pPlayer)
return;

pPlayer->SetTotalDamage(pPlayer->GetTotalDamage() + pEvent->GetInt("dmg_health"));
}

GAME_EVENT_F(round_start)
{
for (int i = 0; i < MAXPLAYERS; i++)
{
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);

if (!pPlayer)
continue;

pPlayer->SetTotalDamage(0);
}
}

int SortPlayerDamage(ZEPlayer* const* a, ZEPlayer* const* b)
{
return (*a)->GetTotalDamage() < (*b)->GetTotalDamage();
}

GAME_EVENT_F(round_end)
{
CUtlVector<ZEPlayer*> sortedPlayers;

for (int i = 0; i < MAXPLAYERS; i++)
{
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);

if (!pPlayer)
continue;

sortedPlayers.AddToTail(pPlayer);
}

sortedPlayers.Sort(SortPlayerDamage);

ClientPrintAll(HUD_PRINTTALK, " \x09TOP DEFENDERS");

char colorMap[] = { '\x10', '\x08', '\x09', '\x0B'};

for (int i = 0; i < MIN(sortedPlayers.Count(), 5); i++)
{
ZEPlayer* pPlayer = sortedPlayers[i];
CCSPlayerController* pController = (CCSPlayerController*)g_pEntitySystem->GetBaseEntity(CEntityIndex(pPlayer->GetPlayerSlot().Get() + 1));

ClientPrintAll(HUD_PRINTTALK, " %c%i. %s \x01- \x07%i DMG", colorMap[MIN(i, 3)], i + 1, pController->GetPlayerName(), pPlayer->GetTotalDamage());
pPlayer->SetTotalDamage(0);
}
}
6 changes: 5 additions & 1 deletion src/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ZEPlayer
m_bMuted = false;
m_iHideDistance = 0;
m_bConnected = false;
m_iTotalDamage = 0;
}

bool IsFakeClient() { return m_bFakeClient; }
Expand All @@ -69,16 +70,18 @@ class ZEPlayer
void SetTransmit(int index, bool shouldTransmit) { shouldTransmit ? m_shouldTransmit.Set(index) : m_shouldTransmit.Clear(index); }
void ClearTransmit() { m_shouldTransmit.ClearAll(); }
void SetHideDistance(int distance) { m_iHideDistance = distance; }

void ToggleStopSound() { m_bStopSound = !m_bStopSound; }
void ToggleStopDecals() { m_bStopDecals = !m_bStopDecals; }
void SetTotalDamage(int damage) { m_iTotalDamage = damage; }

bool IsUsingStopSound() { return m_bStopSound; }
bool IsUsingStopDecals() { return m_bStopDecals; }
bool IsMuted() { return m_bMuted; }
bool IsGagged() { return m_bGagged; }
bool ShouldBlockTransmit(int index) { return m_shouldTransmit.Get(index); }
int GetHideDistance() { return m_iHideDistance; }
CPlayerSlot GetPlayerSlot() { return m_slot; }
int GetTotalDamage() { return m_iTotalDamage; }

void OnAuthenticated();
void CheckAdmin();
Expand All @@ -97,6 +100,7 @@ class ZEPlayer
uint64 m_iAdminFlags;
int m_iHideDistance;
CBitVec<MAXPLAYERS> m_shouldTransmit;
int m_iTotalDamage;
};

class CPlayerManager
Expand Down

0 comments on commit 57b502f

Please sign in to comment.