-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnominations_unlimited.sp
1763 lines (1461 loc) · 56.6 KB
/
nominations_unlimited.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
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
#pragma newdecls required
#pragma semicolon 1
#include <sourcemod>
#include <clientprefs>
#include <mapchooser_unlimited>
#include <csgocolors_fix>
#define PLUGIN_VERSION "1.2.2"
public Plugin myinfo =
{
name = "Nominations Unlimited",
author = "tilgep (Based on plugin by Powerlord and AlliedModders LLC)",
description = "Nominations allowing votes for everyone.",
version = PLUGIN_VERSION,
url = "https://www.github.com/tilgep/"
};
bool g_bLateLoad = false;
Cookie g_cookie_Nomban; //Format("length:timeIssued")
Cookie g_cookie_NombanAdmin; //Admin who gave the nomban
#define NOMBAN_NOTBANNED -1
#define NOMBAN_PERMANENT 0
int g_iNomBanLength[MAXPLAYERS+1];
int g_iNomBanStart[MAXPLAYERS+1];
char g_sNomBanAdmin[MAXPLAYERS+1][PLATFORM_MAX_PATH];
ArrayList g_MapList;
ConVar g_cv_Enabled;
ConVar g_cv_NominationDelay;
ConVar g_cv_ClientNomDelay;
ConVar g_cv_NomAnnounceInterval;
ConVar g_cv_AnnounceToClient;
ConVar g_cv_RemoveNomOnNomban;
ConVar g_cv_ShowNomInConsole;
ConVar g_cv_ShowCooldown;
bool g_bEnabled = true; //Is nominating allowed
int g_iSerial;
int g_iNominationDelay; //Inital time to start allowing noms
int g_iClientNomDelay[MAXPLAYERS+1]; //Last time a client nominated
public void OnPluginStart()
{
if(GetEngineVersion() != Engine_CSGO)
{
LogMessage("This plugin is only tested and supported on CSGO! Beware of bugs!");
PrintToServer("This plugin is only tested and supported on CSGO! Beware of bugs!");
}
LoadTranslations("common.phrases"); //For nomban FindTarget
LoadTranslations("mapchooser_unlimited.phrases");
LoadTranslations("nominations_unlimited.phrases");
/* Client commands */
RegConsoleCmd("sm_nominate", Command_Nominate, "Nominate a map.");
RegConsoleCmd("sm_nom", Command_Nominate, "Nominate a map.");
RegConsoleCmd("sm_unnominate", Command_UnNominate, "Removes your nomination");
RegConsoleCmd("sm_unominate", Command_UnNominate, "Removes your nomination");
RegConsoleCmd("sm_unnom", Command_UnNominate, "Removes your nomination");
RegConsoleCmd("sm_unom", Command_UnNominate, "Removes your nomination");
RegConsoleCmd("sm_nomlist", Command_Nomlist, "Shows a list of currently nominated maps");
RegConsoleCmd("sm_noms", Command_Nomlist, "Shows a list of currently nominated maps");
RegConsoleCmd("sm_nomstatus", Command_NomStatus, "Shows your current nomban status.");
/* Admin commands */
RegAdminCmd("sm_nomenable", Command_Enable, ADMFLAG_BAN, "Enables nominating.", "nom_enable");
RegAdminCmd("sm_enablenom", Command_Enable, ADMFLAG_BAN, "Enables nominating.", "nom_enable");
RegAdminCmd("sm_nomdisable", Command_Disable, ADMFLAG_BAN, "Disables nominating.", "nom_disable");
RegAdminCmd("sm_disablenom", Command_Disable, ADMFLAG_BAN, "Disables nominating.", "nom_disable");
RegAdminCmd("sm_adminnom", Command_Insert, ADMFLAG_BAN, "Insert a map into the nomlist.", "nom_admin");
RegAdminCmd("sm_adminom", Command_Insert, ADMFLAG_BAN, "Insert a map into the nomlist.", "nom_admin");
RegAdminCmd("sm_nominate_addmap", Command_Insert, ADMFLAG_BAN, "Insert a map into the nomlist.", "nom_admin");
RegAdminCmd("sm_adminom", Command_Insert, ADMFLAG_BAN, "Insert a map into the nomlist.", "nom_admin");
RegAdminCmd("sm_insertmap", Command_Insert, ADMFLAG_BAN, "Insert a map into the nomlist.", "nom_admin");
RegAdminCmd("sm_adminunnom", Command_UnInsert, ADMFLAG_BAN, "Removes an inserted map from the nomlist.", "nom_admin");
RegAdminCmd("sm_uninsert", Command_UnInsert, ADMFLAG_BAN, "Removes an inserted map from the nomlist.", "nom_admin");
RegAdminCmd("sm_removenom", Command_RemoveNom, ADMFLAG_BAN, "Removes a given clients nomination.");
RegAdminCmd("sm_nomban", Command_Nomban, ADMFLAG_BAN, "Ban a client from nominating.", "nomban");
RegAdminCmd("sm_nombanlist", Command_NombanList, ADMFLAG_BAN, "View a list of nombanned clients.", "nomban");
RegAdminCmd("sm_unnomban", Command_UnNomban, ADMFLAG_BAN, "Unban a client from nominating.", "nomban");
RegAdminCmd("sm_nomunban", Command_UnNomban, ADMFLAG_BAN, "Unban a client from nominating.", "nomban");
RegAdminCmd("sm_unomban", Command_UnNomban, ADMFLAG_BAN, "Unban a client from nominating.", "nomban");
RegAdminCmd("sm_addmapvotes", Command_AddMapVotes, ADMFLAG_ROOT, "Set's a map's votes (Used for testing)");
g_cv_Enabled = CreateConVar("nominate_enabled", "1", "Is nominating enabled.", _, true, 0.0, true, 1.0);
g_cv_NominationDelay = CreateConVar("nominate_initialdelay", "60.0", "Time in seconds before first Nomination can be made.", _, true, 0.0);
g_cv_ClientNomDelay = CreateConVar("nominate_clientdelay", "10", "Number of seconds a client must wait before making another nomination.", _, true, 0.0);
g_cv_NomAnnounceInterval = CreateConVar("nominate_announce_interval", "1", "When a map gets nominated in infinite mode, it will announce to all only if the number of votes can be divided by this value, it will always announce first vote. (0 = only announce first vote, -1 = never announce to all)", _, true, -1.0);
g_cv_AnnounceToClient = CreateConVar("nominate_clientannounce", "1", "Should the client receive a message about their nomination if it doesnt print to all.", _, true, 0.0, true, 1.0);
g_cv_ShowNomInConsole = CreateConVar("nominate_console", "1", "Should every nomination be printed into client consoles", _, true, 0.0, true, 1.0);
g_cv_RemoveNomOnNomban = CreateConVar("nominate_banclear", "1", "Should a client's nomination be removed when they get nombanned.", _,true, 0.0, true, 1.0);
g_cv_ShowCooldown = CreateConVar("nominate_showcooldown", "1", "Whether the current cooldown for maps should be shown in the nominate menu (1=enabled, 0=disabled)", _, true, 0.0, true, 1.0);
AutoExecConfig(true, "nominations_unlimited");
g_cookie_Nomban = RegClientCookie("nomban_status", "Client's nomban info", CookieAccess_Private);
g_cookie_NombanAdmin = RegClientCookie("nomban_admin", "Admin who nombanned", CookieAccess_Private);
if(g_bLateLoad)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i) && AreClientCookiesCached(i))
{
OnClientCookiesCached(i);
}
}
}
g_MapList = CreateArray(ByteCountToCells(PLATFORM_MAX_PATH));
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(LibraryExists("nominations"))
{
strcopy(error, err_max, "Nominations already loaded! Aborting.");
return APLRes_Failure;
}
RegPluginLibrary("nominations");
g_bLateLoad = late;
return APLRes_Success;
}
public void OnAllPluginsLoaded()
{
if(!LibraryExists("mapchooser"))
{
SetFailState("Mapchooser not found! It is required for this plugin to work!");
}
}
public void OnConfigsExecuted()
{
LoadMaplist();
g_iNominationDelay = GetTime() + g_cv_NominationDelay.IntValue;
g_bEnabled = g_cv_Enabled.BoolValue;
}
public void OnMapListReloaded()
{
LoadMaplist();
}
bool LoadMaplist()
{
if(ReadMapList(g_MapList, g_iSerial, "mapchooser", MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_MAPSFOLDER) != INVALID_HANDLE)
{
if(g_iSerial == -1)
{
LogError("Unable to create a valid map list.");
return false;
}
return true;
}
return false;
}
public void OnClientPutInServer(int client)
{
if(!AreClientCookiesCached(client))
{
g_iNomBanLength[client] = NOMBAN_NOTBANNED;
g_iNomBanStart[client] = NOMBAN_NOTBANNED;
}
}
public void OnClientDisconnect(int client)
{
SaveClientNombanStatus(client);
}
public void OnClientCookiesCached(int client)
{
char sCookie[128];
GetClientCookie(client, g_cookie_Nomban, sCookie, sizeof(sCookie));
if(StrEqual(sCookie, ""))
{
g_iNomBanStart[client] = NOMBAN_NOTBANNED;
g_iNomBanLength[client] = NOMBAN_NOTBANNED;
return;
}
char sBuffer[2][64];
ExplodeString(sCookie, ":", sBuffer, sizeof(sBuffer), sizeof(sBuffer[]), true);
g_iNomBanLength[client] = StringToInt(sBuffer[0]);
g_iNomBanStart[client] = StringToInt(sBuffer[1]);
if(IsClientNomBanned(client))
{
RemoveNominationByOwner(client, Removed_Ignore);
}
}
/* ====================================================== */
/* ====================================================== */
/* Command Callbacks */
/* ====================================================== */
/* ====================================================== */
public Action Command_Nominate(int client, int args)
{
if(!CanClientNominate(client))
{
return Plugin_Handled;
}
CanNominateResult canNom = CanNominate(client);
if(canNom != CanNominate_Yes)
{
switch(canNom)
{
case CanNominate_VoteComplete:
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cannot Nominate - Vote Complete");
}
case CanNominate_VoteInProgress:
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cannot Nominate - Vote In Progress");
}
case CanNominate_VoteFull:
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cannot Nominate - Vote Full");
}
}
return Plugin_Handled;
}
if(args == 0)
{
AttemptNominate(client);
return Plugin_Handled;
}
if(g_iClientNomDelay[client] > GetTime())
{
CReplyToCommand(client, "%t %t", "NPrefix", "Wait to nominate", g_iClientNomDelay[client] - GetTime());
return Plugin_Handled;
}
char map[PLATFORM_MAX_PATH];
GetCmdArgString(map, sizeof(map));
ReplaceString(map, sizeof(map), " ", "_", false);
StripQuotes(map);
if(StrEqual(map, "_random"))
{
Format(map, sizeof(map), "%s", GetRandomMap(client));
}
if(FindStringInArray(g_MapList, map) == -1 || !IsMapValid(map))
{
//Check if only 1 map matches pattern before saying not found
if(!AttemptNominate(client, map))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map was not found", map);
return Plugin_Handled;
}
}
int status = CanMapBeNominated(client, map);
if((status & CanClientNom_Yes) == CanClientNom_Yes)
{
NominateResult result = NominateMap(client, map, false);
//Successful nomination prints in OnMapNominated
if(result == Nominate_InvalidMap)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map was not found", map);
LogMessage("Map not found %s", map);
}
else if(result == Nominate_VoteFull)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cannot Nominate - Vote Full");
}
return Plugin_Handled;
}
/* Map cannot be nominated - Lets tell the client why */
if((status & CanClientNom_CurrentMap) == CanClientNom_CurrentMap)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Current map");
return Plugin_Handled;
}
if((status & CanClientNom_CurrentNom) == CanClientNom_CurrentNom)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Current nomination", map);
return Plugin_Handled;
}
if((status & CanClientNom_Inserted) == CanClientNom_Inserted)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Already Inserted", map);
return Plugin_Handled;
}
if((status & CanClientNom_Nominated) == CanClientNom_Nominated)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Already Nominated", map);
return Plugin_Handled;
}
if((status & CanClientNom_AdminOnly) == CanClientNom_AdminOnly)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Admin Only Nominating", map);
return Plugin_Handled;
}
if((status & CanClientNom_Cooldown) == CanClientNom_Cooldown)
{
if(g_cv_ShowCooldown.BoolValue)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map is on cooldown", map, GetMapCooldown(map));
}
else
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map is on cooldown - No Value", map);
}
return Plugin_Handled;
}
if((status & CanClientNom_NotEnoughPlayers) == CanClientNom_NotEnoughPlayers)
{
int players = GetMapPlayerRestriction(map) * -1;
CReplyToCommand(client, "%t %t", "NPrefix", "Map needs more players", map, players);
return Plugin_Handled;
}
if((status & CanClientNom_TooManyPlayers) == CanClientNom_TooManyPlayers)
{
int players = GetMapPlayerRestriction(map) * -1;
CReplyToCommand(client, "%t %t", "NPrefix", "Map needs fewer players", map, players);
return Plugin_Handled;
}
if((status & CanClientNom_Time) == CanClientNom_Time)
{
int minutes = GetMapTimeRestriction(map);
if(minutes >= 60)
{
int hours = minutes / 60;
minutes = minutes % 60;
CReplyToCommand(client, "%t %t", "NPrefix", "Nominate Time Restriction - Hours", map, hours, minutes);
}
else
{
CReplyToCommand(client, "%t %t", "NPrefix", "Nominate Time Restriction - Minutes", map, minutes);
}
return Plugin_Handled;
}
CReplyToCommand(client, "%t %t", "NPrefix", "Error Nominating", map);
return Plugin_Handled;
}
public Action Command_UnNominate(int client, int args)
{
if(args > 0 && CheckCommandAccess(client, "sm_adminnom", ADMFLAG_BAN))
{
char sTarget[64];
GetCmdArg(1, sTarget, sizeof(sTarget));
int target = FindTarget(client, sTarget);
if(target > 0)
{
if(!RemoveNominationByOwner(client, Removed_AdminClear))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Unable To Unnominate Admin", target);
}
}
return Plugin_Handled;
}
if(!RemoveNominationByOwner(client, Removed_UnNominated))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Unable To Unnominate");
}
//OnNominationRemoved will print to all if it gets removed
return Plugin_Handled;
}
public Action Command_Nomlist(int client, int args)
{
if(client == 0)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Can only use command in game");
return Plugin_Handled;
}
PrepareNomlistMenu(client);
return Plugin_Handled;
}
public Action Command_NomStatus(int client, int args)
{
if(client == 0)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Can only use command in game");
return Plugin_Handled;
}
int target = client;
if(args > 0)
{
char targ[64];
GetCmdArg(1, targ, sizeof(targ));
target = FindTarget(client, targ);
}
if(!AreClientCookiesCached(target))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cookies are not cached");
return Plugin_Handled;
}
PrepareNomStatusMenu(client, target);
return Plugin_Handled;
}
public Action Command_Enable(int client, int args)
{
if(g_bEnabled)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Nominating already enabled");
return Plugin_Handled;
}
g_bEnabled = true;
LogAction(client, -1, "%L enabled nominating.", client);
CPrintToChatAll("%t %t", "NPrefix", "Nominating Enabled");
return Plugin_Handled;
}
public Action Command_Disable(int client, int args)
{
if(!g_bEnabled)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Nominating already disabled");
return Plugin_Handled;
}
g_bEnabled = false;
LogAction(client, -1, "%L disabled nominating.", client);
CPrintToChatAll("%t %t", "NPrefix", "Nominating Disabled");
return Plugin_Handled;
}
public Action Command_Insert(int client, int args)
{
CanNominateResult result = CanNominate(client);
if(result == CanNominate_VoteInProgress)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Cannot insert - Vote in progress");
return Plugin_Handled;
}
if(args == 0)
{
AttemptInsert(client);
return Plugin_Handled;
}
char map[PLATFORM_MAX_PATH];
GetCmdArg(1, map, sizeof(map));
if(FindStringInArray(g_MapList, map) == -1)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map was not found", map);
AttemptInsert(client, map);
return Plugin_Handled;
}
int status = CanMapBeNominated(client, map);
if((status & CanClientNom_Inserted) == CanClientNom_Inserted)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Already Inserted", map);
return Plugin_Handled;
}
NominateMap(client, map, true);
/* OnMapInserted handles printing to chat */
return Plugin_Handled;
}
public Action Command_UnInsert(int client, int args)
{
if(args < 1)
{
CReplyToCommand(client, "%t %t", "NPrefix", "UnInsert Usage");
return Plugin_Handled;
}
char map[PLATFORM_MAX_PATH];
GetCmdArg(1, map, sizeof(map));
if(FindStringInArray(g_MapList, map) == -1)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map was not found", map);
return Plugin_Handled;
}
if(!IsMapInserted(map))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Map is not inserted", map);
return Plugin_Handled;
}
if(RemoveInsertedMap(client, map))
{
CPrintToChatAll("%t %t", "NPrefix", "Map Uninserted", client, map);
}
else
{
CReplyToCommand(client, "%t %t", "NPrefix", "Failed to uninsert", map);
}
return Plugin_Handled;
}
public Action Command_RemoveNom(int client, int args)
{
if(args == 0)
{
CReplyToCommand(client, "%t %t", "NPrefix", "RemoveNom Usage");
return Plugin_Handled;
}
char buffer[64];
GetCmdArg(1, buffer, sizeof(buffer));
int target = FindTarget(client, buffer);
if(target == -1) return Plugin_Handled;
RemoveNominationByOwner(target, Removed_AdminClear);
return Plugin_Handled;
}
public Action Command_Nomban(int client, int args)
{
if(GetCmdArgs() != 2)
{
CReplyToCommand(client, "%t %t", "NPrefix", "Nomban usage");
return Plugin_Handled;
}
char target_argument[64];
GetCmdArg(1, target_argument, sizeof(target_argument));
int target = -1;
if((target = FindTarget(client, target_argument, true)) == -1)
{
return Plugin_Handled;
}
if(IsClientNomBanned(target))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Already nombanned", target);
return Plugin_Handled;
}
char sLen[64];
GetCmdArg(2, sLen, sizeof(sLen));
int length = StringToInt(sLen);
if(length >= NOMBAN_PERMANENT)
{
NomBanClient(target, length*60, client);
}
else
{
CReplyToCommand(client, "%t %t", "NPrefix", "Nomban usage");
}
return Plugin_Handled;
}
public Action Command_UnNomban(int client, int args)
{
if(GetCmdArgs() < 1)
{
CReplyToCommand(client, "%t %t", "NPrefix", "UnNomban usage");
return Plugin_Handled;
}
char target_argument[64];
GetCmdArg(1, target_argument, sizeof(target_argument));
int target = -1;
if((target = FindTarget(client, target_argument, true)) == -1)
{
return Plugin_Handled;
}
if(!IsClientNomBanned(target))
{
CReplyToCommand(client, "%t %t", "NPrefix", "Already not nombanned", target);
return Plugin_Handled;
}
UnNomBanClient(target, client);
return Plugin_Handled;
}
public Action Command_NombanList(int client, int args)
{
if(client == 0)
{
PrintToServer("--------------------");
PrintToServer("Nomban List");
PrintToServer("--------------------");
for(int i = 1; i <= MaxClients; i++)
{
if(!IsClientNomBanned(i)) continue;
int uid = GetClientUserId(i);
PrintToServer("[#%d] %N", uid, i);
}
PrintToServer("--------------------");
}
else
{
PrepareNombanListMenu(client);
}
return Plugin_Handled;
}
public Action Command_AddMapVotes(int client, int args)
{
if(args == 0)
{
CPrintToChat(client, "%t Usage: sm_addmapvotes <map> [votes] (dont specify votes to add 1)", "NPrefix");
return Plugin_Handled;
}
char map[PLATFORM_MAX_PATH];
GetCmdArg(1, map, sizeof(map));
if(FindStringInArray(g_MapList, map) == -1)
{
CPrintToChat(client, "%t %t", "NPrefix", "Map was not found", map);
return Plugin_Handled;
}
int add = 1;
if(args > 1)
{
char buf[16];
GetCmdArg(2, buf, sizeof(buf));
int temp = StringToInt(buf);
if(temp > 1) add = temp;
}
for(int i = 0; i < add; i++)
{
NominateMap(0, map, false);
}
int votes = GetMapVotes(map);
if(votes > 0) CPrintToChatAll("%t Admin added %d votes for map '%s' [%d votes]", "NPrefix", add, map, votes);
return Plugin_Handled;
}
public void OnNominationRemoved(NominateRemoved reason, const char[] map, int client)
{
switch(reason)
{
case Removed_UnNominated:
{
//TODO: Implement same printing logic as nomination
CPrintToChat(client, "%t %t", "NPrefix", "Nomination Removed - UnNominated", map);
}
case Removed_AdminClear:
{
CPrintToChat(client, "%t %t", "NPrefix", "Nomination Removed - Admin Removed", map);
}
case Removed_NotEnoughPlayers:
{
CPrintToChat(client, "%t %t", "NPrefix", "Nomination Removed - Not Enough Players", map);
}
case Removed_TooManyPlayers:
{
CPrintToChat(client, "%t %t", "NPrefix", "Nomination Removed - Too Many Players", map);
}
case Removed_Time:
{
CPrintToChat(client, "%t %t", "NPrefix", "Nomination Removed - Time", map);
}
}
}
/* ====================================================== */
/* ====================================================== */
/* Nominate */
/* ====================================================== */
/* ====================================================== */
bool AttemptNominate(int client, char[] filter = "")
{
Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
bool single = BuildMapMenu(menu, filter);
if(single) return true;
SetMenuTitle(menu, "%T", "Nominate Menu Title", client);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return false;
}
public void OnMapNominated(int client, const char[] map, int votes, bool replaced)
{
if(client == 0) return;
g_iClientNomDelay[client] = GetTime() + g_cv_ClientNomDelay.IntValue;
if(g_cv_ShowNomInConsole.BoolValue)
{
char buffer[256];
if(GetNominationMode() == NominationMode_Limited)
{
if(replaced)
{
Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated Replaced", client, map);
}
else
{
Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated", client, map);
}
}
else //Infinite noms
{
if(replaced)
{
if(votes == 1) Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated Single Replaced", client, map);
else Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated Multiple Replaced", client, map, votes);
}
else
{
if(votes == 1) Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated Single", client, map);
else Format(buffer, sizeof(buffer), "%t %t", "NPrefix", "Player Nominated Multiple", client, map, votes);
}
}
CRemoveTags(buffer, sizeof(buffer));
PrintToConsoleAll(buffer);
}
if(GetNominationMode() == NominationMode_Limited)
{
if(replaced)
{
CPrintToChatAll("%t %t", "NPrefix", "Player Nominated Replaced", client, map);
}
else
{
CPrintToChatAll("%t %t", "NPrefix", "Player Nominated", client, map);
}
return;
}
if(g_cv_NomAnnounceInterval.IntValue == -1)
{
if(g_cv_AnnounceToClient.IntValue == 0) return;
if(votes==1)
{
if(replaced) CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Single Replaced", map);
else CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Single", map);
return;
}
if(replaced) CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple Replaced", map, votes);
else CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple", map, votes);
return;
}
if(votes == 1)
{
if(replaced) CPrintToChatAll("%t %t", "NPrefix", "Player Nominated Single Replaced", client, map);
else CPrintToChatAll("%t %t", "NPrefix", "Player Nominated Single", client, map);
return;
}
if(g_cv_NomAnnounceInterval.IntValue == 0)
{
if(g_cv_AnnounceToClient.IntValue == 0) return;
if(replaced) CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple Replaced", map, votes);
else CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple", map, votes);
return;
}
if(votes % g_cv_NomAnnounceInterval.IntValue == 0)
{
if(replaced) CPrintToChatAll("%t %t", "NPrefix", "Player Nominated Multiple Replaced", client, map, votes);
else CPrintToChatAll("%t %t", "NPrefix", "Player Nominated Multiple", client, map, votes);
return;
}
if(g_cv_AnnounceToClient.IntValue == 0) return;
if(replaced) CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple Replaced", map, votes);
else CPrintToChat(client, "%t %t", "NPrefix", "Client Nominated Multiple", map, votes);
}
/* ====================================================== */
/* ====================================================== */
/* Nom Menu */
/* ====================================================== */
/* ====================================================== */
bool BuildMapMenu(Menu menu, char[] filter)
{
static char map[PLATFORM_MAX_PATH];
int count;
char first[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(g_MapList); i++)
{
GetArrayString(g_MapList, i, map, sizeof(map));
if(!filter[0] || StrContains(map, filter, false) != -1)
{
AddMenuItem(menu, map, map);
if(count==0) Format(first,sizeof(first), "%s", map);
count++;
}
}
SetMenuExitButton(menu, true);
if(count == 1)
{
Format(filter, PLATFORM_MAX_PATH, "%s", first);
return true;
}
return false;
}
public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_Select:
{
static char map[PLATFORM_MAX_PATH];
GetMenuItem(menu, param2, map, sizeof(map));
if(!CanClientNominate(param1)) return 0;
if(g_iClientNomDelay[param1] > GetTime())
{
CPrintToChat(param1, "%t %t", "NPrefix", "Wait to nominate", g_iClientNomDelay[param1] - GetTime());
return 0;
}
CanNominateResult canNom = CanNominate(param1);
if(canNom != CanNominate_Yes)
{
switch(canNom)
{
case CanNominate_VoteComplete:
{
CPrintToChat(param1, "%t %t", "NPrefix", "Cannot Nominate - Vote Complete");
}
case CanNominate_VoteInProgress:
{
CPrintToChat(param1, "%t %t", "NPrefix", "Cannot Nominate - Vote In Progress");
}
case CanNominate_VoteFull:
{
CPrintToChat(param1, "%t %t", "NPrefix", "Cannot Nominate - Vote Full");
}
}
return 0;
}
int status = CanMapBeNominated(param1, map);
if((status & CanClientNom_Yes) == CanClientNom_Yes)
{
NominateResult result = NominateMap(param1, map, false);
//Successful nomination prints in OnMapNominated
if(result == Nominate_InvalidMap)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Map was not found", map);
}
else if(result == Nominate_VoteFull)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Vote Full");
}
return 0;
}
/*
Map cannot be nominated - Lets tell the client why
These should VERY rarely be seen since items are disabled on menu creation
*/
if((status & CanClientNom_CurrentMap) == CanClientNom_CurrentMap)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Current map");
return 0;
}
if((status & CanClientNom_CurrentNom) == CanClientNom_CurrentNom)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Current nomination", map);
return 0;
}
if((status & CanClientNom_Inserted) == CanClientNom_Inserted)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Already Inserted", map);
return 0;
}
if((status & CanClientNom_Nominated) == CanClientNom_Nominated)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Already Nominated", map);
return 0;
}
if((status & CanClientNom_AdminOnly) == CanClientNom_AdminOnly)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Admin Only Nominating", map);
return 0;
}
if((status & CanClientNom_Cooldown) == CanClientNom_Cooldown)
{
if(g_cv_ShowCooldown.BoolValue)
{
CPrintToChat(param1, "%t %t", "NPrefix", "Map is on cooldown", map, GetMapCooldown(map));
}
else
{
CPrintToChat(param1, "%t %t", "NPrefix", "Map is on cooldown - No Value", map);
}
return 0;
}
if((status & CanClientNom_NotEnoughPlayers) == CanClientNom_NotEnoughPlayers)
{
int players = GetMapPlayerRestriction(map) * -1;
CPrintToChat(param1, "%t %t", "NPrefix", "Map needs more players", map, players);
return 0;
}
if((status & CanClientNom_TooManyPlayers) == CanClientNom_TooManyPlayers)
{
int players = GetMapPlayerRestriction(map) * -1;
CPrintToChat(param1, "%t %t", "NPrefix", "Map needs more players", map, players);
return 0;
}
if((status & CanClientNom_Time) == CanClientNom_Time)