From 1fad10e933c59974ba5da778e42eef0c498b1231 Mon Sep 17 00:00:00 2001 From: marqdevx Date: Tue, 16 Apr 2024 11:36:40 +0200 Subject: [PATCH 1/4] Add damage print Original https://github.com/splewis/sm-misc/blob/master/scripting/csgo_damageprint.sp --- src/events.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 9 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index f4078a4c..8f02f1a4 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -44,6 +44,39 @@ 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 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; @@ -155,6 +188,15 @@ GAME_EVENT_F(round_prestart) GAME_EVENT_F(round_start) { + if(g_bEnableDamagePrint){ + 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){ @@ -219,19 +261,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){ @@ -281,4 +339,18 @@ 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) + return; + + for (int i = 1; i <= gpGlobals->maxClients; i++) { + CCSPlayerController* pController = CCSPlayerController::FromSlot(i); + + if(!pController) + continue; + + PrintDamageInfo(i); + } } \ No newline at end of file From dd987edf0b684032de211f4d4098c1880e428326 Mon Sep 17 00:00:00 2001 From: marqdevx Date: Wed, 17 Apr 2024 08:59:01 +0200 Subject: [PATCH 2/4] Add damage print cvar --- CFGs/cs2scrim/cs2scrim.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/CFGs/cs2scrim/cs2scrim.cfg b/CFGs/cs2scrim/cs2scrim.cfg index f6e39be5..b09b669b 100644 --- a/CFGs/cs2scrim/cs2scrim.cfg +++ b/CFGs/cs2scrim/cs2scrim.cfg @@ -17,3 +17,4 @@ cs2scrim_admin_gag 1 //.gag cs2scrim_admin_slay 1 //.slay cs2scrim_admin_teleport 1 //.goto cs2scrim_admin_team 1 //.setteam +cs2scrim_damage_print 1 // none \ No newline at end of file From dad96fd73325962f032b4c7deb22b6d33f480d9d Mon Sep 17 00:00:00 2001 From: marqdevx Date: Wed, 17 Apr 2024 08:59:19 +0200 Subject: [PATCH 3/4] Update comments --- CFGs/cs2scrim/cs2scrim.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CFGs/cs2scrim/cs2scrim.cfg b/CFGs/cs2scrim/cs2scrim.cfg index b09b669b..6b579d30 100644 --- a/CFGs/cs2scrim/cs2scrim.cfg +++ b/CFGs/cs2scrim/cs2scrim.cfg @@ -11,9 +11,9 @@ 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 From 4966c4e1991c3310e7cb6f5d3e2404717389a737 Mon Sep 17 00:00:00 2001 From: marqdevx Date: Wed, 17 Apr 2024 09:28:27 +0200 Subject: [PATCH 4/4] Only damage print in scrim mode --- src/events.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/events.cpp b/src/events.cpp index 8f02f1a4..e3ae1abe 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -46,6 +46,7 @@ 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) @@ -188,7 +189,7 @@ GAME_EVENT_F(round_prestart) GAME_EVENT_F(round_start) { - if(g_bEnableDamagePrint){ + 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; @@ -342,7 +343,7 @@ GAME_EVENT_F(grenade_thrown){ } GAME_EVENT_F(round_end){ - if(!g_bEnableDamagePrint) + if(!g_bEnableDamagePrint || practiceMode) return; for (int i = 1; i <= gpGlobals->maxClients; i++) { @@ -353,4 +354,6 @@ GAME_EVENT_F(round_end){ PrintDamageInfo(i); } + + damagePrint_shown = true; } \ No newline at end of file