-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdamagelog3.sp
424 lines (369 loc) · 11.2 KB
/
damagelog3.sp
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <cnf_core>
#pragma newdecls required
#pragma semicolon 1
#define SAVEROUNDS 3
// @TODO: group menuhandlers
// @TODO: generalize player menu logic
int damageTaken[SAVEROUNDS][MAXPLAYERS+1][MAXPLAYERS+1];
int killedBy[SAVEROUNDS][MAXPLAYERS+1];
char playerNames[MAXPLAYERS+1][MAX_NAME_LENGTH];
int currentround = 0;
int targetChosen[MAXPLAYERS+1];
public void OnPluginStart()
{
LoadTranslations("common.phrases");
RegisterCommands();
HookEvents();
playerNames[0] = "World";
for (int iRound = 0; iRound < SAVEROUNDS; iRound++)
{
for (int client = 1; client <= MAXPLAYERS; client++)
{
killedBy[iRound][client] = -1;
}
}
}
public void RegisterCommands()
{
RegAdminCmd("sm_damagelog", Command_LogDamage, ADMFLAG_SLAY);
RegAdminCmd("sm_dl", Command_LogDamage, ADMFLAG_SLAY);
RegAdminCmd("sm_hurtlog", Command_LogDamage, ADMFLAG_SLAY);
RegAdminCmd("sm_hl", Command_LogDamage, ADMFLAG_SLAY);
RegAdminCmd("sm_killlog", Command_KillLog, ADMFLAG_SLAY);
RegAdminCmd("sm_kl", Command_KillLog, ADMFLAG_SLAY);
RegAdminCmd("sm_deathlog", Command_DeathLog, ADMFLAG_SLAY);
}
public void HookEvents()
{
HookEvent("player_hurt", Event_PlayerHurt);
HookEvent("player_spawn", Event_PlayerSpawn);
HookEvent("player_death", Event_PlayerDeath);
HookEvent("round_end", Event_RoundEnd);
}
public Action Command_LogDamage(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, " \x07[SM]\x01 Usage: !damagelog\x03 <player/@all/@ct/@t>");
return Plugin_Handled;
}
char arg1[32];
GetCmdArg(1, arg1, 32);
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS]; int target_count; bool tn_is_ml;
target_count = Core_ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_CONNECTED, target_name, sizeof(target_name), tn_is_ml);
if (target_count < 1)
{
ReplyToCommand(client, " \x07[SM]\x01 No matching client was found.");
return Plugin_Handled;
}
if (target_count == 1)
{
targetChosen[client] = target_list[0];
ShowRoundMenu(client, MenuHandler_DamageShow);
return Plugin_Handled;
}
Menu menu = CreateMenu(MenuHandler_DamageNameChoice);
menu.SetTitle("What player did you mean?");
for (int i = 0; i < target_count; i++)
{
char name[32]; char targetid[3];
GetClientName(target_list[i], name, sizeof(name));
IntToString(target_list[i], targetid, sizeof(targetid));
menu.AddItem(targetid, name);
}
menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Action Command_DeathLog(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, " \x07[SM]\x01 Usage: !deathlog\x03 <player/@all/@ct/@t>");
return Plugin_Handled;
}
char arg1[32];
GetCmdArg(1, arg1, 32);
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS]; int target_count; bool tn_is_ml;
target_count = Core_ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_CONNECTED, target_name, sizeof(target_name), tn_is_ml);
if (target_count < 1)
{
ReplyToCommand(client, " \x07[SM]\x01 No matching client was found.");
return Plugin_Handled;
}
if (target_count == 1)
{
targetChosen[client] = target_list[0];
ShowRoundMenu(client, MenuHandler_DeathShow);
return Plugin_Handled;
}
Menu menu = CreateMenu(MenuHandler_DeathNameChoice);
menu.SetTitle("What player did you mean?");
for (int i = 0; i < target_count; i++)
{
char name[32]; char targetid[3];
GetClientName(target_list[i], name, sizeof(name));
IntToString(target_list[i], targetid, sizeof(targetid));
menu.AddItem(targetid, name);
}
menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Action Command_KillLog(int client, int args)
{
if (args < 1)
{
ReplyToCommand(client, " \x07[SM]\x01 Usage: !killlog\x03 <player/@all/@ct/@t>");
return Plugin_Handled;
}
char arg1[32];
GetCmdArg(1, arg1, 32);
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS]; int target_count; bool tn_is_ml;
target_count = ProcessTargetString(arg1, client, target_list, MAXPLAYERS, COMMAND_FILTER_CONNECTED, target_name, sizeof(target_name), tn_is_ml);
if (target_count < 1)
{
if (StrEqual(arg1, "world", false))
{
targetChosen[client] = 0;
ShowRoundMenu(client, MenuHandler_KillShow);
}
else ReplyToCommand(client, " \x07[SM]\x01 No matching client was found.");
return Plugin_Handled;
}
if (target_count == 1)
{
targetChosen[client] = target_list[0];
ShowRoundMenu(client, MenuHandler_KillShow);
return Plugin_Handled;
}
Menu menu = CreateMenu(MenuHandler_KillNameChoice);
menu.SetTitle("What player did you mean?");
// @TODO: replace below logic with AddTargetsToMenu
for (int i = 0; i < target_count; i++)
{
char name[32]; char targetid[3];
GetClientName(target_list[i], name, sizeof(name));
IntToString(target_list[i], targetid, sizeof(targetid));
menu.AddItem(targetid, name);
}
menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
int victimId = GetClientOfUserId(event.GetInt("userid"));
int attackerId = GetClientOfUserId(event.GetInt("attacker"));
killedBy[currentround][victimId] = attackerId;
return Plugin_Continue;
}
public Action Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
{
int victimId = GetClientOfUserId(event.GetInt("userid"));
int attackerId = GetClientOfUserId(event.GetInt("attacker"));
int damage = event.GetInt("dmg_health");
damageTaken[currentround][victimId][attackerId] += damage;
return Plugin_Continue;
}
public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
GetClientName(client, playerNames[client], MAX_NAME_LENGTH);
for (int i = 0; i <= MaxClients; i++)
{
damageTaken[currentround][client][i] = 0;
}
killedBy[currentround][client] = -1;
}
public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
currentround = (currentround + 1) % SAVEROUNDS;
return Plugin_Continue;
}
public int MenuHandler_KillNameChoice(Menu menu, MenuAction action, int param1, int param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
targetChosen[param1] = StringToInt(info);
ShowRoundMenu(param1, MenuHandler_KillShow);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack)
{
ShowRoundMenu(param1, MenuHandler_KillShow);
}
}
stock void ShowKillMenu(int client, int round)
{
Menu menu = CreateMenu(MenuHandler_KillNameChoice);
menu.SetTitle("%N killed", targetChosen[client]);
int count;
for (int j = 1; j <= MaxClients; j++)
{
if (IsClientInGame(j) && killedBy[round][j] == targetChosen[client]) {
char name[32];
GetClientName(j, name, sizeof(name));
menu.AddItem("", name, ITEMDRAW_DISABLED);
count++;
}
}
if (count == 0) menu.AddItem("", "DIDN'T KILL", ITEMDRAW_DISABLED);
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
public int MenuHandler_DamageNameChoice(Menu menu, MenuAction action, int param1, int param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
targetChosen[param1] = StringToInt(info);
ShowRoundMenu(param1, MenuHandler_DamageShow);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack)
{
ShowRoundMenu(param1, MenuHandler_DamageShow);
}
}
stock void ShowDamageMenu(int client, int round)
{
Menu menu = CreateMenu(MenuHandler_DamageNameChoice);
menu.SetTitle("%N damaged by", targetChosen[client]);
int count;
for (int i = 0; i <= MaxClients; i++)
{
if (damageTaken[round][targetChosen[client]][i] != 0)
{
char damagelog[40];
Format(damagelog, sizeof(damagelog), "%s - %d", playerNames[i], damageTaken[round][targetChosen[client]][i]);
menu.AddItem("", damagelog, ITEMDRAW_DISABLED);
count++;
}
}
if (count == 0) menu.AddItem("", "NOT DAMAGED", ITEMDRAW_DISABLED);
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}
int GetPreviousRound(int round)
{
int newround = round - 1;
if (newround < 0) newround = SAVEROUNDS-1;
return newround;
}
stock void ShowRoundMenu(int client, MenuHandler handler)
{
Menu menu = CreateMenu(handler);
menu.SetTitle("What round?");
char round[3];
IntToString(currentround, round, sizeof(round));
menu.AddItem(round, "Current round");
int previousround = currentround;
int roundsAgo;
char display[18];
while((previousround = GetPreviousRound(previousround)) != currentround)
{
Format(display, sizeof(display), "%d round(s) ago", ++roundsAgo);
IntToString(previousround, round, sizeof(round));
menu.AddItem(round, display);
}
menu.Display(client, MENU_TIME_FOREVER);
}
public int MenuHandler_DamageShow(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
int round = StringToInt(info);
ShowDamageMenu(param1, round);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
}
public int MenuHandler_KillShow(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
int round = StringToInt(info);
ShowKillMenu(param1, round);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
}
public int MenuHandler_DeathNameChoice(Menu menu, MenuAction action, int param1, int param2)
{
/* If an option was selected, tell the client about the item. */
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
targetChosen[param1] = StringToInt(info);
ShowRoundMenu(param1, MenuHandler_DeathShow);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
else if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack)
{
ShowRoundMenu(param1, MenuHandler_DeathShow);
}
}
public int MenuHandler_DeathShow(Menu menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
char info[3];
menu.GetItem(param2, info, sizeof(info));
int round = StringToInt(info);
ShowDeathMenu(param1, round);
}
/* If the menu has ended, destroy it */
else if (action == MenuAction_End)
{
delete menu;
}
}
stock void ShowDeathMenu(int client, int round)
{
Menu menu = CreateMenu(MenuHandler_DeathNameChoice);
menu.SetTitle("%N killed by", targetChosen[client]);
if (killedBy[round][targetChosen[client]] < 0)
{
menu.AddItem("", "DIDN'T DIE", ITEMDRAW_DISABLED);
}
else
{
char deathlog[40];
Format(deathlog, sizeof(deathlog), "%s - %d", playerNames[killedBy[round][targetChosen[client]]], damageTaken[round][targetChosen[client]][killedBy[round][targetChosen[client]]]);
menu.AddItem("", deathlog, ITEMDRAW_DISABLED);
}
menu.ExitBackButton = true;
menu.Display(client, MENU_TIME_FOREVER);
}