summaryrefslogtreecommitdiff
path: root/retakes_weaponallocator.sp
blob: 52909005e6bfdde5cce52878498f575e21c299f4 (plain)
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
#include <sourcemod>
#include <cstrike>
#include <clientprefs>
#include "include/retakes.inc"
#include "retakes/generic.sp"

#pragma semicolon 1
#pragma newdecls required

#define MENU_TIME_LENGTH 15

const int money_for_competitive_pistol_round = 800;

const int rifle_choice_ct_famas = 1;
const int rifle_choice_ct_m4a4 = 2;
const int rifle_choice_ct_m4a1_s = 3;
const int rifle_choice_ct_aug = 4;
const int rifle_choice_ct_ssg08 = 5;
const int rifle_choice_ct_mp9 = 6;
const int rifle_choice_ct_mp7 = 7;
const int rifle_choice_ct_ump45 = 8;
const int rifle_choice_ct_p90 = 9;
const int rifle_choice_ct_bizon = 10;
const int rifle_choice_ct_nova = 11;
const int rifle_choice_ct_xm1014 = 12;
const int rifle_choice_ct_mag7 = 13;
const int rifle_choice_ct_m249 = 14;
const int rifle_choice_ct_negev = 15;
const int rifle_choice_ct_random = 99;

const int rifle_choice_t_galil = 1;
const int rifle_choice_t_ak47 = 2;
const int rifle_choice_t_sg553 = 3;
const int rifle_choice_t_ssg08 = 4;
const int rifle_choice_t_mac10 = 5;
const int rifle_choice_t_mp7 = 6;
const int rifle_choice_t_ump45 = 7;
const int rifle_choice_t_p90 = 8;
const int rifle_choice_t_bizon = 9;
const int rifle_choice_t_nova = 10;
const int rifle_choice_t_xm1014 = 11;
const int rifle_choice_t_sawedoff = 12;
const int rifle_choice_t_m249 = 13;
const int rifle_choice_t_negev = 14;
const int rifle_choice_t_random = 99;

const int pistol_choice_ct_hkp2000 = 1;
const int pistol_choice_ct_usp = 7;
const int pistol_choice_ct_p250 = 2;
const int pistol_choice_ct_fiveseven = 3;
const int pistol_choice_ct_cz = 4;
const int pistol_choice_ct_deagle = 5;
const int pistol_choice_ct_r8 = 6;
const int pistol_choice_ct_dualies = 8;
const int pistol_choice_ct_random = 99;

const int pistol_choice_t_glock = 1;
const int pistol_choice_t_p250 = 2;
const int pistol_choice_t_tec9 = 3;
const int pistol_choice_t_cz = 4;
const int pistol_choice_t_deagle = 5;
const int pistol_choice_t_r8 = 6;
const int pistol_choice_t_dualies = 7;
const int pistol_choice_t_random = 99;

const int nade_price_for_hegrenade = 300;
const int nade_price_for_flashbang = 200;
const int nade_price_for_smokegrenade = 300;
const int nade_price_for_molotov = 400;
const int nade_price_for_incgrenade = 600;

const int gun_price_for_p250 = 300;
const int gun_price_for_cz = 500;
const int gun_price_for_fiveseven = 500;
const int gun_price_for_tec9 = 500;
const int gun_price_for_deagle = 700;
const int gun_price_for_r8 = 600;
const int gun_price_for_dualies = 300;

const int kit_price = 400;
const int kevlar_price = 650;

int g_PistolRchoiceCT[MAXPLAYERS+1];
int g_PistolRchoiceT[MAXPLAYERS+1];
int g_PistolchoiceCT[MAXPLAYERS+1];
int g_PistolchoiceT[MAXPLAYERS+1];
int g_RifleChoiceCT[MAXPLAYERS+1];
int g_RifleChoiceT[MAXPLAYERS+1];
bool g_AwpChoiceT[MAXPLAYERS+1];
bool g_AwpChoiceCT[MAXPLAYERS+1];
int g_side[MAXPLAYERS+1];
Handle g_hPISTOLRChoiceCookieCT = INVALID_HANDLE;
Handle g_hPISTOLRChoiceCookieT = INVALID_HANDLE;
Handle g_hGUNChoiceCookieCT = INVALID_HANDLE;
Handle g_hGUNChoiceCookieT = INVALID_HANDLE;
Handle g_hRifleChoiceCookieCT = INVALID_HANDLE;
Handle g_hRifleChoiceCookieT = INVALID_HANDLE;
Handle g_hAwpChoiceCookieCT = INVALID_HANDLE;
Handle g_hAwpChoiceCookieT = INVALID_HANDLE;

Handle g_h_sm_retakes_weapon_mimic_competitive_pistol_rounds = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_primary_enabled = INVALID_HANDLE;

Handle g_h_sm_retakes_weapon_nades_enabled = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_hegrenade_ct_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_hegrenade_t_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_flashbang_ct_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_flashbang_t_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_smokegrenade_ct_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_smokegrenade_t_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_molotov_ct_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_nades_molotov_t_max = INVALID_HANDLE;

Handle g_h_sm_retakes_weapon_helmet_enabled = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_kevlar_enabled = INVALID_HANDLE;

Handle g_h_sm_retakes_weapon_awp_team_max = INVALID_HANDLE;
Handle g_h_sm_retakes_weapon_pistolrounds  = INVALID_HANDLE;

Handle g_h_sm_retakes_weapon_allow_nades_on_pistol_rounds = INVALID_HANDLE;

Handle g_h_sm_retakes_kevlar_probability_on_comp_pistol_rounds = INVALID_HANDLE;
Handle g_h_sm_retakes_defusekit_probability_on_comp_pistol_rounds = INVALID_HANDLE;

Handle g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kev = INVALID_HANDLE;
Handle g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kit = INVALID_HANDLE;
Handle g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_nad = INVALID_HANDLE;

int nades_hegrenade_ct_max = 0;
int nades_hegrenade_t_max = 0;
int nades_flashbang_ct_max = 0;
int nades_flashbang_t_max = 0;
int nades_smokegrenade_ct_max = 0;
int nades_smokegrenade_t_max = 0;
int nades_molotov_ct_max = 0;
int nades_molotov_t_max = 0;

int dollars_for_mimic_competitive_pistol_rounds;

public Plugin myinfo = {
  name = "CS:GO Retakes: Customised Weapon Allocator for splewis retakes plugin",
  author = "BatMen and tmercswims, modified by enghausen",
  description = "Defines convars to customize weapon allocator of splewis retakes plugin",
  version = PLUGIN_VERSION,
  url = "https://github.com/enghausen/csgo-retakes-splewis-convar-weapon-allocator"
};

public void OnPluginStart() {
  g_hPISTOLRChoiceCookieCT = RegClientCookie("retakes_pistolrchoice_ct", "", CookieAccess_Private);
  g_hPISTOLRChoiceCookieT = RegClientCookie("retakes_pistolrchoice_t", "", CookieAccess_Private);
  g_hGUNChoiceCookieCT = RegClientCookie("retakes_pistolchoice_ct", "", CookieAccess_Private);
  g_hGUNChoiceCookieT = RegClientCookie("retakes_pistolchoice_t", "", CookieAccess_Private);
  g_hRifleChoiceCookieCT  = RegClientCookie("retakes_riflechoice_ct", "", CookieAccess_Private);
  g_hRifleChoiceCookieT  = RegClientCookie("retakes_riflechoice_t", "", CookieAccess_Private);
  g_hAwpChoiceCookieCT = RegClientCookie("retakes_awpchoice_ct", "", CookieAccess_Private);
  g_hAwpChoiceCookieT = RegClientCookie("retakes_awpchoice_t", "", CookieAccess_Private);

  g_h_sm_retakes_weapon_pistolrounds = CreateConVar("sm_retakes_weapon_pistolrounds", "5", "The number of gun rounds (0 = no gun round)");
  g_h_sm_retakes_weapon_mimic_competitive_pistol_rounds = CreateConVar("sm_retakes_weapon_mimic_competitive_pistol_rounds", "1", "Whether pistol rounds are like 800$ rounds");
  g_h_sm_retakes_weapon_primary_enabled = CreateConVar("sm_retakes_weapon_primary_enabled", "1", "Whether the players can have primary weapon");

  g_h_sm_retakes_weapon_nades_enabled = CreateConVar("sm_retakes_weapon_nades_enabled", "1", "Whether the players can have nades");
  g_h_sm_retakes_weapon_allow_nades_on_pistol_rounds = CreateConVar("sm_retakes_weapon_allow_nades_on_pistol_rounds", "1", "Whether the players can have nades on pistol rounds");
  g_h_sm_retakes_weapon_nades_hegrenade_ct_max = CreateConVar("sm_retakes_weapon_nades_hegrenade_ct_max", "1", "Number of hegrenade CT team can have");
  g_h_sm_retakes_weapon_nades_hegrenade_t_max = CreateConVar("sm_retakes_weapon_nades_hegrenade_t_max", "1", "Number of hegrenade T team can have");
  g_h_sm_retakes_weapon_nades_flashbang_ct_max = CreateConVar("sm_retakes_weapon_nades_flashbang_ct_max", "1", "Number of flashbang CT team can have");
  g_h_sm_retakes_weapon_nades_flashbang_t_max = CreateConVar("sm_retakes_weapon_nades_flashbang_t_max", "1", "Number of flashbang T team can have");
  g_h_sm_retakes_weapon_nades_smokegrenade_ct_max = CreateConVar("sm_retakes_weapon_nades_smokegrenade_ct_max", "1", "Number of smokegrenade CT team can have");
  g_h_sm_retakes_weapon_nades_smokegrenade_t_max = CreateConVar("sm_retakes_weapon_nades_smokegrenade_t_max", "1", "Number of smokegrenade T team can have");
  g_h_sm_retakes_weapon_nades_molotov_ct_max = CreateConVar("sm_retakes_weapon_nades_molotov_ct_max", "1", "Number of molotov CT team can have");
  g_h_sm_retakes_weapon_nades_molotov_t_max = CreateConVar("sm_retakes_weapon_nades_molotov_t_max", "1", "Number of molotov T team can have");

  g_h_sm_retakes_weapon_helmet_enabled = CreateConVar("sm_retakes_weapon_helmet_enabled", "1", "Whether the players have helmet");
  g_h_sm_retakes_weapon_kevlar_enabled = CreateConVar("sm_retakes_weapon_kevlar_enabled", "1", "Whether the players have kevlar");
  g_h_sm_retakes_weapon_awp_team_max = CreateConVar("sm_retakes_weapon_awp_team_max", "1", "The max number of AWP per team (0 = no awp)");

  g_h_sm_retakes_kevlar_probability_on_comp_pistol_rounds = CreateConVar("sm_retakes_kevlar_probability_on_competitive_pistol_rounds", "6", "The probability to get kevlar for each player on competitive pistol rounds. Between 0 to 10. 0 = never, 10 = always");
  g_h_sm_retakes_defusekit_probability_on_comp_pistol_rounds = CreateConVar("sm_retakes_defusekit_probability_on_competitive_pistol_rounds", "6", "The probability to get defusal kit for each player on competitive pistol rounds. Between 0 to 10. 0 = never, 10 = always");

  g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kev = CreateConVar("sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kev", "1", "The relative priority to have kevlar against kit/nade. Between 1 to 3. Default 1 (first).");
  g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kit = CreateConVar("sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kit", "2", "The relative priority to have kit against kevlar/nade. Between 1 to 3. Default 2 (second).");
  g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_nad = CreateConVar("sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_nad", "3", "The relative priority to have nade against kevlar/kit. Between 1 to 3. Default 3 (third).");
}

public void OnClientConnected(int client) {
  g_PistolRchoiceCT[client] = pistol_choice_ct_hkp2000;
  g_PistolchoiceCT[client] = pistol_choice_ct_hkp2000;
  g_PistolchoiceT[client] = pistol_choice_t_glock;
  g_PistolRchoiceT[client] = pistol_choice_t_glock;
  g_RifleChoiceCT[client] = rifle_choice_ct_m4a4;
  g_RifleChoiceT[client] = rifle_choice_t_ak47;
  g_side[client] = 0;
  g_AwpChoiceT[client] = false;
  g_AwpChoiceCT[client] = false;
}

public void Retakes_OnGunsCommand(int client) {
  // on est pas T only
  if (g_side[client] != 1)
    GivePistolRMenuCT(client);
  else
    GivePistolRMenuT(client);
}

public void Retakes_OnWeaponsAllocated(ArrayList tPlayers, ArrayList ctPlayers, Bombsite bombsite) {
  WeaponAllocator(tPlayers, ctPlayers, bombsite);
}

/**
 * Updates client weapon settings according to their cookies.
 */
public void OnClientCookiesCached(int client) {
  if (IsFakeClient(client))
    return;

  g_PistolRchoiceCT[client]  = GetCookieInt(client, g_hPISTOLRChoiceCookieCT);
  g_PistolRchoiceT[client]  = GetCookieInt(client, g_hPISTOLRChoiceCookieT);
  g_PistolchoiceCT[client]  = GetCookieInt(client, g_hGUNChoiceCookieCT);
  g_PistolchoiceT[client]  = GetCookieInt(client, g_hGUNChoiceCookieT);
  g_RifleChoiceCT[client] = GetCookieInt(client, g_hRifleChoiceCookieCT);
  g_RifleChoiceT[client] = GetCookieInt(client, g_hRifleChoiceCookieT);
  g_AwpChoiceCT[client]  = GetCookieBool(client, g_hAwpChoiceCookieCT);
  g_AwpChoiceT[client]  = GetCookieBool(client, g_hAwpChoiceCookieT);
}

static void SetNades(char nades[NADE_STRING_LENGTH], bool terrorist, bool competitivePistolRound) {
  nades = "";
  if (competitivePistolRound && GetConVarInt(g_h_sm_retakes_weapon_allow_nades_on_pistol_rounds)  != 1)
    return;
  if (GetConVarInt(g_h_sm_retakes_weapon_nades_enabled) == 1)
  {
    int max_hegrenade_allow = terrorist ? GetConVarInt(g_h_sm_retakes_weapon_nades_hegrenade_t_max) : GetConVarInt(g_h_sm_retakes_weapon_nades_hegrenade_ct_max);
    int max_flashbang_allow = terrorist ? GetConVarInt(g_h_sm_retakes_weapon_nades_flashbang_t_max) : GetConVarInt(g_h_sm_retakes_weapon_nades_flashbang_ct_max);
    int max_smokegrenade_allow = terrorist ? GetConVarInt(g_h_sm_retakes_weapon_nades_smokegrenade_t_max) : GetConVarInt(g_h_sm_retakes_weapon_nades_smokegrenade_ct_max);
    int max_molotov_allow = terrorist ? GetConVarInt(g_h_sm_retakes_weapon_nades_molotov_t_max) : GetConVarInt(g_h_sm_retakes_weapon_nades_molotov_ct_max);

    int he_number = 0;
    int smoke_number = 0;
    int flashbang_number = 0;
    int molotov_number = 0;

    int maxgrenades = GetConVarInt(FindConVar("ammo_grenade_limit_total"));
    int maxflashbang = GetConVarInt(FindConVar("ammo_grenade_limit_flashbang"));

    int rand;
    int indice = 0;
    // be sure to spend all the money on pistol rounds
    for(int i=0; i < 10; i++)
    {
      rand = GetRandomInt(1, 4);

      if (competitivePistolRound)
      {
        // no money for molotov
        if ( rand == 4 && (
              (terrorist && dollars_for_mimic_competitive_pistol_rounds < nade_price_for_molotov) ||
              (!terrorist && dollars_for_mimic_competitive_pistol_rounds < nade_price_for_incgrenade) ) )
          rand = GetRandomInt(1, 3);
        // no money for smoke or hegrenade
        if (rand != 3 && dollars_for_mimic_competitive_pistol_rounds < nade_price_for_hegrenade)
          rand = 3;
        // no money for flashbang
        if (dollars_for_mimic_competitive_pistol_rounds < nade_price_for_flashbang)
          break;
      }

      if (maxgrenades <= indice)
        break;

      if (!competitivePistolRound && indice >= 2)
        break;

      switch(rand) {
        case 1:
          if ((terrorist ? nades_hegrenade_t_max : nades_hegrenade_ct_max) < max_hegrenade_allow && he_number == 0)
          {
            nades[indice] = 'h';
            dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - nade_price_for_hegrenade;
            indice++;
            he_number++;
            if (terrorist)
              nades_hegrenade_t_max++;
            else
              nades_hegrenade_ct_max++;
          }
        case 2:
          if ((terrorist ? nades_smokegrenade_t_max : nades_smokegrenade_ct_max) < max_smokegrenade_allow && smoke_number == 0)
          {
            nades[indice] = 's';
            dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - nade_price_for_smokegrenade;
            indice++;
            smoke_number++;
            if (terrorist)
              nades_smokegrenade_t_max++;
            else
              nades_smokegrenade_ct_max++;
          }
        case 3:
          if ((terrorist ? nades_flashbang_t_max : nades_flashbang_ct_max) < max_flashbang_allow && flashbang_number < maxflashbang)
          {
            nades[indice] = 'f';
            dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - nade_price_for_flashbang;
            indice++;
            flashbang_number++;
            if (terrorist)
              nades_flashbang_t_max++;
            else
              nades_flashbang_ct_max++;
          }
        case 4:
          if ((terrorist ? nades_molotov_t_max : nades_molotov_ct_max) < max_molotov_allow && molotov_number == 0)
          {
            nades[indice] = terrorist ? 'm' : 'i';
            if (terrorist)
              dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - nade_price_for_molotov;
            else
              dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - nade_price_for_incgrenade;
            indice++;
            molotov_number++;
            if (terrorist)
              nades_molotov_t_max++;
            else
              nades_molotov_ct_max++;
          }
      }
    }
  }
}

public void WeaponAllocator(ArrayList tPlayers, ArrayList ctPlayers, Bombsite bombsite) {
  int tCount = GetArraySize(tPlayers);
  int ctCount = GetArraySize(ctPlayers);

  bool isPistolRound = GetConVarInt(g_h_sm_retakes_weapon_primary_enabled) == 0 || Retakes_GetRetakeRoundsPlayed() < GetConVarInt(g_h_sm_retakes_weapon_pistolrounds);
  bool mimicCompetitivePistolRounds = GetConVarInt(g_h_sm_retakes_weapon_mimic_competitive_pistol_rounds) == 1;

  char primary[WEAPON_STRING_LENGTH];
  char secondary[WEAPON_STRING_LENGTH];
  char nades[NADE_STRING_LENGTH];

  int health = 100;
  int kevlar = 100;
  bool helmet = true;
  bool kit = true;

  nades_hegrenade_ct_max = 0;
  nades_hegrenade_t_max = 0;
  nades_smokegrenade_ct_max = 0;
  nades_smokegrenade_t_max = 0;
  nades_flashbang_ct_max = 0;
  nades_flashbang_t_max = 0;
  nades_molotov_ct_max = 0;
  nades_molotov_t_max = 0;

  bool giveTAwp = true;
  bool giveCTAwp = true;
  if (GetConVarInt(g_h_sm_retakes_weapon_awp_team_max) < 1)
  {
    giveTAwp = false;
    giveCTAwp = false;
  }

  int awp_given = 0;
  int[] treatedT = new int[tCount];
  for (int i = 0; i < tCount; i++) {

    // dynamic array which contains all the players'number for whom we don't already give weapons, take a random new one
    // we don't treat players in the same order for each round. More equity to have AWP and nades
    int[] NotTreatedT = new int[tCount - i];
    for(int iNotTreated=0; iNotTreated < (tCount - i); iNotTreated++)
    {
      for (int candidate = 0; candidate < tCount; candidate++)
      {
        bool alreadyTreated = false;
        for (int iTreated = 0; iTreated < i; iTreated++)
        {
          if (treatedT[iTreated] == candidate)
          {
            alreadyTreated = true;
            break;
          }
        }
        if (!alreadyTreated)
          NotTreatedT[iNotTreated] = candidate;
      }
    }
    int pick = GetRandomInt(0, tCount - i - 1);
    int playerPick = NotTreatedT[pick];
    treatedT[i] = playerPick;

    int client = GetArrayCell(tPlayers, playerPick);

    g_side[client] = 1;

    dollars_for_mimic_competitive_pistol_rounds = money_for_competitive_pistol_round;

    primary = "";
    if (!isPistolRound)
    {
      int randGiveAwp = GetRandomInt(0, 4);

      if (giveTAwp && g_AwpChoiceT[client] && randGiveAwp == 1 && awp_given < GetConVarInt(g_h_sm_retakes_weapon_awp_team_max)) {
        primary = "weapon_awp";
        giveTAwp = false;
        awp_given = awp_given + 1;
      } else {
        int rifle_choice_t = g_RifleChoiceT[client];
        if(rifle_choice_t == rifle_choice_t_random) {
          rifle_choice_t = GetRandomInt(1,14);
        }
        primary = "weapon_ak47";
        switch(rifle_choice_t)
        {
          case rifle_choice_t_galil:
            primary = "weapon_galilar";
          case rifle_choice_t_sg553:
            primary = "weapon_sg556";
          case rifle_choice_t_ssg08:
            primary = "weapon_ssg08";
          case rifle_choice_t_mac10:
            primary = "weapon_mac10";
          case rifle_choice_t_mp7:
            primary = "weapon_mp7";
          case rifle_choice_t_ump45:
            primary = "weapon_ump45";
          case rifle_choice_t_p90:
            primary = "weapon_p90";
          case rifle_choice_t_bizon:
            primary = "weapon_bizon";
          case rifle_choice_t_nova:
            primary = "weapon_nova";
          case rifle_choice_t_xm1014:
            primary = "weapon_xm1014";
          case rifle_choice_t_sawedoff:
            primary = "weapon_sawedoff";
          case rifle_choice_t_m249:
            primary = "weapon_m249";
          case rifle_choice_t_negev:
            primary = "weapon_negev";
          default:
            primary = "weapon_ak47";
        }
      }
    }

    int pistol_choice_t = g_PistolchoiceT[client]; // Round choice
    if (isPistolRound) {
      pistol_choice_t = g_PistolRchoiceT[client]; // Pistol round choice
    }
    if (pistol_choice_t == pistol_choice_t_random) {
      pistol_choice_t = GetRandomInt(1,7);
    }
    switch(pistol_choice_t)
    {
      case pistol_choice_t_p250:
        {
          secondary = "weapon_p250";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_p250;
        }
      case pistol_choice_t_tec9:
        {
          secondary = "weapon_tec9";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_tec9;
        }
      case pistol_choice_t_cz:
        {
          secondary = "weapon_cz75a";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_cz;
        }
      case pistol_choice_t_deagle:
        {
          secondary = "weapon_deagle";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_deagle;
        }
      case pistol_choice_t_r8:
        {
          secondary = "weapon_revolver";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_r8;
        }
      case pistol_choice_t_dualies:
        {
          secondary = "weapon_elite";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_dualies;
        }
      default:
        secondary = "weapon_glock";
    }

    health = 100;

    if (GetConVarInt(g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kev) <= GetConVarInt(g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_nad))
    {
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
      SetNades(nades, true, mimicCompetitivePistolRounds && isPistolRound);
    }
    else
    {
      SetNades(nades, true, mimicCompetitivePistolRounds && isPistolRound);
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
    }

    helmet = true;
    if (GetConVarInt(g_h_sm_retakes_weapon_helmet_enabled) != 1 || kevlar == 0 || (isPistolRound && mimicCompetitivePistolRounds))
      helmet = false;

    kit = false;

    Retakes_SetPlayerInfo(client, primary, secondary, nades, health, kevlar, helmet, kit);
  }

  awp_given = 0;
  int[] treatedCT = new int[ctCount];
  for (int i = 0; i < ctCount; i++) {

    // dynamic array which contains all the players'number for whom we don't already give weapons, take a random new one
    // we don't treat players in the same order for each round. More equity to have AWP and nades
    int[] NotTreatedCT = new int[ctCount - i];
    for(int iNotTreated=0; iNotTreated < (ctCount - i); iNotTreated++)
    {
      for (int candidate = 0; candidate < ctCount; candidate++)
      {
        bool alreadyTreated = false;
        for (int iTreated = 0; iTreated < i; iTreated++)
        {
          if (treatedCT[iTreated] == candidate)
          {
            alreadyTreated = true;
            break;
          }
        }
        if (!alreadyTreated)
          NotTreatedCT[iNotTreated] = candidate;
      }
    }
    int pick = GetRandomInt(0, ctCount - i - 1);
    int playerPick = NotTreatedCT[pick];
    treatedCT[i] = playerPick;

    int client = GetArrayCell(ctPlayers, playerPick);

    g_side[client] = 2;

    dollars_for_mimic_competitive_pistol_rounds = money_for_competitive_pistol_round;

    primary = "";
    if (!isPistolRound)
    {
      int randGiveAwp = GetRandomInt(0, 3);

      if (giveCTAwp && g_AwpChoiceCT[client] && randGiveAwp == 1 && awp_given < GetConVarInt(g_h_sm_retakes_weapon_awp_team_max)) {
        primary = "weapon_awp";
        giveCTAwp = false;
        awp_given = awp_given + 1;
      } else {
        int rifle_choice_ct = g_RifleChoiceCT[client];
        if (rifle_choice_ct == rifle_choice_ct_random) {
          rifle_choice_ct = GetRandomInt(1,15);
        }
        switch(rifle_choice_ct)
        {
          case rifle_choice_ct_famas:
            primary = "weapon_famas";
          case rifle_choice_ct_m4a1_s:
            primary = "weapon_m4a1_silencer";
          case rifle_choice_ct_aug:
            primary = "weapon_aug";
          case rifle_choice_ct_ssg08:
            primary = "weapon_ssg08";
          case rifle_choice_ct_mp9:
            primary = "weapon_mp9";
          case rifle_choice_ct_mp7:
            primary = "weapon_mp7";
          case rifle_choice_ct_ump45:
            primary = "weapon_ump45";
          case rifle_choice_ct_p90:
            primary = "weapon_p90";
          case rifle_choice_ct_bizon:
            primary = "weapon_bizon";
          case rifle_choice_ct_nova:
            primary = "weapon_nova";
          case rifle_choice_ct_xm1014:
            primary = "weapon_xm1014";
          case rifle_choice_ct_mag7:
            primary = "weapon_mag7";
          case rifle_choice_ct_m249:
            primary = "weapon_m249";
          case rifle_choice_ct_negev:
            primary = "weapon_negev";
          default:
            primary = "weapon_m4a1";
        }
      }
    }

    int pistol_choice_ct = g_PistolchoiceCT[client]; // Round choice
    if (isPistolRound) {
      pistol_choice_ct = g_PistolRchoiceCT[client]; // Pistol round choice
    }
    if (pistol_choice_ct == pistol_choice_ct_random) {
      pistol_choice_ct = GetRandomInt(1,8);
    }

    switch(pistol_choice_ct)
    {
      case pistol_choice_ct_p250:
        {
          secondary = "weapon_p250";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_p250;
        }
      case pistol_choice_ct_fiveseven:
        {
          secondary = "weapon_fiveseven";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_fiveseven;
        }
      case pistol_choice_ct_cz:
        {
          secondary = "weapon_cz75a";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_cz;
        }
      case pistol_choice_ct_deagle:
        {
          secondary = "weapon_deagle";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_deagle;
        }
      case pistol_choice_ct_r8:
        {
          secondary = "weapon_revolver";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_r8;
        }
      case pistol_choice_ct_dualies:
        {
          secondary = "weapon_elite";
          dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - gun_price_for_dualies;
        }
      case pistol_choice_ct_usp:
        secondary = "weapon_usp_silencer";
      default:
        secondary = "weapon_hkp2000";
    }

    health = 100;
    int kit_priority = GetConVarInt(g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kit);
    int kev_priority = GetConVarInt(g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_kev);
    int nad_priority = GetConVarInt(g_h_sm_retakes_kev_kit_nad_priority_on_comp_pistol_rounds_nad);
    bool call_kit = false;
    bool call_kev = false;
    bool call_nad = false;
    if (kev_priority == 1 && !call_kev)
    {
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
      call_kev = true;
    }
    else if (kit_priority == 1 && !call_kit)
    {
      kit = getkit(mimicCompetitivePistolRounds, isPistolRound);
      call_kit = true;
    }
    else if (nad_priority == 1 && !call_nad)
    {
      SetNades(nades, false, mimicCompetitivePistolRounds && isPistolRound);
      call_nad = true;
    }

    if (kev_priority == 2 && !call_kev)
    {
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
      call_kev = true;
    }
    else if (kit_priority == 2 && !call_kit)
    {
      kit = getkit(mimicCompetitivePistolRounds, isPistolRound);
      call_kit = true;
    }
    else if (nad_priority == 2 && !call_nad)
    {
      SetNades(nades, false, mimicCompetitivePistolRounds && isPistolRound);
      call_nad = true;
    }

    if (kev_priority == 3 && !call_kev)
    {
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
      call_kev = true;
    }
    else if (kit_priority == 3 && !call_kit)
    {
      kit = getkit(mimicCompetitivePistolRounds, isPistolRound);
      call_kit = true;
    }
    else if (nad_priority == 3 && !call_nad)
    {
      SetNades(nades, false, mimicCompetitivePistolRounds && isPistolRound);
      call_nad = true;
    }

    // if server does not set exactly 1, 2, 3 on priority vars, we have to call them in default order
    if (!call_kev)
      kevlar = getkevlar(mimicCompetitivePistolRounds, isPistolRound);
    if (!call_kit)
      kit = getkit(mimicCompetitivePistolRounds, isPistolRound);
    if (!call_nad)
      SetNades(nades, false, mimicCompetitivePistolRounds && isPistolRound);

    helmet = true;
    if (GetConVarInt(g_h_sm_retakes_weapon_helmet_enabled) != 1 || kevlar == 0 || (isPistolRound && mimicCompetitivePistolRounds))
      helmet = false;

    if (!isPistolRound || (isPistolRound && !mimicCompetitivePistolRounds))
      kit = true;

    Retakes_SetPlayerInfo(client, primary, secondary, nades, health, kevlar, helmet, kit);
  }
}

public int getkevlar(bool mimicCompetitivePistolRounds, bool isPistolRound)
{
  int odds;
  int kevlar = 100;
  if (GetConVarInt(g_h_sm_retakes_weapon_kevlar_enabled) != 1)
  {
    kevlar = 0;
  }
  else if (mimicCompetitivePistolRounds && isPistolRound)
  {
    kevlar = 0;
    if (dollars_for_mimic_competitive_pistol_rounds >= kevlar_price)
    {
      odds = GetRandomInt(0,10);
      // percentage between 0% to 100% to have kevlar if money
      if (odds <= GetConVarInt(g_h_sm_retakes_kevlar_probability_on_comp_pistol_rounds))
      {
        kevlar = 100;
        dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - kevlar_price;
      }
    }
  }
  return kevlar;
}

public bool getkit(bool mimicCompetitivePistolRounds, bool isPistolRound)
{
  int odds;
  bool kit = false;
  if(dollars_for_mimic_competitive_pistol_rounds >= kit_price && isPistolRound && mimicCompetitivePistolRounds)
  {
    odds = GetRandomInt(0,10);
    // percentage between 0% to 100% to get kit if money before nades
    if (odds <= GetConVarInt(g_h_sm_retakes_defusekit_probability_on_comp_pistol_rounds))
    {
      kit = true;
      dollars_for_mimic_competitive_pistol_rounds = dollars_for_mimic_competitive_pistol_rounds - kit_price;
    }
  }
  return kit;
}

public void GivePistolRMenuCT(int client) {
  Menu menu = CreateMenu(MenuHandler_PISTOLR_CT);
  SetMenuTitle(menu, "Select a CT pistol round pistol:");
  AddMenuInt(menu, pistol_choice_ct_hkp2000, "P2000");
  AddMenuInt(menu, pistol_choice_ct_usp, "USP-S");
  AddMenuInt(menu, pistol_choice_ct_p250, "P250");
  AddMenuInt(menu, pistol_choice_ct_fiveseven, "Five-Seven");
  AddMenuInt(menu, pistol_choice_ct_cz, "CZ75-Auto");
  AddMenuInt(menu, pistol_choice_ct_deagle, "Desert Eagle");
  AddMenuInt(menu, pistol_choice_ct_r8, "R8 Revolver");
  AddMenuInt(menu, pistol_choice_ct_dualies, "Dual Berettas");
  AddMenuInt(menu, pistol_choice_ct_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public void GivePistolRMenuT(int client) {
  Menu menu = CreateMenu(MenuHandler_PISTOLR_T);
  SetMenuTitle(menu, "Select a T pistol round pistol:");
  AddMenuInt(menu, pistol_choice_t_glock, "Glock");
  AddMenuInt(menu, pistol_choice_t_p250, "P250");
  AddMenuInt(menu, pistol_choice_t_tec9, "Tec-9");
  AddMenuInt(menu, pistol_choice_t_cz, "CZ75-Auto");
  AddMenuInt(menu, pistol_choice_t_deagle, "Desert Eagle");
  AddMenuInt(menu, pistol_choice_t_r8, "R8 Revolver");
  AddMenuInt(menu, pistol_choice_t_dualies, "Dual Berettas");
  AddMenuInt(menu, pistol_choice_t_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public int MenuHandler_PISTOLR_CT(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int gunchoice = GetMenuInt(menu, param2);
    g_PistolRchoiceCT[client] = gunchoice;
    SetCookieInt(client, g_hPISTOLRChoiceCookieCT, gunchoice);
    // on est pas CT only
    if (g_side[client] != 2)
      GivePistolRMenuT(client);
    else
      GivePistolMenuCT(client);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public int MenuHandler_PISTOLR_T(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int gunchoice = GetMenuInt(menu, param2);
    g_PistolRchoiceT[client] = gunchoice;
    SetCookieInt(client, g_hPISTOLRChoiceCookieT, gunchoice);
    // on est pas T only
    if (g_side[client] != 1)
      GivePistolMenuCT(client);
    else
      GivePistolMenuT(client);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public void GivePistolMenuCT(int client) {
  Menu menu = CreateMenu(MenuHandler_PISTOL_CT);
  SetMenuTitle(menu, "Select a CT gun round pistol:");
  AddMenuInt(menu, pistol_choice_ct_hkp2000, "P2000");
  AddMenuInt(menu, pistol_choice_ct_usp, "USP-S");
  AddMenuInt(menu, pistol_choice_ct_p250, "P250");
  AddMenuInt(menu, pistol_choice_ct_fiveseven, "Five-Seven");
  AddMenuInt(menu, pistol_choice_ct_cz, "CZ75-Auto");
  AddMenuInt(menu, pistol_choice_ct_deagle, "Desert Eagle");
  AddMenuInt(menu, pistol_choice_ct_r8, "R8 Revolver");
  AddMenuInt(menu, pistol_choice_ct_dualies, "Dual Berettas");
  AddMenuInt(menu, pistol_choice_ct_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public void GivePistolMenuT(int client) {
  Menu menu = CreateMenu(MenuHandler_PISTOL_T);
  SetMenuTitle(menu, "Select a T gun round pistol:");
  AddMenuInt(menu, pistol_choice_t_glock, "Glock-18");
  AddMenuInt(menu, pistol_choice_t_p250, "P250");
  AddMenuInt(menu, pistol_choice_t_tec9, "Tec-9");
  AddMenuInt(menu, pistol_choice_t_cz, "CZ75-Auto");
  AddMenuInt(menu, pistol_choice_t_deagle, "Desert Eagle");
  AddMenuInt(menu, pistol_choice_t_r8, "R8 Revolver");
  AddMenuInt(menu, pistol_choice_t_dualies, "Dual Berettas");
  AddMenuInt(menu, pistol_choice_t_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public int MenuHandler_PISTOL_CT(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int gunchoice = GetMenuInt(menu, param2);
    g_PistolchoiceCT[client] = gunchoice;
    SetCookieInt(client, g_hGUNChoiceCookieCT, gunchoice);
    // on est pas CT only
    if (g_side[client] != 2)
      GivePistolMenuT(client);
    else
      GiveWeaponMenuCT(client);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public int MenuHandler_PISTOL_T(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int gunchoice = GetMenuInt(menu, param2);
    g_PistolchoiceT[client] = gunchoice;
    SetCookieInt(client, g_hGUNChoiceCookieT, gunchoice);
    // on est pas T only
    if (g_side[client] != 1)
      GiveWeaponMenuCT(client);
    else
      GiveWeaponMenuT(client);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public void GiveWeaponMenuCT(int client) {
  Menu menu = CreateMenu(MenuHandler_RIFLE_CT);
  SetMenuTitle(menu, "Select a CT primary:");
  AddMenuInt(menu, rifle_choice_ct_m4a4, "M4A4");
  AddMenuInt(menu, rifle_choice_ct_m4a1_s, "M4A1-S");
  AddMenuInt(menu, rifle_choice_ct_famas, "FAMAS");
  AddMenuInt(menu, rifle_choice_ct_aug, "AUG");
  AddMenuInt(menu, rifle_choice_ct_ssg08, "SSG 08");
  AddMenuInt(menu, rifle_choice_ct_mp9, "MP9");
  AddMenuInt(menu, rifle_choice_ct_mp7, "MP7");
  AddMenuInt(menu, rifle_choice_ct_ump45, "UMP-45");
  AddMenuInt(menu, rifle_choice_ct_p90, "P90");
  AddMenuInt(menu, rifle_choice_ct_bizon, "PP-Bizon");
  AddMenuInt(menu, rifle_choice_ct_nova, "Nova");
  AddMenuInt(menu, rifle_choice_ct_xm1014, "XM1014");
  AddMenuInt(menu, rifle_choice_ct_mag7, "MAG-7");
  AddMenuInt(menu, rifle_choice_ct_m249, "M249");
  AddMenuInt(menu, rifle_choice_ct_negev, "Negev");
  AddMenuInt(menu, rifle_choice_ct_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public void GiveWeaponMenuT(int client) {
  Menu menu = CreateMenu(MenuHandler_RIFLE_T);
  SetMenuTitle(menu, "Select a T primary:");
  AddMenuInt(menu, rifle_choice_t_ak47, "AK-47");
  AddMenuInt(menu, rifle_choice_t_galil, "Galil AR");
  AddMenuInt(menu, rifle_choice_t_sg553, "SG 553");
  AddMenuInt(menu, rifle_choice_t_ssg08, "SSG 08");
  AddMenuInt(menu, rifle_choice_t_mac10, "MAC-10");
  AddMenuInt(menu, rifle_choice_t_mp7, "MP7");
  AddMenuInt(menu, rifle_choice_t_ump45, "UMP-45");
  AddMenuInt(menu, rifle_choice_t_p90, "P90");
  AddMenuInt(menu, rifle_choice_t_bizon, "PP-Bizon");
  AddMenuInt(menu, rifle_choice_t_nova, "Nova");
  AddMenuInt(menu, rifle_choice_t_xm1014, "XM1014");
  AddMenuInt(menu, rifle_choice_t_sawedoff, "Sawed-Off");
  AddMenuInt(menu, rifle_choice_t_m249, "M249");
  AddMenuInt(menu, rifle_choice_t_negev, "Negev");
  AddMenuInt(menu, rifle_choice_t_random, "Random");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public int MenuHandler_RIFLE_CT(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int riflechoice = GetMenuInt(menu, param2);
    g_RifleChoiceCT[client] = riflechoice;
    SetCookieInt(client, g_hRifleChoiceCookieCT, riflechoice);
    // on est pas CT only
    if (g_side[client] != 2)
      GiveWeaponMenuT(client);
    else if (GetConVarInt(g_h_sm_retakes_weapon_awp_team_max) > 0)
      GiveAwpMenuCT(client);
    else
      CloseHandle(menu);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public int MenuHandler_RIFLE_T(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    int riflechoice = GetMenuInt(menu, param2);
    g_RifleChoiceT[client] = riflechoice;
    SetCookieInt(client, g_hRifleChoiceCookieT, riflechoice);
    if (g_side[client] != 1 && GetConVarInt(g_h_sm_retakes_weapon_awp_team_max) > 0)
      GiveAwpMenuCT(client);
    else if (GetConVarInt(g_h_sm_retakes_weapon_awp_team_max) > 0)
      GiveAwpMenuT(client);
    else
      CloseHandle(menu);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public void GiveAwpMenuCT(int client) {
  Menu menu = CreateMenu(MenuHandler_AWP_CT);
  SetMenuTitle(menu, "Allow yourself to receive AWPs on CT side?");
  AddMenuBool(menu, true, "Yes");
  AddMenuBool(menu, false, "No");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public void GiveAwpMenuT(int client) {
  Menu menu = CreateMenu(MenuHandler_AWP_T);
  SetMenuTitle(menu, "Allow yourself to receive AWPs on T side?");
  AddMenuBool(menu, true, "Yes");
  AddMenuBool(menu, false, "No");
  DisplayMenu(menu, client, MENU_TIME_LENGTH);
}

public int MenuHandler_AWP_CT(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    bool allowAwps = GetMenuBool(menu, param2);
    g_AwpChoiceCT[client] = allowAwps;
    SetCookieBool(client, g_hAwpChoiceCookieCT, allowAwps);
    if (g_side[client] != 2)
      GiveAwpMenuT(client);
    else
      CloseHandle(menu);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}

public int MenuHandler_AWP_T(Menu menu, MenuAction action, int param1, int param2) {
  if (action == MenuAction_Select) {
    int client = param1;
    bool allowAwps = GetMenuBool(menu, param2);
    g_AwpChoiceT[client] = allowAwps;
    SetCookieBool(client, g_hAwpChoiceCookieT, allowAwps);
    CloseHandle(menu);
  } else if (action == MenuAction_End) {
    CloseHandle(menu);
  }
}