forked from TheDoctor0/CoDMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcod_stats.sma
More file actions
1219 lines (855 loc) · 40.2 KB
/
Copy pathcod_stats.sma
File metadata and controls
1219 lines (855 loc) · 40.2 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
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
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <amxmodx>
#include <cod>
#include <csx>
#include <sqlx>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <unixtime>
#include <nvault>
#define PLUGIN "CoD Stats"
#define VERSION "1.3.1"
#define AUTHOR "O'Zone"
#define TASK_TIME 9054
#define ADMIN_FLAG ADMIN_BAN
new const commandMenu[][] = { "menustaty", "say /statsmenu", "say_team /statsmenu", "say /statymenu", "say_team /statymenu", "say /menustaty", "say_team /menustaty" };
new const commandTime[][] = { "czas", "say /time", "say_team /time", "say /czas", "say_team /czas" };
new const commandAdminTime[][] = { "czasadmin", "say /timeadmin", "say_team /timeadmin", "say /tadmin", "say_team /tadmin", "say /czasadmin", "say_team /czasadmin", "say /cadmin", "say_team /cadmin", "say /adminczas", "say_team /adminczas" };
new const commandTopTime[][] = { "topczas", "say /ttop15", "say_team /ttop15", "say /toptime", "say_team /toptime", "say /ctop15", "say_team /ctop15", "say /topczas", "say_team /topczas" };
new const commandBestStats[][] = { "najlepszestaty", "say /staty", "say_team /staty", "say /beststats", "say_team /beststats", "say /bstats", "say_team /bstats", "say /najlepszestaty", "say_team /najlepszestaty", "say /nstaty", "say_team /nstaty" };
new const commandTopStats[][] = { "topstaty", "say /stop15", "say_team /stop15", "say /topstats", "say_team /topstats", "say /topstaty", "say_team /topstaty" };
new const commandMedals[][] = { "medale", "say /medal", "say_team /medal", "say /medale", "say_team /medale", "say /medals", "say_team /medals" };
new const commandTopMedals[][] = { "medale", "topmedale", "say /mtop15", "say_team /mtop15", "say /topmedals", "say_team /topmedals", "say /topmedale", "say_team /topmedale" };
new const commandSounds[][] = { "dzwieki", "say /dzwiek", "say_team /dzwiek", "say /dzwieki", "say_team /dzwieki", "say /sound", "say_team /sound" };
enum _:statsInfo { ADMIN, REVENGE, TIME, FIRST_VISIT, LAST_VISIT, KILLS, BRONZE, SILVER, GOLD, MEDALS, BEST_STATS, BEST_KILLS,
BEST_HS_KILLS, BEST_DEATHS, CURRENT_STATS, CURRENT_KILLS, CURRENT_HS_KILLS, CURRENT_DEATHS, ROUND_KILLS, ROUND_HS_KILLS };
enum _:winers { THIRD, SECOND, FIRST };
new playerName[MAX_PLAYERS + 1][MAX_SAFE_NAME], playerStats[MAX_PLAYERS + 1][statsInfo], playerDamage[MAX_PLAYERS + 1][MAX_PLAYERS + 1],
Handle:sql, Handle:connection, bool:sqlConnected, bool:blockCount, bool:showedOneAndOnly, bool:mapEnd, round, dataLoaded, visitInfo;
new cvarMinPlayers, cvarMedalsEnabled, cvarGoldMedalExp, cvarSilverMedalExp, cvarBronzeMedalExp, cvarAssistEnabled,
cvarAssistDamage, cvarAssistHonor, cvarAssistExp, cvarRevengeEnabled, cvarRevengeHonor, cvarRevengeExp, cvarSoundsDefault;
new soundsVault, soundMayTheForce, soundOneAndOnly, soundPrepare, soundHumiliation, soundLastLeft;
forward amxbans_admin_connect(id);
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
bind_pcvar_num(create_cvar("cod_stats_min_players", "4"), cvarMinPlayers);
bind_pcvar_num(create_cvar("cod_medals_enabled", "1"), cvarMedalsEnabled);
bind_pcvar_num(create_cvar("cod_medals_gold_exp", "500"), cvarGoldMedalExp);
bind_pcvar_num(create_cvar("cod_medals_silver_exp", "300"), cvarSilverMedalExp);
bind_pcvar_num(create_cvar("cod_medals_bronze_exp", "100"), cvarBronzeMedalExp);
bind_pcvar_num(create_cvar("cod_assist_enabled", "1"), cvarAssistEnabled);
bind_pcvar_num(create_cvar("cod_assist_damage", "65"), cvarAssistDamage);
bind_pcvar_num(create_cvar("cod_assist_honor", "1"), cvarAssistHonor);
bind_pcvar_num(create_cvar("cod_assist_exp", "15"), cvarAssistExp);
bind_pcvar_num(create_cvar("cod_revenge_enabled", "1"), cvarRevengeEnabled);
bind_pcvar_num(create_cvar("cod_revenge_honor", "1"), cvarRevengeHonor);
bind_pcvar_num(create_cvar("cod_revenge_exp", "15"), cvarRevengeExp);
bind_pcvar_num(create_cvar("cod_sounds_default", "1"), cvarSoundsDefault);
for (new i; i < sizeof commandMenu; i++) register_clcmd(commandMenu[i], "stats_menu");
for (new i; i < sizeof commandTime; i++) register_clcmd(commandTime[i], "command_time");
for (new i; i < sizeof commandAdminTime; i++) register_clcmd(commandAdminTime[i], "command_time_admin");
for (new i; i < sizeof commandTopTime; i++) register_clcmd(commandTopTime[i], "command_time_top");
for (new i; i < sizeof commandBestStats; i++) register_clcmd(commandBestStats[i], "command_best_stats");
for (new i; i < sizeof commandTopStats; i++) register_clcmd(commandTopStats[i], "command_top_stats");
for (new i; i < sizeof commandMedals; i++) register_clcmd(commandMedals[i], "command_medals");
for (new i; i < sizeof commandTopMedals; i++) register_clcmd(commandTopMedals[i], "command_top_medals");
for (new i; i < sizeof commandSounds; i++) register_clcmd(commandSounds[i], "command_sounds");
register_message(get_user_msgid("SayText"), "say_text");
soundsVault = nvault_open("cod_sound");
}
public plugin_cfg()
sql_init();
public plugin_end()
{
if (sql != Empty_Handle) SQL_FreeHandle(sql);
if (connection != Empty_Handle) SQL_FreeHandle(connection);
nvault_close(soundsVault);
}
public plugin_natives()
{
register_native("cod_stats_add_kill", "_cod_stats_add_kill", 1);
register_native("cod_get_user_time", "_cod_get_user_time", 1);
register_native("cod_get_user_time_text", "_cod_get_user_time_text", 1);
}
public client_putinserver(id)
{
for (new i = REVENGE; i <= ROUND_HS_KILLS; i++) playerStats[id][i] = 0;
rem_bit(id, dataLoaded);
rem_bit(id, visitInfo);
if (cvarSoundsDefault) {
set_bit(id, soundOneAndOnly);
set_bit(id, soundLastLeft);
set_bit(id, soundPrepare);
set_bit(id, soundMayTheForce);
set_bit(id, soundHumiliation);
} else {
rem_bit(id, soundOneAndOnly);
rem_bit(id, soundLastLeft);
rem_bit(id, soundPrepare);
rem_bit(id, soundMayTheForce);
rem_bit(id, soundHumiliation);
}
if (is_user_bot(id) || is_user_hltv(id)) return;
get_user_name(id, playerName[id], charsmax(playerName[]));
cod_sql_string(playerName[id], playerName[id], charsmax(playerName[]));
load_sounds(id);
set_task(0.1, "load_stats", id);
}
public client_disconnected(id)
{
remove_task(id);
save_stats(id, 1);
}
public cod_flags_changed(id, flags)
{
playerStats[id][ADMIN] = (flags & ADMIN_FLAG) ? 1 : 0;
save_stats(id);
}
public cod_reset_data()
clear_database();
public cod_reset_stats_data()
clear_database();
public cod_reset_all_data()
{
clear_database();
mapEnd = true;
nvault_prune(soundsVault, 0, get_systime() + 1);
}
public clear_database()
{
for (new i = 1; i <= MAX_PLAYERS; i++) rem_bit(i, dataLoaded);
sqlConnected = false;
new tempData[32];
formatex(tempData, charsmax(tempData), "DROP TABLE `cod_stats`;");
SQL_ThreadQuery(sql, "ignore_handle", tempData);
}
public stats_menu(id)
{
if (!cod_check_account(id)) return PLUGIN_HANDLED;
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new menu = menu_create("\yMenu \yStatystyk\r", "stats_menu_handle");
menu_additem(menu, "\wMoj \rCzas \y(/czas)", "1");
if (playerStats[id][ADMIN]) menu_additem(menu, "\wCzas \rAdminow \y(/adminczas)", "2");
menu_additem(menu, "\wTop \rCzasu \y(/ctop15)", "3");
menu_additem(menu, "\wNajlepsze \rStaty \y(/staty)", "4");
menu_additem(menu, "\wTop \rStatow \y(/stop15)", "5");
menu_additem(menu, "\wMoje \rMedale \y(/medale)", "6");
menu_additem(menu, "\wTop \rMedali \y(/mtop15)", "7");
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_display(id, menu);
return PLUGIN_HANDLED;
}
public stats_menu_handle(id, menu, item)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
client_cmd(id, "spk %s", codSounds[SOUND_EXIT]);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
client_cmd(id, "spk %s", codSounds[SOUND_SELECT]);
new itemData[3], itemAccess, itemCallback;
menu_item_getinfo(menu, item, itemAccess, itemData, charsmax(itemData), _, _, itemCallback);
new item = str_to_num(itemData);
switch (item) {
case 1: command_time(id);
case 2: command_time_admin(id)
case 3: command_time_top(id);
case 4: command_best_stats(id);
case 5: command_top_stats(id);
case 6: command_medals(id);
case 7: command_top_medals(id);
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public command_time(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[256], tempId[1];
tempId[0] = id;
formatex(queryData, charsmax(queryData), "SELECT rank, count FROM (SELECT COUNT(*) as count FROM `cod_stats`) a CROSS JOIN (SELECT COUNT(*) as rank FROM `cod_stats` WHERE `time` > '%i' ORDER BY `time` DESC) b",
playerStats[id][TIME] + get_user_time(id));
SQL_ThreadQuery(sql, "show_time", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_time(failState, Handle:query, error[], errorNum, tempId[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempId[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new rank, count, hours, minutes, seconds = (playerStats[id][TIME] + get_user_time(id));
rank = SQL_ReadResult(query, SQL_FieldNameToNum(query, "rank")) + 1;
count = SQL_ReadResult(query, SQL_FieldNameToNum(query, "count"));
while (seconds >= 60) {
seconds -= 60;
minutes++;
}
while (minutes >= 60) {
minutes -= 60;
hours++;
}
cod_print_chat(id, "Spedziles na serwerze lacznie^x04 %i h %i min %i s^x01.", hours, minutes, seconds);
cod_print_chat(id, "Zajmujesz^x04 %i/%i^x01 miejsce w rankingu czasu gry.", rank, count);
return PLUGIN_HANDLED;
}
public command_time_admin(id)
{
if (!is_user_connected(id) || !playerStats[id][ADMIN]) return PLUGIN_HANDLED;
new queryData[128], tempData[2];
tempData[0] = id;
tempData[1] = 1;
formatex(queryData, charsmax(queryData), "SELECT name, time FROM `cod_stats` WHERE admin = '1' ORDER BY time DESC");
SQL_ThreadQuery(sql, "show_top_time", queryData, tempData, sizeof(tempData));
return PLUGIN_HANDLED;
}
public command_time_top(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[128], tempId[2];
tempId[0] = id;
tempId[1] = 0;
formatex(queryData, charsmax(queryData), "SELECT name, time FROM `cod_stats` ORDER BY time DESC LIMIT 15");
SQL_ThreadQuery(sql, "show_top_time", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_top_time(failState, Handle:query, error[], errorNum, tempData[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempData[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
static motdData[2048], userName[64], motdLength, rank, seconds, minutes, hours;
rank = 0;
motdLength = format(motdData, charsmax(motdData), "<body bgcolor=#000000><font color=#FFB000><pre>");
motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1s %-22.22s %13s^n", "#", "Nick", "Czas Gry");
while (SQL_MoreResults(query)) {
rank++;
SQL_ReadResult(query, 0, userName, charsmax(userName));
seconds = SQL_ReadResult(query, 1);
minutes = 0;
hours = 0;
replace_all(userName, charsmax(userName), "<", "");
replace_all(userName, charsmax(userName), ">", "");
while (seconds >= 60) {
seconds -= 60;
minutes++;
}
while (minutes >= 60) {
minutes -= 60;
hours++;
}
if (rank >= 10) motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %1ih %1imin %1is^n", rank, userName, hours, minutes, seconds);
else motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %2ih %1imin %1is^n", rank, userName, hours, minutes, seconds);
SQL_NextRow(query);
}
tempData[1] ? show_motd(id, motdData, "Czas Gry Adminow") : show_motd(id, motdData, "Top15 Czasu Gry");
return PLUGIN_HANDLED;
}
public command_best_stats(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[256], tempId[1];
tempId[0] = id;
playerStats[id][CURRENT_STATS] = playerStats[id][CURRENT_KILLS] * 2 + playerStats[id][CURRENT_HS_KILLS] - playerStats[id][CURRENT_DEATHS] * 2;
if (playerStats[id][CURRENT_STATS] > playerStats[id][BEST_STATS]) {
formatex(queryData, charsmax(queryData), "SELECT rank, count FROM (SELECT COUNT(*) as count FROM `cod_stats`) a CROSS JOIN (SELECT COUNT(*) as rank FROM `cod_stats` WHERE `beststats` > '%i' ORDER BY `beststats` DESC) b",
playerStats[id][BEST_STATS]);
} else {
formatex(queryData, charsmax(queryData), "SELECT rank, count FROM (SELECT COUNT(*) as count FROM `cod_stats`) a CROSS JOIN (SELECT COUNT(*) as rank FROM `cod_stats` WHERE `beststats` > '%i' ORDER BY `beststats` DESC) b",
playerStats[id][CURRENT_STATS]);
}
SQL_ThreadQuery(sql, "show_best_stats", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_best_stats(failState, Handle:query, error[], errorNum, tempId[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempId[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new rank = SQL_ReadResult(query, 0) + 1, players = SQL_ReadResult(query, 1);
if (playerStats[id][CURRENT_STATS] > playerStats[id][BEST_STATS]) {
cod_print_chat(id, "Twoje najlepsze staty to^x04 %i^x01 zabic (w tym^x04 %i^x01 z HS) i^x04 %i^x01 zgonow^x01.",
playerStats[id][CURRENT_KILLS], playerStats[id][CURRENT_HS_KILLS], playerStats[id][CURRENT_DEATHS]);
} else {
cod_print_chat(id, "Twoje najlepsze staty to^x04 %i^x01 zabic (w tym^x04 %i^x01 z HS) i^x04 %i^x01 zgonow^x01.",
playerStats[id][BEST_KILLS], playerStats[id][BEST_HS_KILLS], playerStats[id][BEST_DEATHS]);
}
cod_print_chat(id, "Zajmujesz^x04 %i/%i^x01 miejsce w rankingu najlepszych statystyk.", rank, players);
return PLUGIN_HANDLED;
}
public command_top_stats(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[128], tempId[1];
tempId[0] = id;
formatex(queryData, charsmax(queryData), "SELECT name, bestkills, besths, bestdeaths FROM `cod_stats` ORDER BY beststats DESC LIMIT 15");
SQL_ThreadQuery(sql, "show_top_stats", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_top_stats(failState, Handle:query, error[], errorNum, tempId[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempId[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
static motdData[2048], userName[64], motdLength, rank, kills, hs, deaths;
rank = 0;
motdLength = format(motdData, charsmax(motdData), "<body bgcolor=#000000><font color=#FFB000><pre>");
motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1s %-22.22s %19s %4s^n", "#", "Nick", "Zabojstwa", "Zgony");
while (SQL_MoreResults(query)) {
rank++;
SQL_ReadResult(query, 0, userName, charsmax(userName));
kills = SQL_ReadResult(query, 1);
hs = SQL_ReadResult(query, 2);
deaths = SQL_ReadResult(query, 3);
replace_all(userName, charsmax(userName), "<", "");
replace_all(userName, charsmax(userName), ">", "");
if (rank >= 10) motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %1d (%i HS) %12d^n", rank, userName, kills, hs, deaths);
else motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %2d (%i HS) %12d^n", rank, userName, kills, hs, deaths);
SQL_NextRow(query);
}
show_motd(id, motdData, "Top15 Statystyk");
return PLUGIN_HANDLED;
}
public command_medals(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[256], tempId[1];
tempId[0] = id;
formatex(queryData, charsmax(queryData), "SELECT rank, count FROM (SELECT COUNT(*) as count FROM `cod_stats`) a CROSS JOIN (SELECT COUNT(*) as rank FROM `cod_stats` WHERE `medals` > '%i' ORDER BY `medals` DESC) b",
playerStats[id][MEDALS]);
SQL_ThreadQuery(sql, "show_medals", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_medals(failState, Handle:query, error[], errorNum, tempId[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempId[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new rank = SQL_ReadResult(query, 0) + 1, players = SQL_ReadResult(query, 1);
cod_print_chat(id, "Twoje medale:^x04 %i Zlote^x01,^x04 %i Srebre^x01,^x04 %i Brazowe^x01.", playerStats[id][GOLD], playerStats[id][SILVER], playerStats[id][BRONZE]);
cod_print_chat(id, "Zajmujesz^x04 %i/%i^x01 miejsce w rankingu medalowym.", rank, players);
return PLUGIN_HANDLED;
}
public command_top_medals(id)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
new queryData[128], tempId[1];
tempId[0] = id;
formatex(queryData, charsmax(queryData), "SELECT name, gold, silver, bronze, medals FROM `cod_stats` ORDER BY medals DESC LIMIT 15");
SQL_ThreadQuery(sql, "show_top_medals", queryData, tempId, sizeof(tempId));
return PLUGIN_HANDLED;
}
public show_top_medals(failState, Handle:query, error[], errorNum, tempId[], dataSize)
{
if (failState) {
if (failState == TQUERY_CONNECT_FAILED) cod_log_error(PLUGIN, "Could not connect to SQL database. Error: %s (%d)", error, errorNum);
else if (failState == TQUERY_QUERY_FAILED) cod_log_error(PLUGIN, "Threaded query failed. Error: %s (%d)", error, errorNum);
return PLUGIN_HANDLED;
}
new id = tempId[0];
if (!is_user_connected(id)) return PLUGIN_HANDLED;
static motdData[2048], userName[64], motdLength, rank, gold, silver, bronze, medals;
rank = 0;
motdLength = format(motdData, charsmax(motdData), "<body bgcolor=#000000><font color=#FFB000><pre>");
motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1s %-22.22s %6s %8s %8s %5s^n", "#", "Nick", "Zlote", "Srebrne", "Brazowe", "Suma");
while (SQL_MoreResults(query)) {
rank++;
SQL_ReadResult(query, 0, userName, charsmax(userName));
gold = SQL_ReadResult(query, 1);
silver = SQL_ReadResult(query, 2);
bronze = SQL_ReadResult(query, 3);
medals = SQL_ReadResult(query, 4);
replace_all(userName, charsmax(userName), "<", "");
replace_all(userName, charsmax(userName), ">", "");
if (rank >= 10) motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %2d %7d %8d %7d^n", rank, userName, gold, silver, bronze, medals);
else motdLength += format(motdData[motdLength], charsmax(motdData) - motdLength, "%1i %-22.22s %3d %7d %8d %7d^n", rank, userName, gold, silver, bronze, medals);
SQL_NextRow(query);
}
show_motd(id, motdData, "Top15 Medali");
return PLUGIN_HANDLED;
}
public command_sounds(id)
{
new menuData[64], menu = menu_create("\yUstawienia \rDzwiekow\w:", "command_sounds_handle");
formatex(menuData, charsmax(menuData), "\wThe Force Will Be With You \w[\r%s\w]", get_bit(id, soundMayTheForce) ? "Wlaczony" : "Wylaczony");
menu_additem(menu, menuData);
formatex(menuData, charsmax(menuData), "\wI Am The One And Only \w[\r%s\w]", get_bit(id, soundOneAndOnly) ? "Wlaczony" : "Wylaczony");
menu_additem(menu, menuData);
formatex(menuData, charsmax(menuData), "\wDziabnal Mnie \w[\r%s\w]", get_bit(id, soundHumiliation) ? "Wlaczony" : "Wylaczony");
menu_additem(menu, menuData);
formatex(menuData, charsmax(menuData), "\wKici Kici Tas Tas \w[\r%s\w]", get_bit(id, soundLastLeft) ? "Wlaczony" : "Wylaczony");
menu_additem(menu, menuData);
formatex(menuData, charsmax(menuData), "\wNie Obijac Sie \w[\r%s\w]", get_bit(id, soundPrepare) ? "Wlaczony" : "Wylaczony");
menu_additem(menu, menuData);
menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
menu_display(id, menu);
return PLUGIN_HANDLED;
}
public command_sounds_handle(id, menu, item)
{
if (!is_user_connected(id)) return PLUGIN_HANDLED;
if (item == MENU_EXIT) {
menu_destroy(menu);
return PLUGIN_HANDLED;
}
switch(item) {
case 0: get_bit(id, soundMayTheForce) ? rem_bit(id, soundMayTheForce) : set_bit(id, soundMayTheForce);
case 1: get_bit(id, soundOneAndOnly) ? rem_bit(id, soundOneAndOnly) : set_bit(id, soundOneAndOnly);
case 2: get_bit(id, soundHumiliation) ? rem_bit(id, soundHumiliation) : set_bit(id, soundHumiliation);
case 3: get_bit(id, soundLastLeft) ? rem_bit(id, soundLastLeft) : set_bit(id, soundLastLeft);
case 4: get_bit(id, soundPrepare) ? rem_bit(id, soundPrepare) : set_bit(id, soundPrepare);
}
save_sounds(id);
command_sounds(id);
menu_destroy(menu);
return PLUGIN_HANDLED;
}
public check_time(id)
{
id -= TASK_TIME;
if (get_bit(id, visitInfo)) return;
if (!get_bit(id, dataLoaded)) {
set_task(3.0, "check_time", id + TASK_TIME);
return;
}
set_bit(id, visitInfo);
new currentYear, lastYear, currentMonth, lastMonth, currentDay, lastDay, hour, minute, second, time = get_systime();
UnixToTime(time, currentYear, currentMonth, currentDay, hour, minute, second, UT_TIMEZONE_SERVER);
cod_print_chat(id, "Aktualnie jest godzina^x03 %02d:%02d:%02d (Data: %02d.%02d.%02d)^x01.", hour, minute, second, currentDay, currentMonth, currentYear);
if (playerStats[id][FIRST_VISIT] == playerStats[id][LAST_VISIT]) cod_print_chat(id, "To twoja^x03 pierwsza wizyta^x01 na serwerze. Zyczymy milej gry!" );
else {
UnixToTime(playerStats[id][LAST_VISIT], lastYear, lastMonth, lastDay, hour, minute, second, UT_TIMEZONE_SERVER);
if (currentYear == lastYear && currentMonth == lastMonth && currentDay == lastDay) {
cod_print_chat(id, "Twoja ostatnia wizyta miala miejsce^x04 dzisiaj^x01 o^x03 %02d:%02d:%02d^x01. Zyczymy milej gry!", hour, minute, second);
} else if (currentYear == lastYear && currentMonth == lastMonth && (currentDay - 1) == lastDay) {
cod_print_chat(id, "Twoja ostatnia wizyta miala miejsce^x04 wczoraj^x01 o^x03 %02d:%02d:%02d^x01. Zyczymy milej gry!", hour, minute, second);
} else {
cod_print_chat(id, "Twoja ostatnia wizyta:^x03 %02d:%02d:%02d (Data: %02d.%02d.%02d)^x01. Zyczymy milej gry!", hour, minute, second, lastDay, lastMonth, lastYear);
}
}
}
public cod_spawned(id, respawn)
{
if (!get_bit(id, visitInfo)) set_task(5.0, "check_time", id + TASK_TIME);
if (!respawn) for (new i = 1; i <= MAX_PLAYERS; i++) playerDamage[id][i] = 0;
save_stats(id);
}
public first_round()
blockCount = false;
public cod_restart_round()
round = 0;
public cod_new_round()
{
showedOneAndOnly = false;
if (!round) {
set_task(30.0, "first_round");
blockCount = true;
}
round++;
new bestId, bestRoundId, bestFrags, bestRoundFrags, bestRoundHS, tempFrags, bestDeaths, tempDeaths;
for (new id = 1; id <= MAX_PLAYERS; id++) {
if (!is_user_connected(id) || is_user_bot(id) || is_user_hltv(id)) continue;
tempFrags = get_user_frags(id);
tempDeaths = get_user_deaths(id);
if (tempFrags > 0 && tempFrags > bestFrags) {
bestFrags = tempFrags;
bestDeaths = tempDeaths;
bestId = id;
}
if (playerStats[id][ROUND_KILLS] > 0 && (playerStats[id][ROUND_KILLS] > bestRoundFrags || (playerStats[id][ROUND_KILLS] == bestRoundFrags && playerStats[id][ROUND_HS_KILLS] > bestRoundHS))) {
bestRoundFrags = playerStats[id][ROUND_KILLS];
bestRoundHS = playerStats[id][ROUND_HS_KILLS];
bestRoundId = id;
}
playerStats[id][ROUND_KILLS] = 0;
playerStats[id][ROUND_HS_KILLS] = 0;
}
if (is_user_connected(bestRoundId)) {
new bestRoundName[64];
get_user_name(bestRoundId, bestRoundName, charsmax(bestRoundName));
cod_print_chat(0, "^x03%s^x01 byl najlepszym graczem rundy. Ustrzelil^x04 %i^x01 frag%s, w tym^x04 %i^x01 z HeadShotem.", bestRoundName, bestRoundFrags, bestRoundFrags > 1 ? "i" : "a", bestRoundHS);
}
if (is_user_connected(bestId)) {
new bestName[64];
get_user_name(bestId, bestName, charsmax(bestName));
cod_print_chat(0, "^x03%s^x01 prowadzi w grze z^x04 %i^x01 fragami i^x04 %i^x01 zgonami.", bestName, bestFrags, bestDeaths);
}
}
public cod_damage_post(attacker, victim, weapon, Float:damage, damageBits, hitPlace)
playerDamage[attacker][victim] += floatround(damage);
public cod_killed(killer, victim, weaponId, hitPlace)
{
playerStats[victim][CURRENT_DEATHS]++;
playerStats[victim][REVENGE] = killer;
playerStats[killer][CURRENT_KILLS]++;
playerStats[killer][ROUND_KILLS]++;
playerStats[killer][KILLS]++;
if (hitPlace == HIT_HEAD) {
playerStats[killer][CURRENT_HS_KILLS]++;
playerStats[killer][ROUND_HS_KILLS]++;
}
if (weaponId == CSW_KNIFE) {
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_connected(i)) continue;
if ((pev(i, pev_iuser2) == victim || i == victim) && get_bit(i, soundHumiliation)) client_cmd(i, "spk %s", codSounds[SOUND_HUMILIATION]);
}
}
if (cvarRevengeEnabled && playerStats[killer][REVENGE] == victim) {
new nameVictim[MAX_NAME];
get_user_name(victim, nameVictim, charsmax(nameVictim));
set_user_frags(killer, get_user_frags(killer) + 1);
cs_set_user_deaths(killer, cs_get_user_deaths(killer));
playerStats[killer][REVENGE] = 0;
if (cvarMinPlayers >= get_playersnum()) cod_add_user_honor(killer, cvarRevengeHonor, true);
if (cvarMinPlayers >= get_playersnum() && cvarRevengeExp) {
new exp = cod_get_user_bonus_exp(killer, cvarRevengeExp);
cod_set_user_exp(killer, exp);
cod_print_chat(killer, "Zemsciles sie na^x03 %s^x01. Dostajesz fraga i^x03 %i^x01 expa!", nameVictim, exp);
} else cod_print_chat(killer, "Zemsciles sie na^x03 %s^x01. Dostajesz fraga!", nameVictim);
}
if (cvarAssistEnabled) {
new assist = 0, damage = 0;
for (new id = 1; id <= MAX_PLAYERS; id++) {
if (!is_user_connected(id) || is_user_bot(id) || is_user_hltv(id) || id == killer) continue;
if (playerDamage[id][victim] > damage) {
assist = id;
damage = playerDamage[id][victim];
}
playerDamage[id][victim] = 0;
}
if (assist > 0 && damage > cvarAssistDamage) {
set_user_frags(assist, get_user_frags(assist) + 1);
cs_set_user_deaths(assist, cs_get_user_deaths(assist));
new nameVictim[MAX_NAME], nameKiller[MAX_NAME];
get_user_name(victim, nameVictim, charsmax(nameVictim));
get_user_name(killer, nameKiller, charsmax(nameKiller));
if (cvarMinPlayers >= get_playersnum()) cod_add_user_honor(assist, cvarAssistHonor, true);
if (cvarMinPlayers >= get_playersnum() && cvarAssistExp) {
new exp = exp = cod_get_user_bonus_exp(assist, cvarAssistExp);
cod_set_user_exp(assist, exp);
cod_print_chat(assist, "Pomogles^x03 %s^x01 w zabiciu^x03 %s^x01. Dostajesz fraga i^x03 %i^x01 expa!", nameKiller, nameVictim, exp);
} else cod_print_chat(assist, "Pomogles^x03 %s^x01 w zabiciu^x03 %s^x01. Dostajesz fraga!", nameKiller, nameVictim);
}
}
if (blockCount) return;
new tCount, ctCount, lastT, lastCT;
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_alive(i)) continue;
switch (get_user_team(i)) {
case 1: {
tCount++;
lastT = i;
}
case 2: {
ctCount++;
lastCT = i;
}
}
}
if (tCount == 1 && ctCount == 1) {
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_connected(i)) continue;
if ((pev(i, pev_iuser2) == lastT || pev(i, pev_iuser2) == lastCT || i == lastT || i == lastCT) && get_bit(i, soundMayTheForce)) client_cmd(i, "spk %s", codSounds[SOUND_FORCE]);
}
new lastTName[MAX_NAME], lastCTName[MAX_NAME];
get_user_name(lastT, lastTName, charsmax(lastTName));
get_user_name(lastCT, lastCTName, charsmax(lastCTName));
cod_show_hud(0, TYPE_DHUD, 255, 128, 0, -1.0, 0.30, 0, 5.0, 5.0, 0.5, 0.15, "%s vs. %s", lastTName, lastCTName);
}
if (tCount == 1 && ctCount > 1 && !showedOneAndOnly) {
showedOneAndOnly = true;
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_connected(i)) continue;
if (((is_user_alive(i) && get_user_team(i) == 2) || (!is_user_alive(i) && get_user_team(pev(i, pev_iuser2)) == 2)) && get_bit(i, soundOneAndOnly)) client_cmd(i, "spk %s", codSounds[SOUND_LAST]);
if (pev(i, pev_iuser2) == lastT || i == lastT) client_cmd(i, "spk %s", codSounds[SOUND_ONE]);
}
cod_show_hud(0, TYPE_DHUD, 255, 128, 0, -1.0, 0.30, 0, 5.0, 5.0, 0.5, 0.15, "%i vs %i", tCount, ctCount);
}
if (tCount > 1 && ctCount == 1 && !showedOneAndOnly) {
showedOneAndOnly = true;
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_connected(i)) continue;
if (((is_user_alive(i) && get_user_team(i) == 1) || (!is_user_alive(i) && get_user_team(pev(i, pev_iuser2)) == 1)) && get_bit(i, soundOneAndOnly)) client_cmd(i, "spk %s", codSounds[SOUND_LAST]);
if (pev(i, pev_iuser2) == lastCT || i == lastCT) client_cmd(i, "spk %s", codSounds[SOUND_ONE]);
}
cod_show_hud(0, TYPE_DHUD, 255, 128, 0, -1.0, 0.30, 0, 5.0, 5.0, 0.5, 0.15, "%i vs %i", ctCount, tCount);
}
}
public cod_bomb_planted(planter)
{
for (new i = 1; i <= MAX_PLAYERS; i++) {
if (!is_user_connected(i)) continue;
if (((is_user_alive(i) && get_user_team(i) == 2) || (!is_user_alive(i) && get_user_team(pev(i, pev_iuser2)) == 2)) && get_bit(i, soundPrepare)) client_cmd(i, "spk %s", codSounds[SOUND_BOMB]);
}
}
public cod_bomb_explode(planter, defuser)
playerStats[planter][KILLS] += 3;
public cod_bomb_defused(defuser)
playerStats[defuser][KILLS] += 3;
public cod_hostages_rescued(id)
playerStats[id][KILLS] += 3;
public cod_end_map()
{
mapEnd = true;
if (cvarMedalsEnabled) {
new playerName[MAX_NAME], winnersId[3], winnersFrags[3], tempFrags, swapFrags, swapId, exp;
for (new id = 1; id <= MAX_PLAYERS; id++) {
if (!is_user_connected(id) || is_user_hltv(id) || is_user_bot(id)) continue;
tempFrags = get_user_frags(id);
if (tempFrags > winnersFrags[THIRD]) {
winnersFrags[THIRD] = tempFrags;
winnersId[THIRD] = id;
if (tempFrags > winnersFrags[SECOND]) {
swapFrags = winnersFrags[SECOND];
swapId = winnersId[SECOND];
winnersFrags[SECOND] = tempFrags;
winnersId[SECOND] = id;
winnersFrags[THIRD] = swapFrags;
winnersId[THIRD] = swapId;
if (tempFrags > winnersFrags[FIRST]) {
swapFrags = winnersFrags[FIRST];
swapId = winnersId[FIRST];
winnersFrags[FIRST] = tempFrags;
winnersId[FIRST] = id;
winnersFrags[SECOND] = swapFrags;
winnersId[SECOND] = swapId;
}
}
}
}
if (!winnersId[FIRST]) return PLUGIN_CONTINUE;
new const medals[][] = { "Brazowy", "Srebrny", "Zloty" };
cod_print_chat(0, "Gratulacje dla^x03 Najlepszych Graczy^x01!");
for (new i = 2; i >= 0; i--) {
if (!is_user_connected(winnersId[i])) continue;
switch (i) {
case THIRD: {
playerStats[winnersId[i]][BRONZE]++;
exp = cvarBronzeMedalExp;
} case SECOND: {
playerStats[winnersId[i]][SILVER]++;
exp = cvarSilverMedalExp;
} case FIRST: {
playerStats[winnersId[i]][GOLD]++;
exp = cvarGoldMedalExp;
}
}
save_stats(winnersId[i], mapEnd);
get_user_name(winnersId[i], playerName, charsmax(playerName));
if (get_playersnum() >= cvarMinPlayers && exp) {
cod_set_user_exp(winnersId[i], exp);
cod_print_chat(0, "^x03 %s^x01 -^x03 %i^x01 Zabojstw - %s Medal (+^x03%i^x01 Doswiadczenia).", playerName, winnersFrags[i], medals[i], exp);
} else cod_print_chat(0, "^x03 %s^x01 -^x03 %i^x01 Zabojstw - %s Medal.", playerName, winnersFrags[i], medals[i]);
}
}
for (new id = 1; id <= MAX_PLAYERS; id++) {
if (!is_user_connected(id) || is_user_hltv(id) || is_user_bot(id)) continue;
save_stats(id, mapEnd);
}
return PLUGIN_CONTINUE;
}
public say_text(msgId, msgDest, msgEnt)
{
new id = get_msg_arg_int(1);
if (is_user_connected(id)) {
new tempMessage[192], message[192], playerName[MAX_NAME], chatPrefix[16], stats[8], body[8], rank;
get_msg_arg_string(2, tempMessage, charsmax(tempMessage));
rank = get_user_stats(id, stats, body);
if (rank > 3) return PLUGIN_CONTINUE;
switch (rank) {
case 1: formatex(chatPrefix, charsmax(chatPrefix), "^x04[TOP1]");
case 2: formatex(chatPrefix, charsmax(chatPrefix), "^x04[TOP2]");
case 3: formatex(chatPrefix, charsmax(chatPrefix), "^x04[TOP3]");
}
if (!equal(tempMessage, "#Cstrike_Chat_All")) {
add(message, charsmax(message), chatPrefix);
add(message, charsmax(message), " ");
add(message, charsmax(message), tempMessage);
} else {
get_user_name(id, playerName, charsmax(playerName));
get_msg_arg_string(4, tempMessage, charsmax(tempMessage));
set_msg_arg_string(4, "");
add(message, charsmax(message), chatPrefix);
add(message, charsmax(message), "^x03 ");
add(message, charsmax(message), playerName);
add(message, charsmax(message), "^x01 : ");
add(message, charsmax(message), tempMessage);
}
set_msg_arg_string(2, message);
}