-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathround_damage.sp
More file actions
229 lines (191 loc) · 6.14 KB
/
Copy pathround_damage.sp
File metadata and controls
229 lines (191 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1
#pragma newdecls required
#define MAX_PLAYERS 65
#define PLUGIN_VERSION "1.2.0"
// Global variables for tracking damage
int g_DamageGiven[MAX_PLAYERS][MAX_PLAYERS];
int g_HitsGiven[MAX_PLAYERS][MAX_PLAYERS];
int g_KilledBy[MAX_PLAYERS]; // Stores the attacker ID who killed the victim (index)
// ConVars
ConVar g_cvEnabled;
public Plugin myinfo =
{
name = "Round End Damage Report",
author = "RATING3PRO",
description = "Displays damage statistics at the end of each round.",
version = PLUGIN_VERSION
};
public void OnPluginStart()
{
// Register ConVars
g_cvEnabled = CreateConVar("sm_dmgreport_enabled", "1", "Enable damage report plugin");
// Auto generate config file
AutoExecConfig(true, "plugin.round_damage_report");
// Hook events
HookEvent("round_start", Event_RoundStart);
HookEvent("player_hurt", Event_PlayerHurt);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("round_end", Event_RoundEnd);
}
public void OnClientDisconnect(int client)
{
ClearClientData(client);
}
public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
ClearAllData();
return Plugin_Continue;
}
public Action Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
if (!g_cvEnabled.BoolValue)
{
return Plugin_Continue;
}
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
int damage = event.GetInt("dmg_health");
// Check validity and ensure we don't track self-damage or world damage for this report
if (IsValidClient(victim) && IsValidClient(attacker) && victim != attacker)
{
g_DamageGiven[attacker][victim] += damage;
g_HitsGiven[attacker][victim]++;
}
return Plugin_Continue;
}
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int victim = GetClientOfUserId(event.GetInt("userid"));
int attacker = GetClientOfUserId(event.GetInt("attacker"));
if (IsValidClient(victim))
{
if (IsValidClient(attacker) && victim != attacker)
{
g_KilledBy[victim] = attacker;
}
else
{
g_KilledBy[victim] = 0; // Suicide or world
}
}
return Plugin_Continue;
}
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
if (!g_cvEnabled.BoolValue)
{
return Plugin_Continue;
}
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i))
{
ShowDamageReport(i);
}
}
return Plugin_Continue;
}
void ShowDamageReport(int client)
{
int clientTeam = GetClientTeam(client);
// Only show for T or CT (Spectators don't need this report usually)
if (clientTeam != CS_TEAM_T && clientTeam != CS_TEAM_CT)
{
return;
}
bool headerPrinted = false;
for (int i = 1; i <= MaxClients; i++)
{
// Skip self and invalid clients
if (i == client || !IsClientInGame(i))
{
continue;
}
int otherTeam = GetClientTeam(i);
// Only show enemies (Opposite team)
if (otherTeam == clientTeam || (otherTeam != CS_TEAM_T && otherTeam != CS_TEAM_CT))
{
continue;
}
int dmgGiven = g_DamageGiven[client][i];
int hitsGiven = g_HitsGiven[client][i];
int dmgTaken = g_DamageGiven[i][client];
int hitsTaken = g_HitsGiven[i][client];
if (!headerPrinted)
{
PrintToChat(client, " \x04[回合伤害统计] \x01----------------------------");
headerPrinted = true;
}
// Check if the enemy was killed by the client
// We don't have direct kill tracking here, so we'll infer or need to add it.
// Actually, to color the NAME red if killed by client, we need to track kills.
// Let's add kill tracking.
char nameColor[4] = "\x01"; // Default White
if (g_KilledBy[i] == client)
{
Format(nameColor, sizeof(nameColor), "\x02"); // Red if killed by client
}
char enemyName[MAX_NAME_LENGTH];
GetClientName(i, enemyName, sizeof(enemyName));
// Determine Health Status
char healthStatus[32];
if (IsPlayerAlive(i))
{
// Alive: Show HP in Green
Format(healthStatus, sizeof(healthStatus), "\x04%d HP", GetClientHealth(i));
}
else
{
// Dead: Show DEAD in Red
Format(healthStatus, sizeof(healthStatus), "\x02DEAD");
}
// Format:
// Name (Color depends on kill) [Health] :: Hits: X (Y dmg) (Green) :: Taken: A (B dmg) (Red)
// Using \x08 (Grey) for separators
char buffer[256];
Format(buffer, sizeof(buffer), " %s%s \x01[%s\x01] \x08:: \x06攻: %d \x01(\x06%d hp\x01) \x08:: \x02受: %d \x01(\x02%d hp\x01)",
nameColor, enemyName, healthStatus, hitsGiven, dmgGiven, hitsTaken, dmgTaken);
PrintToChat(client, buffer);
}
if (headerPrinted)
{
PrintToChat(client, " \x01-----------------------------------------------");
}
}
void ClearAllData()
{
for (int i = 0; i < MAX_PLAYERS; i++)
{
g_KilledBy[i] = 0;
for (int j = 0; j < MAX_PLAYERS; j++)
{
g_DamageGiven[i][j] = 0;
g_HitsGiven[i][j] = 0;
}
}
}
void ClearClientData(int client)
{
if (client > 0 && client < MAX_PLAYERS)
{
g_KilledBy[client] = 0;
for (int i = 0; i < MAX_PLAYERS; i++)
{
g_DamageGiven[client][i] = 0;
g_HitsGiven[client][i] = 0;
g_DamageGiven[i][client] = 0;
g_HitsGiven[i][client] = 0;
if (g_KilledBy[i] == client)
{
g_KilledBy[i] = 0; // Reset if the killer disconnected? Optional but cleaner
}
}
}
}
bool IsValidClient(int client)
{
return (client > 0 && client <= MaxClients && IsClientInGame(client));
}