Skip to content

Commit

Permalink
Saved vehicles can now be spawned even with the "Vehicle Spawner" men…
Browse files Browse the repository at this point in the history
…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 bb21065
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 26 additions & 1 deletion vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion vMenu/menus/SavedVehicles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 5 additions & 26 deletions vMenu/menus/VehicleSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bb21065

Please sign in to comment.