Skip to content

Commit

Permalink
Merge pull request #203 from attributeerror/master
Browse files Browse the repository at this point in the history
Add vehicle doors control to PV menu.
  • Loading branch information
TomGrobbe authored Oct 15, 2019
2 parents d885bc9 + 0f06ed6 commit 9e4a396
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions SharedClasses/PermissionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public enum Permission
PVToggleLights,
PVKickPassengers,
PVLockDoors,
PVDoors,
PVSoundHorn,
PVToggleAlarm,
PVAddBlip,
Expand Down
125 changes: 125 additions & 0 deletions vMenu/menus/PersonalVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public PersonalVehicle() { }

public Vehicle CurrentPersonalVehicle { get; internal set; } = null;

public Menu VehicleDoorsMenu { get; internal set; } = null;


/// <summary>
/// Creates the menu.
Expand All @@ -41,10 +43,18 @@ private void CreateMenu()
//MenuItem
MenuItem lockDoors = new MenuItem("Lock Vehicle Doors", "This will lock all your vehicle doors for all players. Anyone already inside will always be able to leave the vehicle, even if the doors are locked.");
MenuItem unlockDoors = new MenuItem("Unlock Vehicle Doors", "This will unlock all your vehicle doors for all players.");
MenuItem doorsMenuBtn = new MenuItem("Vehicle Doors", "Open, close, remove and restore vehicle doors here.")
{
Label = "→→→"
};
MenuItem soundHorn = new MenuItem("Sound Horn", "Sounds the horn of the vehicle.");
MenuItem toggleAlarm = new MenuItem("Toggle Alarm Sound", "Toggles the vehicle alarm sound on or off. This does not set an alarm. It only toggles the current sounding status of the alarm.");
MenuCheckboxItem enableBlip = new MenuCheckboxItem("Add Blip For Personal Vehicle", "Enables or disables the blip that gets added when you mark a vehicle as your personal vehicle.", EnableVehicleBlip) { Style = MenuCheckboxItem.CheckboxStyle.Cross };
MenuCheckboxItem exclusiveDriver = new MenuCheckboxItem("Exclusive Driver", "If enabled, then you will be the only one that can enter the drivers seat. Other players will not be able to drive the car. They can still be passengers.", false) { Style = MenuCheckboxItem.CheckboxStyle.Cross };
//submenu
VehicleDoorsMenu = new Menu("Vehicle Doors", "Vehicle Doors Management");
MenuController.AddSubmenu(menu, VehicleDoorsMenu);
MenuController.BindMenuItem(menu, VehicleDoorsMenu, doorsMenuBtn);

// This is always allowed if this submenu is created/allowed.
menu.AddMenuItem(setVehice);
Expand Down Expand Up @@ -76,6 +86,11 @@ private void CreateMenu()
menu.AddMenuItem(unlockDoors);
}

if(IsAllowed(Permission.PVDoors))
{
menu.AddMenuItem(doorsMenuBtn);
}

// Sound horn
if (IsAllowed(Permission.PVSoundHorn))
{
Expand Down Expand Up @@ -297,6 +312,116 @@ private void CreateMenu()
Notify.Error("You have not yet selected a personal vehicle, or your vehicle has been deleted. Set a personal vehicle before you can use these options.");
}
};

#region Doors submenu
MenuItem openAll = new MenuItem("Open All Doors", "Open all vehicle doors.");
MenuItem closeAll = new MenuItem("Close All Doors", "Close all vehicle doors.");
MenuItem LF = new MenuItem("Left Front Door", "Open/close the left front door.");
MenuItem RF = new MenuItem("Right Front Door", "Open/close the right front door.");
MenuItem LR = new MenuItem("Left Rear Door", "Open/close the left rear door.");
MenuItem RR = new MenuItem("Right Rear Door", "Open/close the right rear door.");
MenuItem HD = new MenuItem("Hood", "Open/close the hood.");
MenuItem TR = new MenuItem("Trunk", "Open/close the trunk.");
MenuItem E1 = new MenuItem("Extra 1", "Open/close the extra door (#1). Note this door is not present on most vehicles.");
MenuItem E2 = new MenuItem("Extra 2", "Open/close the extra door (#2). Note this door is not present on most vehicles.");
MenuItem BB = new MenuItem("Bomb Bay", "Open/close the bomb bay. Only available on some planes.");
var doors = new List<string>() { "Front Left", "Front Right", "Rear Left", "Rear Right", "Hood", "Trunk", "Extra 1", "Extra 2", "Bomb Bay" };
MenuListItem removeDoorList = new MenuListItem("Remove Door", doors, 0, "Remove a specific vehicle door completely.");
MenuCheckboxItem deleteDoors = new MenuCheckboxItem("Delete Removed Doors", "When enabled, doors that you remove using the list above will be deleted from the world. If disabled, then the doors will just fall on the ground.", false);

VehicleDoorsMenu.AddMenuItem(LF);
VehicleDoorsMenu.AddMenuItem(RF);
VehicleDoorsMenu.AddMenuItem(LR);
VehicleDoorsMenu.AddMenuItem(RR);
VehicleDoorsMenu.AddMenuItem(HD);
VehicleDoorsMenu.AddMenuItem(TR);
VehicleDoorsMenu.AddMenuItem(E1);
VehicleDoorsMenu.AddMenuItem(E2);
VehicleDoorsMenu.AddMenuItem(BB);
VehicleDoorsMenu.AddMenuItem(openAll);
VehicleDoorsMenu.AddMenuItem(closeAll);
VehicleDoorsMenu.AddMenuItem(removeDoorList);
VehicleDoorsMenu.AddMenuItem(deleteDoors);

VehicleDoorsMenu.OnListItemSelect += (sender, item, index, itemIndex) =>
{
Vehicle veh = CurrentPersonalVehicle;
if(veh != null && veh.Exists())
{
if (!NetworkHasControlOfEntity(CurrentPersonalVehicle.Handle))
{
if (!NetworkRequestControlOfEntity(CurrentPersonalVehicle.Handle))
{
Notify.Error("You currently can't control this vehicle. Is someone else currently driving your car? Please try again after making sure other players are not controlling your vehicle.");
return;
}
}

if(item == removeDoorList)
{
PressKeyFob(veh);
SetVehicleDoorBroken(veh.Handle, index, deleteDoors.Checked);
}
}
};

VehicleDoorsMenu.OnItemSelect += (sender, item, index) =>
{
Vehicle veh = CurrentPersonalVehicle;
if(veh != null && veh.Exists() && !veh.IsDead)
{
if (!NetworkHasControlOfEntity(CurrentPersonalVehicle.Handle))
{
if (!NetworkRequestControlOfEntity(CurrentPersonalVehicle.Handle))
{
Notify.Error("You currently can't control this vehicle. Is someone else currently driving your car? Please try again after making sure other players are not controlling your vehicle.");
return;
}
}

if (index < 8)
{
bool open = GetVehicleDoorAngleRatio(veh.Handle, index) > 0.1f;
PressKeyFob(veh);
if(open)
{
SetVehicleDoorShut(veh.Handle, index, false);
} else
{
SetVehicleDoorOpen(veh.Handle, index, false, false);
}
} else if(item == openAll)
{
PressKeyFob(veh);
for(var door = 0; door < 8; door++)
{
SetVehicleDoorOpen(veh.Handle, door, false, false);
}
} else if(item == closeAll)
{
PressKeyFob(veh);
for(var door = 0; door < 8; door++)
{
SetVehicleDoorShut(veh.Handle, door, false);
}
} else if(item == BB && veh.HasBombBay)
{
PressKeyFob(veh);
bool bombBayOpen = AreBombBayDoorsOpen(veh.Handle);
if(bombBayOpen)
{
veh.CloseBombBay();
} else
{
veh.OpenBombBay();
}
} else
{
Notify.Error("You have not yet selected a personal vehicle, or your vehicle has been deleted. Set a personal vehicle before you can use these options.");
}
}
};
#endregion
}


Expand Down
1 change: 1 addition & 0 deletions vMenuServer/config/permissions.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ add_ace builtin.everyone "vMenu.PersonalVehicle.All" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.ToggleLights" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.KickPassengers" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.LockDoors" allow # This grants both locking and unlocking the doors.
#add_ace builtin.everyone "vMenu.PersonalVehicle.Doors" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.SoundHorn" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.ToggleAlarm" allow
#add_ace builtin.everyone "vMenu.PersonalVehicle.AddBlip" allow # Adds a blip for your personal vehicle only.
Expand Down

0 comments on commit 9e4a396

Please sign in to comment.