Permalink
Browse files

Saved vehicles can now be spawned even with the "Vehicle Spawner" men…

…u "disabled" (no permissions) as long as the saved vehicle belongs in a vehicle class that has been allowed.

For example. If you do *not* give players access to the vehiclespawner menu, but you still want them to be able to spawn saved vehicles from the "offroad" class, simply give them the "vMenu.VehicleSpawner.OffRoad" permission and they'll still be able to spawn that vehicle using the saved vehicles menu.
  • Loading branch information...
TomGrobbe committed Aug 19, 2018
1 parent 91eba95 commit bb2106504dc48dfa09019735859beca1e3b47fbe
Showing with 41 additions and 29 deletions.
  1. +1 −1 vMenu/CommonFunctions.cs
  2. +26 −1 vMenu/MainMenu.cs
  3. +9 −1 vMenu/menus/SavedVehicles.cs
  4. +5 −26 vMenu/menus/VehicleSpawner.cs
@@ -642,7 +642,7 @@ public async void SpawnVehicle(uint vehicleHash, bool spawnInside, bool replaceP
var vehClass = GetVehicleClassFromName(vehicleHash);
int modelClass = GetVehicleClassFromName(vehicleHash);
if (!MainMenu.VehicleSpawnerMenu.allowedCategories[modelClass])
if (!VehicleSpawner.allowedCategories[modelClass])
{
Notify.Alert("You are not allowed to spawn this vehicle, because it belongs to a category which is restricted by the server owner.");
return;
@@ -128,6 +128,31 @@ public static void SetPermissions(dynamic dict)
Cf.Log(JsonConvert.SerializeObject(PermissionsManager.Permissions).ToString());
permissionsSetupDone = true;
VehicleSpawner.allowedCategories = new List<bool>()
{
Cf.IsAllowed(Permission.VSCompacts),
Cf.IsAllowed(Permission.VSSedans),
Cf.IsAllowed(Permission.VSSUVs),
Cf.IsAllowed(Permission.VSCoupes),
Cf.IsAllowed(Permission.VSMuscle),
Cf.IsAllowed(Permission.VSSportsClassic),
Cf.IsAllowed(Permission.VSSports),
Cf.IsAllowed(Permission.VSSuper),
Cf.IsAllowed(Permission.VSMotorcycles),
Cf.IsAllowed(Permission.VSOffRoad),
Cf.IsAllowed(Permission.VSIndustrial),
Cf.IsAllowed(Permission.VSUtility),
Cf.IsAllowed(Permission.VSVans),
Cf.IsAllowed(Permission.VSCycles),
Cf.IsAllowed(Permission.VSBoats),
Cf.IsAllowed(Permission.VSHelicopters),
Cf.IsAllowed(Permission.VSPlanes),
Cf.IsAllowed(Permission.VSService),
Cf.IsAllowed(Permission.VSEmergency),
Cf.IsAllowed(Permission.VSMilitary),
Cf.IsAllowed(Permission.VSCommercial),
Cf.IsAllowed(Permission.VSTrains),
};
}
#endregion
@@ -165,7 +190,7 @@ public static void SetOptions(dynamic options)
/// <returns></returns>
private async Task ProcessMainButtons()
{
if (MainMenu.Mp.IsAnyMenuOpen())
if (Mp.IsAnyMenuOpen())
{
currentMenu = Cf.GetOpenMenu();
if (currentMenu != null && !DontOpenMenus && Mp.IsAnyMenuOpen() && !NoClipEnabled)
@@ -155,7 +155,15 @@ private void CreateMenu()
CommonFunctions.VehicleInfo vehInfo = SavedVehiclesDict["veh_" + item2.Text];
// Spawn a vehicle using the hash, and pass on the vehicleInfo dictionary containing all saved vehicle mods.
cf.SpawnVehicle(vehInfo.model, MainMenu.VehicleSpawnerMenu.SpawnInVehicle, MainMenu.VehicleSpawnerMenu.ReplaceVehicle, false, vehicleInfo: vehInfo, saveName: item2.Text);
if (MainMenu.VehicleSpawnerMenu != null)
{
cf.SpawnVehicle(vehInfo.model, MainMenu.VehicleSpawnerMenu.SpawnInVehicle, MainMenu.VehicleSpawnerMenu.ReplaceVehicle, false, vehicleInfo: vehInfo, saveName: item2.Text);
}
else
{
cf.SpawnVehicle(vehInfo.model, true, true, false, vehicleInfo: vehInfo, saveName: item2.Text);
}
};
// Handle vehicle deletions
@@ -18,36 +18,15 @@ public class VehicleSpawner
public bool SpawnInVehicle { get; private set; } = UserDefaults.VehicleSpawnerSpawnInside;
public bool ReplaceVehicle { get; private set; } = UserDefaults.VehicleSpawnerReplacePrevious;
public List<bool> allowedCategories;
public static List<bool> allowedCategories;
private static VehicleData vd = new VehicleData();
private void CreateMenu()
{
VehicleData vd = new VehicleData();
//VehicleData vd = new VehicleData();
#region initial setup.
allowedCategories = new List<bool>(){
cf.IsAllowed(Permission.VSCompacts),
cf.IsAllowed(Permission.VSSedans),
cf.IsAllowed(Permission.VSSUVs),
cf.IsAllowed(Permission.VSCoupes),
cf.IsAllowed(Permission.VSMuscle),
cf.IsAllowed(Permission.VSSportsClassic),
cf.IsAllowed(Permission.VSSports),
cf.IsAllowed(Permission.VSSuper),
cf.IsAllowed(Permission.VSMotorcycles),
cf.IsAllowed(Permission.VSOffRoad),
cf.IsAllowed(Permission.VSIndustrial),
cf.IsAllowed(Permission.VSUtility),
cf.IsAllowed(Permission.VSVans),
cf.IsAllowed(Permission.VSCycles),
cf.IsAllowed(Permission.VSBoats),
cf.IsAllowed(Permission.VSHelicopters),
cf.IsAllowed(Permission.VSPlanes),
cf.IsAllowed(Permission.VSService),
cf.IsAllowed(Permission.VSEmergency),
cf.IsAllowed(Permission.VSMilitary),
cf.IsAllowed(Permission.VSCommercial),
cf.IsAllowed(Permission.VSTrains),
};
// Create the menu.
menu = new UIMenu(GetPlayerName(PlayerId()), "Vehicle Spawner", true)

0 comments on commit bb21065

Please sign in to comment.