-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathMainMenu.cs
904 lines (824 loc) · 39.2 KB
/
MainMenu.cs
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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CitizenFX.Core;
using MenuAPI;
using Newtonsoft.Json;
using vMenuClient.menus;
using static CitizenFX.Core.Native.API;
using static vMenuClient.CommonFunctions;
using static vMenuShared.ConfigManager;
using static vMenuShared.PermissionsManager;
namespace vMenuClient
{
public class MainMenu : BaseScript
{
#region Variables
public static bool PermissionsSetupComplete => ArePermissionsSetup;
public static bool ConfigOptionsSetupComplete = false;
public static string MenuToggleKey { get; private set; } = "M"; // M by default
public static string NoClipKey { get; private set; } = "F2"; // F2 by default
public static Menu Menu { get; private set; }
public static Menu PlayerSubmenu { get; private set; }
public static Menu VehicleSubmenu { get; private set; }
public static Menu WorldSubmenu { get; private set; }
public static PlayerOptions PlayerOptionsMenu { get; private set; }
public static OnlinePlayers OnlinePlayersMenu { get; private set; }
public static BannedPlayers BannedPlayersMenu { get; private set; }
public static SavedVehicles SavedVehiclesMenu { get; private set; }
public static PersonalVehicle PersonalVehicleMenu { get; private set; }
public static VehicleOptions VehicleOptionsMenu { get; private set; }
public static VehicleSpawner VehicleSpawnerMenu { get; private set; }
public static PlayerAppearance PlayerAppearanceMenu { get; private set; }
public static MpPedCustomization MpPedCustomizationMenu { get; private set; }
public static TimeOptions TimeOptionsMenu { get; private set; }
public static WeatherOptions WeatherOptionsMenu { get; private set; }
public static WeaponOptions WeaponOptionsMenu { get; private set; }
public static WeaponLoadouts WeaponLoadoutsMenu { get; private set; }
public static Recording RecordingMenu { get; private set; }
public static MiscSettings MiscSettingsMenu { get; private set; }
public static VoiceChat VoiceChatSettingsMenu { get; private set; }
public static About AboutMenu { get; private set; }
public static bool NoClipEnabled { get { return NoClip.IsNoclipActive(); } set { NoClip.SetNoclipActive(value); } }
public static IPlayerList PlayersList;
public static bool DebugMode = GetResourceMetadata(GetCurrentResourceName(), "client_debug_mode", 0) == "true";
public static bool EnableExperimentalFeatures = (GetResourceMetadata(GetCurrentResourceName(), "experimental_features_enabled", 0) ?? "0") == "1";
public static string Version { get { return GetResourceMetadata(GetCurrentResourceName(), "version", 0); } }
public static bool DontOpenMenus { get { return MenuController.DontOpenAnyMenu; } set { MenuController.DontOpenAnyMenu = value; } }
public static bool DisableControls { get { return MenuController.DisableMenuButtons; } set { MenuController.DisableMenuButtons = value; } }
public static bool MenuEnabled { get; private set; } = true;
private const int currentCleanupVersion = 2;
#endregion
/// <summary>
/// Constructor.
/// </summary>
public MainMenu()
{
PlayersList = new NativePlayerList(Players);
#region cleanup unused kvps
var tmp_kvp_handle = StartFindKvp("");
var cleanupVersionChecked = false;
var tmp_kvp_names = new List<string>();
while (true)
{
var k = FindKvp(tmp_kvp_handle);
if (string.IsNullOrEmpty(k))
{
break;
}
if (k == "vmenu_cleanup_version")
{
if (GetResourceKvpInt("vmenu_cleanup_version") >= currentCleanupVersion)
{
cleanupVersionChecked = true;
}
}
tmp_kvp_names.Add(k);
}
EndFindKvp(tmp_kvp_handle);
if (!cleanupVersionChecked)
{
SetResourceKvpInt("vmenu_cleanup_version", currentCleanupVersion);
foreach (var kvp in tmp_kvp_names)
{
#pragma warning disable CS8793 // The given expression always matches the provided pattern.
if (currentCleanupVersion is 1 or 2)
{
if (!kvp.StartsWith("settings_") && !kvp.StartsWith("vmenu") && !kvp.StartsWith("veh_") && !kvp.StartsWith("ped_") && !kvp.StartsWith("mp_ped_"))
{
DeleteResourceKvp(kvp);
Debug.WriteLine($"[vMenu] [cleanup id: 1] Removed unused (old) KVP: {kvp}.");
}
}
#pragma warning restore CS8793 // The given expression always matches the provided pattern.
if (currentCleanupVersion == 2)
{
if (kvp.StartsWith("mp_char"))
{
DeleteResourceKvp(kvp);
Debug.WriteLine($"[vMenu] [cleanup id: 2] Removed unused (old) KVP: {kvp}.");
}
}
}
Debug.WriteLine("[vMenu] Cleanup of old unused KVP items completed.");
}
#endregion
#region keymapping
string KeyMappingID = String.IsNullOrWhiteSpace(GetSettingsString(Setting.vmenu_keymapping_id)) ? "Default" : GetSettingsString(Setting.vmenu_keymapping_id);
RegisterCommand($"vMenu:{KeyMappingID}:NoClip", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
if (IsAllowed(Permission.NoClip))
{
if (Game.PlayerPed.IsInVehicle())
{
var veh = GetVehicle();
if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed)
{
NoClipEnabled = !NoClipEnabled;
}
else
{
NoClipEnabled = false;
Notify.Error("This vehicle does not exist (somehow) or you need to be the driver of this vehicle to enable noclip!");
}
}
else
{
NoClipEnabled = !NoClipEnabled;
}
}
}), false);
RegisterCommand($"vMenu:{KeyMappingID}:MenuToggle", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
if (MenuEnabled)
{
if (!MenuController.IsAnyMenuOpen())
{
Menu.OpenMenu();
}
else
{
MenuController.CloseAllMenus();
}
}
}), false);
if (!(GetSettingsString(Setting.vmenu_noclip_toggle_key) == null))
{
NoClipKey = GetSettingsString(Setting.vmenu_noclip_toggle_key);
}
else
{
NoClipKey = "F2";
}
if (!(GetSettingsString(Setting.vmenu_menu_toggle_key) == null))
{
MenuToggleKey = GetSettingsString(Setting.vmenu_menu_toggle_key);
}
else
{
MenuToggleKey = "M";
}
MenuController.MenuToggleKey = (Control)(-1); // disables the menu toggle key
RegisterKeyMapping($"vMenu:{KeyMappingID}:NoClip", "vMenu NoClip Toggle Button", "keyboard", NoClipKey);
RegisterKeyMapping($"vMenu:{KeyMappingID}:MenuToggle", "vMenu Toggle Button", "keyboard", MenuToggleKey);
RegisterKeyMapping($"vMenu:{KeyMappingID}:MenuToggle", "vMenu Toggle Button Controller", "pad_digitalbuttonany", "start_index");
#endregion
if (EnableExperimentalFeatures)
{
RegisterCommand("testped", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
var data = Game.PlayerPed.GetHeadBlendData();
Debug.WriteLine(JsonConvert.SerializeObject(data, Formatting.Indented));
}), false);
RegisterCommand("tattoo", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
if (args != null && args[0] != null && args[1] != null)
{
Debug.WriteLine(args[0].ToString() + " " + args[1].ToString());
TattooCollectionData d = Game.GetTattooCollectionData(int.Parse(args[0].ToString()), int.Parse(args[1].ToString()));
Debug.WriteLine("check");
Debug.Write(JsonConvert.SerializeObject(d, Formatting.Indented) + "\n");
}
}), false);
RegisterCommand("clearfocus", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
SetNuiFocus(false, false);
}), false);
}
RegisterCommand("vmenuclient", new Action<dynamic, List<dynamic>, string>((dynamic source, List<dynamic> args, string rawCommand) =>
{
if (args != null)
{
if (args.Count > 0)
{
if (args[0].ToString().ToLower() == "debug")
{
DebugMode = !DebugMode;
Notify.Custom($"Debug mode is now set to: {DebugMode}.");
// Set discord rich precense once, allowing it to be overruled by other resources once those load.
if (DebugMode)
{
SetRichPresence($"Debugging vMenu {Version}!");
}
else
{
SetRichPresence($"Enjoying FiveM!");
}
}
else if (args[0].ToString().ToLower() == "gc")
{
GC.Collect();
Debug.Write("Cleared memory.\n");
}
else if (args[0].ToString().ToLower() == "dump")
{
Notify.Info("A full config dump will be made to the console. Check the log file. This can cause lag!");
Debug.WriteLine("\n\n\n########################### vMenu ###########################");
Debug.WriteLine($"Running vMenu Version: {Version}, Experimental features: {EnableExperimentalFeatures}, Debug mode: {DebugMode}.");
Debug.WriteLine("\nDumping a list of all KVPs:");
var handle = StartFindKvp("");
var names = new List<string>();
while (true)
{
var k = FindKvp(handle);
if (string.IsNullOrEmpty(k))
{
break;
}
//if (!k.StartsWith("settings_") && !k.StartsWith("vmenu") && !k.StartsWith("veh_") && !k.StartsWith("ped_") && !k.StartsWith("mp_ped_"))
//{
// DeleteResourceKvp(k);
//}
names.Add(k);
}
EndFindKvp(handle);
var kvps = new Dictionary<string, dynamic>();
foreach (var kvp in names)
{
var type = 0; // 0 = string, 1 = float, 2 = int.
if (kvp.StartsWith("settings_"))
{
if (kvp == "settings_voiceChatProximity") // float
{
type = 1;
}
else if (kvp == "settings_clothingAnimationType") // int
{
type = 2;
}
else if (kvp == "settings_miscLastTimeCycleModifierIndex") // int
{
type = 2;
}
else if (kvp == "settings_miscLastTimeCycleModifierStrength") // int
{
type = 2;
}
}
else if (kvp == "vmenu_cleanup_version") // int
{
type = 2;
}
switch (type)
{
case 0:
var s = GetResourceKvpString(kvp);
if (s.StartsWith("{") || s.StartsWith("["))
{
kvps.Add(kvp, JsonConvert.DeserializeObject(s));
}
else
{
kvps.Add(kvp, GetResourceKvpString(kvp));
}
break;
case 1:
kvps.Add(kvp, GetResourceKvpFloat(kvp));
break;
case 2:
kvps.Add(kvp, GetResourceKvpInt(kvp));
break;
}
}
Debug.WriteLine(@JsonConvert.SerializeObject(kvps, Formatting.None) + "\n");
Debug.WriteLine("\n\nDumping a list of allowed permissions:");
Debug.WriteLine(@JsonConvert.SerializeObject(Permissions, Formatting.None));
Debug.WriteLine("\n\nDumping vmenu server configuration settings:");
var settings = new Dictionary<string, string>();
foreach (var a in Enum.GetValues(typeof(Setting)))
{
settings.Add(a.ToString(), GetSettingsString((Setting)a));
}
Debug.WriteLine(@JsonConvert.SerializeObject(settings, Formatting.None));
Debug.WriteLine("\nEnd of vMenu dump!");
Debug.WriteLine("\n########################### vMenu ###########################");
}
}
else
{
Notify.Custom($"vMenu is currently running version: {Version}.");
}
}
}), false);
if (GetCurrentResourceName() != "vMenu")
{
MenuController.MainMenu = null;
MenuController.DontOpenAnyMenu = true;
MenuController.DisableMenuButtons = true;
throw new Exception("\n[vMenu] INSTALLATION ERROR!\nThe name of the resource is not valid. Please change the folder name from '" + GetCurrentResourceName() + "' to 'vMenu' (case sensitive)!\n");
}
else
{
Tick += OnTick;
}
// Clear all previous pause menu info/brief messages on resource start.
ClearBrief();
// Request the permissions data from the server.
TriggerServerEvent("vMenu:RequestPermissions");
// Request server state from the server.
TriggerServerEvent("vMenu:RequestServerState");
}
#region Infinity bits
[EventHandler("vMenu:SetServerState")]
public void SetServerState(IDictionary<string, object> data)
{
if (data.TryGetValue("IsInfinity", out var isInfinity))
{
if (isInfinity is bool isInfinityBool)
{
if (isInfinityBool)
{
PlayersList = new InfinityPlayerList(Players);
}
}
}
}
[EventHandler("vMenu:ReceivePlayerList")]
public void ReceivedPlayerList(IList<object> players)
{
PlayersList?.ReceivedPlayerList(players);
}
public static async Task<Vector3> RequestPlayerCoordinates(int serverId)
{
var coords = Vector3.Zero;
var completed = false;
// TODO: replace with client<->server RPC once implemented in CitizenFX!
Func<Vector3, bool> CallbackFunction = (data) =>
{
coords = data;
completed = true;
return true;
};
TriggerServerEvent("vMenu:GetPlayerCoords", serverId, CallbackFunction);
while (!completed)
{
await Delay(0);
}
return coords;
}
#endregion
#region Set Permissions function
/// <summary>
/// Set the permissions for this client.
/// </summary>
/// <param name="dict"></param>
public static async void SetPermissions(string permissionsList)
{
vMenuShared.PermissionsManager.SetPermissions(permissionsList);
VehicleSpawner.allowedCategories = new List<bool>()
{
IsAllowed(Permission.VSCompacts, checkAnyway: true),
IsAllowed(Permission.VSSedans, checkAnyway: true),
IsAllowed(Permission.VSSUVs, checkAnyway: true),
IsAllowed(Permission.VSCoupes, checkAnyway: true),
IsAllowed(Permission.VSMuscle, checkAnyway: true),
IsAllowed(Permission.VSSportsClassic, checkAnyway: true),
IsAllowed(Permission.VSSports, checkAnyway: true),
IsAllowed(Permission.VSSuper, checkAnyway: true),
IsAllowed(Permission.VSMotorcycles, checkAnyway: true),
IsAllowed(Permission.VSOffRoad, checkAnyway: true),
IsAllowed(Permission.VSIndustrial, checkAnyway: true),
IsAllowed(Permission.VSUtility, checkAnyway: true),
IsAllowed(Permission.VSVans, checkAnyway: true),
IsAllowed(Permission.VSCycles, checkAnyway: true),
IsAllowed(Permission.VSBoats, checkAnyway: true),
IsAllowed(Permission.VSHelicopters, checkAnyway: true),
IsAllowed(Permission.VSPlanes, checkAnyway: true),
IsAllowed(Permission.VSService, checkAnyway: true),
IsAllowed(Permission.VSEmergency, checkAnyway: true),
IsAllowed(Permission.VSMilitary, checkAnyway: true),
IsAllowed(Permission.VSCommercial, checkAnyway: true),
IsAllowed(Permission.VSTrains, checkAnyway: true),
IsAllowed(Permission.VSOpenWheel, checkAnyway: true)
};
ArePermissionsSetup = true;
while (!ConfigOptionsSetupComplete)
{
await Delay(100);
}
PostPermissionsSetup();
}
#endregion
/// <summary>
/// This setups things as soon as the permissions are loaded.
/// It triggers the menu creations, setting of initial flags like PVP, player stats,
/// and triggers the creation of Tick functions from the FunctionsController class.
/// </summary>
private static void PostPermissionsSetup()
{
switch (GetSettingsInt(Setting.vmenu_pvp_mode))
{
case 1:
NetworkSetFriendlyFireOption(true);
SetCanAttackFriendly(Game.PlayerPed.Handle, true, false);
break;
case 2:
NetworkSetFriendlyFireOption(false);
SetCanAttackFriendly(Game.PlayerPed.Handle, false, false);
break;
case 0:
default:
break;
}
static bool canUseMenu()
{
if (GetSettingsBool(Setting.vmenu_menu_staff_only) == false)
{
return true;
}
else if (IsAllowed(Permission.Staff))
{
return true;
}
return false;
}
if (!canUseMenu())
{
MenuController.MainMenu = null;
MenuController.DisableMenuButtons = true;
MenuController.DontOpenAnyMenu = true;
MenuEnabled = false;
return;
}
// Create the main menu.
Menu = new Menu(Game.Player.Name, "Main Menu");
PlayerSubmenu = new Menu(Game.Player.Name, "Player Related Options");
VehicleSubmenu = new Menu(Game.Player.Name, "Vehicle Related Options");
WorldSubmenu = new Menu(Game.Player.Name, "World Options");
// Add the main menu to the menu pool.
MenuController.AddMenu(Menu);
MenuController.MainMenu = Menu;
MenuController.AddSubmenu(Menu, PlayerSubmenu);
MenuController.AddSubmenu(Menu, VehicleSubmenu);
MenuController.AddSubmenu(Menu, WorldSubmenu);
// Create all (sub)menus.
CreateSubmenus();
if (!GetSettingsBool(Setting.vmenu_disable_player_stats_setup))
{
// Manage Stamina
if (PlayerOptionsMenu != null && PlayerOptionsMenu.PlayerStamina && IsAllowed(Permission.POUnlimitedStamina))
{
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 100, true);
}
else
{
StatSetInt((uint)GetHashKey("MP0_STAMINA"), 0, true);
}
// Manage other stats, in order of appearance in the pause menu (stats) page.
StatSetInt((uint)GetHashKey("MP0_SHOOTING_ABILITY"), 100, true); // Shooting
StatSetInt((uint)GetHashKey("MP0_STRENGTH"), 100, true); // Strength
StatSetInt((uint)GetHashKey("MP0_STEALTH_ABILITY"), 100, true); // Stealth
StatSetInt((uint)GetHashKey("MP0_FLYING_ABILITY"), 100, true); // Flying
StatSetInt((uint)GetHashKey("MP0_WHEELIE_ABILITY"), 100, true); // Driving
StatSetInt((uint)GetHashKey("MP0_LUNG_CAPACITY"), 100, true); // Lung Capacity
StatSetFloat((uint)GetHashKey("MP0_PLAYER_MENTAL_STATE"), 0f, true); // Mental State
}
TriggerEvent("vMenu:SetupTickFunctions");
}
/// <summary>
/// Main OnTick task runs every game tick and handles all the menu stuff.
/// </summary>
/// <returns></returns>
private async Task OnTick()
{
// If the setup (permissions) is done, and it's not the first tick, then do this:
if (ConfigOptionsSetupComplete)
{
#region Handle Opening/Closing of the menu.
var tmpMenu = GetOpenMenu();
if (MpPedCustomizationMenu != null)
{
static bool IsOpen()
{
return
MpPedCustomizationMenu.appearanceMenu.Visible ||
MpPedCustomizationMenu.faceShapeMenu.Visible ||
MpPedCustomizationMenu.createCharacterMenu.Visible ||
MpPedCustomizationMenu.inheritanceMenu.Visible ||
MpPedCustomizationMenu.propsMenu.Visible ||
MpPedCustomizationMenu.clothesMenu.Visible ||
MpPedCustomizationMenu.tattoosMenu.Visible;
}
if (IsOpen())
{
if (tmpMenu == MpPedCustomizationMenu.createCharacterMenu)
{
MpPedCustomization.DisableBackButton = true;
}
else
{
MpPedCustomization.DisableBackButton = false;
}
MpPedCustomization.DontCloseMenus = true;
}
else
{
MpPedCustomization.DisableBackButton = false;
MpPedCustomization.DontCloseMenus = false;
}
}
if (Game.IsDisabledControlJustReleased(0, Control.PhoneCancel) && MpPedCustomization.DisableBackButton)
{
await Delay(0);
Notify.Alert("You must save your ped first before exiting, or click the ~r~Exit Without Saving~s~ button.");
}
//if (Game.CurrentInputMode == InputMode.MouseAndKeyboard)
//{
// if (Game.IsControlJustPressed(0, (Control)NoClipKey) && IsAllowed(Permission.NoClip) && UpdateOnscreenKeyboard() != 0)
// {
// if (Game.PlayerPed.IsInVehicle())
// {
// var veh = GetVehicle();
// if (veh != null && veh.Exists() && veh.Driver == Game.PlayerPed)
// {
// NoClipEnabled = !NoClipEnabled;
// }
// else
// {
// NoClipEnabled = false;
// Notify.Error("This vehicle does not exist (somehow) or you need to be the driver of this vehicle to enable noclip!");
// }
// }
// else
// {
// NoClipEnabled = !NoClipEnabled;
// }
// }
//}
#endregion
// Menu toggle button.
//Game.DisableControlThisFrame(0, MenuToggleKey);
}
}
#region Add Menu Function
/// <summary>
/// Add the menu to the menu pool and set it up correctly.
/// Also add and bind the menu buttons.
/// </summary>
/// <param name="submenu"></param>
/// <param name="menuButton"></param>
private static void AddMenu(Menu parentMenu, Menu submenu, MenuItem menuButton)
{
parentMenu.AddMenuItem(menuButton);
MenuController.AddSubmenu(parentMenu, submenu);
MenuController.BindMenuItem(parentMenu, submenu, menuButton);
submenu.RefreshIndex();
}
#endregion
#region Create Submenus
/// <summary>
/// Creates all the submenus depending on the permissions of the user.
/// </summary>
private static void CreateSubmenus()
{
// Add the online players menu.
if (IsAllowed(Permission.OPMenu))
{
OnlinePlayersMenu = new OnlinePlayers();
var menu = OnlinePlayersMenu.GetMenu();
var button = new MenuItem("Online Players", "All currently connected players.")
{
Label = "→→→"
};
AddMenu(Menu, menu, button);
Menu.OnItemSelect += async (sender, item, index) =>
{
if (item == button)
{
PlayersList.RequestPlayerList();
await OnlinePlayersMenu.UpdatePlayerlist();
menu.RefreshIndex();
}
};
}
if (IsAllowed(Permission.OPUnban) || IsAllowed(Permission.OPViewBannedPlayers))
{
BannedPlayersMenu = new BannedPlayers();
var menu = BannedPlayersMenu.GetMenu();
var button = new MenuItem("Banned Players", "View and manage all banned players in this menu.")
{
Label = "→→→"
};
AddMenu(Menu, menu, button);
Menu.OnItemSelect += (sender, item, index) =>
{
if (item == button)
{
TriggerServerEvent("vMenu:RequestBanList", Game.Player.Handle);
menu.RefreshIndex();
}
};
}
var playerSubmenuBtn = new MenuItem("Player Related Options", "Open this submenu for player related subcategories.") { Label = "→→→" };
Menu.AddMenuItem(playerSubmenuBtn);
// Add the player options menu.
if (IsAllowed(Permission.POMenu))
{
PlayerOptionsMenu = new PlayerOptions();
var menu = PlayerOptionsMenu.GetMenu();
var button = new MenuItem("Player Options", "Common player options can be accessed here.")
{
Label = "→→→"
};
AddMenu(PlayerSubmenu, menu, button);
}
var vehicleSubmenuBtn = new MenuItem("Vehicle Related Options", "Open this submenu for vehicle related subcategories.") { Label = "→→→" };
Menu.AddMenuItem(vehicleSubmenuBtn);
// Add the vehicle options Menu.
if (IsAllowed(Permission.VOMenu))
{
VehicleOptionsMenu = new VehicleOptions();
var menu = VehicleOptionsMenu.GetMenu();
var button = new MenuItem("Vehicle Options", "Here you can change common vehicle options, as well as tune & style your vehicle.")
{
Label = "→→→"
};
AddMenu(VehicleSubmenu, menu, button);
}
// Add the vehicle spawner menu.
if (IsAllowed(Permission.VSMenu))
{
VehicleSpawnerMenu = new VehicleSpawner();
var menu = VehicleSpawnerMenu.GetMenu();
var button = new MenuItem("Vehicle Spawner", "Spawn a vehicle by name or choose one from a specific category.")
{
Label = "→→→"
};
AddMenu(VehicleSubmenu, menu, button);
}
// Add Saved Vehicles menu.
if (IsAllowed(Permission.SVMenu))
{
SavedVehiclesMenu = new SavedVehicles();
var menu = SavedVehiclesMenu.GetTypeMenu();
var button = new MenuItem("Saved Vehicles", "Save new vehicles, or spawn or delete already saved vehicles.")
{
Label = "→→→"
};
AddMenu(VehicleSubmenu, menu, button);
}
// Add the Personal Vehicle menu.
if (IsAllowed(Permission.PVMenu))
{
PersonalVehicleMenu = new PersonalVehicle();
var menu = PersonalVehicleMenu.GetMenu();
var button = new MenuItem("Personal Vehicle", "Set a vehicle as your personal vehicle, and control some things about that vehicle when you're not inside.")
{
Label = "→→→"
};
AddMenu(VehicleSubmenu, menu, button);
}
// Add the player appearance menu.
if (IsAllowed(Permission.PAMenu))
{
PlayerAppearanceMenu = new PlayerAppearance();
var menu = PlayerAppearanceMenu.GetMenu();
var button = new MenuItem("Player Appearance", "Choose a ped model, customize it and save & load your customized characters.")
{
Label = "→→→"
};
AddMenu(PlayerSubmenu, menu, button);
MpPedCustomizationMenu = new MpPedCustomization();
var menu2 = MpPedCustomizationMenu.GetMenu();
var button2 = new MenuItem("MP Ped Customization", "Create, edit, save and load multiplayer peds. ~r~Note, you can only save peds created in this submenu. vMenu can NOT detect peds created outside of this submenu. Simply due to GTA limitations.")
{
Label = "→→→"
};
AddMenu(PlayerSubmenu, menu2, button2);
}
var worldSubmenuBtn = new MenuItem("World Related Options", "Open this submenu for world related subcategories.") { Label = "→→→" };
Menu.AddMenuItem(worldSubmenuBtn);
// Add the time options menu.
// check for 'not true' to make sure that it _ONLY_ gets disabled if the owner _REALLY_ wants it disabled, not if they accidentally spelled "false" wrong or whatever.
if (IsAllowed(Permission.TOMenu) && GetSettingsBool(Setting.vmenu_enable_time_sync))
{
TimeOptionsMenu = new TimeOptions();
var menu = TimeOptionsMenu.GetMenu();
var button = new MenuItem("Time Options", "Change the time, and edit other time related options.")
{
Label = "→→→"
};
AddMenu(WorldSubmenu, menu, button);
}
// Add the weather options menu.
// check for 'not true' to make sure that it _ONLY_ gets disabled if the owner _REALLY_ wants it disabled, not if they accidentally spelled "false" wrong or whatever.
if (IsAllowed(Permission.WOMenu) && GetSettingsBool(Setting.vmenu_enable_weather_sync))
{
WeatherOptionsMenu = new WeatherOptions();
var menu = WeatherOptionsMenu.GetMenu();
var button = new MenuItem("Weather Options", "Change all weather related options here.")
{
Label = "→→→"
};
AddMenu(WorldSubmenu, menu, button);
}
// Add the weapons menu.
if (IsAllowed(Permission.WPMenu))
{
WeaponOptionsMenu = new WeaponOptions();
var menu = WeaponOptionsMenu.GetMenu();
var button = new MenuItem("Weapon Options", "Add/remove weapons, modify weapons and set ammo options.")
{
Label = "→→→"
};
AddMenu(PlayerSubmenu, menu, button);
}
// Add Weapon Loadouts menu.
if (IsAllowed(Permission.WLMenu))
{
WeaponLoadoutsMenu = new WeaponLoadouts();
var menu = WeaponLoadoutsMenu.GetMenu();
var button = new MenuItem("Weapon Loadouts", "Mange, and spawn saved weapon loadouts.")
{
Label = "→→→"
};
AddMenu(PlayerSubmenu, menu, button);
}
if (IsAllowed(Permission.NoClip))
{
var toggleNoclip = new MenuItem("Toggle NoClip", "Toggle NoClip on or off.");
PlayerSubmenu.AddMenuItem(toggleNoclip);
PlayerSubmenu.OnItemSelect += (sender, item, index) =>
{
if (item == toggleNoclip)
{
NoClipEnabled = !NoClipEnabled;
}
};
}
// Add Voice Chat Menu.
if (IsAllowed(Permission.VCMenu))
{
VoiceChatSettingsMenu = new VoiceChat();
var menu = VoiceChatSettingsMenu.GetMenu();
var button = new MenuItem("Voice Chat Settings", "Change Voice Chat options here.")
{
Label = "→→→"
};
AddMenu(Menu, menu, button);
}
{
RecordingMenu = new Recording();
var menu = RecordingMenu.GetMenu();
var button = new MenuItem("Recording Options", "In-game recording options.")
{
Label = "→→→"
};
AddMenu(Menu, menu, button);
}
// Add misc settings menu.
{
MiscSettingsMenu = new MiscSettings();
var menu = MiscSettingsMenu.GetMenu();
var button = new MenuItem("Misc Settings", "Miscellaneous vMenu options/settings can be configured here. You can also save your settings in this menu.")
{
Label = "→→→"
};
AddMenu(Menu, menu, button);
}
// Add About Menu.
AboutMenu = new About();
var sub = AboutMenu.GetMenu();
var btn = new MenuItem("About vMenu", "Information about vMenu.")
{
Label = "→→→"
};
AddMenu(Menu, sub, btn);
// Refresh everything.
MenuController.Menus.ForEach((m) => m.RefreshIndex());
if (!GetSettingsBool(Setting.vmenu_use_permissions))
{
Notify.Alert("vMenu is set up to ignore permissions, default permissions will be used.");
}
if (PlayerSubmenu.Size > 0)
{
MenuController.BindMenuItem(Menu, PlayerSubmenu, playerSubmenuBtn);
}
else
{
Menu.RemoveMenuItem(playerSubmenuBtn);
}
if (VehicleSubmenu.Size > 0)
{
MenuController.BindMenuItem(Menu, VehicleSubmenu, vehicleSubmenuBtn);
}
else
{
Menu.RemoveMenuItem(vehicleSubmenuBtn);
}
if (WorldSubmenu.Size > 0)
{
MenuController.BindMenuItem(Menu, WorldSubmenu, worldSubmenuBtn);
}
else
{
Menu.RemoveMenuItem(worldSubmenuBtn);
}
if (MiscSettingsMenu != null)
{
MenuController.EnableMenuToggleKeyOnController = !MiscSettingsMenu.MiscDisableControllerSupport;
}
}
#endregion
}
}