Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from marqdevx/marqdevx/damage-print
Browse files Browse the repository at this point in the history
Add damage print
  • Loading branch information
marqdevx authored Apr 22, 2024
2 parents 467a0b5 + 4966c4e commit 72636d0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 11 deletions.
5 changes: 3 additions & 2 deletions CFGs/cs2scrim/cs2scrim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ cs2scrim_restore 1 //.restore
cs2scrim_rcon 1 //.rcon
cs2scrim_pause 1 //.pause .unpause
cs2scrim_practice_spawn 1 //.spawn
cs2scrim_admin_ban 1 //.ban
cs2scrim_admin_ban 1 //.ban .unban
cs2scrim_admin_kick 1 //.kick
cs2scrim_admin_gag 1 //.gag
cs2scrim_admin_gag 1 //.gag .ungag
cs2scrim_admin_slay 1 //.slay
cs2scrim_admin_teleport 1 //.goto
cs2scrim_admin_team 1 //.setteam
cs2scrim_damage_print 1 // none
93 changes: 84 additions & 9 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,40 @@ bool swapped_teams = false;
extern bool g_bEnablePractice;
extern bool g_bEnableCoach;

int g_DamageDone[MAXPLAYERS+1][MAXPLAYERS+1];
int g_DamageDoneHits[MAXPLAYERS+1][MAXPLAYERS+1];
bool damagePrint_shown = false;

bool g_bEnableDamagePrint = true;
FAKE_BOOL_CVAR(cs2scrim_damage_print, "Whether to enable chat Damage Print", g_bEnableDamagePrint, true, false)

void PrintDamageInfo(int client) {
CCSPlayerController* pController = CCSPlayerController::FromSlot(client);

if(!pController)
return;

int team = pController->m_iTeamNum();
if (team != CS_TEAM_T && team != CS_TEAM_CT)
return;

int otherTeam = (team == CS_TEAM_T) ? CS_TEAM_CT : CS_TEAM_T;

for (int i = 1; i <= gpGlobals->maxClients; i++) {
CCSPlayerController* pTarget = CCSPlayerController::FromSlot(i);

if(!pTarget)
continue;

if (pTarget->m_iTeamNum() == otherTeam) {
int targetHealth = pTarget->GetPawn()->m_iHealth();
if (targetHealth < 0) targetHealth = 0;

ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "(%i dmg / %i hits) to (%i dmg / %i hits) from %s (%i)", g_DamageDone[client][i], g_DamageDoneHits[client][i], g_DamageDone[i][client], g_DamageDoneHits[i][client], pTarget->GetPlayerName(), targetHealth);
}
}
}

void RegisterEventListeners()
{
static bool bRegistered = false;
Expand Down Expand Up @@ -155,6 +189,15 @@ GAME_EVENT_F(round_prestart)

GAME_EVENT_F(round_start)
{
if (g_bEnableDamagePrint && damagePrint_shown){
for (int i = 1; i <= gpGlobals->maxClients; i++) {
for (int j = 1; j <= gpGlobals->maxClients; j++) {
g_DamageDone[i][j] = 0;
g_DamageDoneHits[i][j] = 0;
}
}
}

if (coaches.Count() < 1) return;

FOR_EACH_VEC(coaches,i){
Expand Down Expand Up @@ -219,19 +262,35 @@ GAME_EVENT_F(round_freeze_end)
}

GAME_EVENT_F(player_hurt){
if(!practiceMode || !g_bEnablePractice) return;

CCSPlayerController* pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("attacker") + 1));

if (!pController)
return;
CCSPlayerController* pVictim = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("userid") + 1));
CCSPlayerController* pAttacker = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("attacker") + 1));

if(!pVictim || !pAttacker) return;

CCSPlayerController* pHurt = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pEvent->GetUint64("userid") + 1));
//ClientPrintAll(HUD_PRINTTALK, "Smoke end %i", pEvent->GetUint64("entityid"));
int damage = pEvent->GetFloat("dmg_health");
int actualHealth = pEvent->GetFloat("health");
ClientPrint(pController, HUD_PRINTTALK, CHAT_PREFIX "Damage done \04%d \01to \04%s\1[\04%d\01]", damage , pHurt->GetPlayerName(), actualHealth);
int postDamageHealth = pEvent->GetFloat("health");
int preDamageHealth = pVictim->GetPawn()->m_iHealth();

if(g_bEnableDamagePrint && !practiceMode){
int attacker = pEvent->GetFloat("attacker");
int victim = pEvent->GetFloat("userid");

// this maxes the damage variables at 100,
// so doing 50 damage when the player had 2 health
// only counts as 2 damage.
if (postDamageHealth == 0) {
damage += preDamageHealth;
}

g_DamageDone[attacker][victim] += damage;
g_DamageDoneHits[attacker][victim]++;
return;
}

if(!practiceMode || !g_bEnablePractice) return;

ClientPrint(pAttacker, HUD_PRINTTALK, CHAT_PREFIX "Damage done \04%d \01to \04%s\1[\04%d\01]", damage , pVictim->GetPlayerName(), postDamageHealth);
}

GAME_EVENT_F(player_blind){
Expand Down Expand Up @@ -281,4 +340,20 @@ GAME_EVENT_F(grenade_thrown){
ZEPlayer *pPlayer = g_playerManager->GetPlayer(pController->GetPlayerSlot());
pPlayer->lastThrow_position = currentPos;
pPlayer->lastThrow_rotation = currentAngle;
}

GAME_EVENT_F(round_end){
if(!g_bEnableDamagePrint || practiceMode)
return;

for (int i = 1; i <= gpGlobals->maxClients; i++) {
CCSPlayerController* pController = CCSPlayerController::FromSlot(i);

if(!pController)
continue;

PrintDamageInfo(i);
}

damagePrint_shown = true;
}

0 comments on commit 72636d0

Please sign in to comment.