Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using CitizenFX.Core;
- using CitizenFX.Core.Native;
- using CitizenFX.Core.UI;
- using NativeUI;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace VehicleControls {
- public class VehicleControls : BaseScript {
- private static string ERROR = "~r~Errore: ";
- private static string ERROR_NOCAR = ERROR + "Non sei su un veicolo oppure non hai un veicolo salvato!";
- private Vehicle savedVehicle;
- private void AddEngineItem(UIMenu menu) {
- var newItem = new UIMenuItem("Gestisci Motore");
- menu.AddItem(newItem);
- menu.OnItemSelect += (sender, item, index) => {
- if (item != newItem) {
- return;
- }
- Vehicle car = LocalPlayer.Character.CurrentVehicle;
- if (car == null && savedVehicle == null) {
- Screen.ShowNotification(ERROR_NOCAR);
- return;
- }
- if (car != null) {
- ToggleEngine(car);
- }
- else if (savedVehicle != null) {
- ToggleEngine(savedVehicle);
- }
- };
- }
- private void ToggleEngine(Vehicle car) {
- if (car.IsEngineRunning) {
- Screen.ShowNotification("Il motore è ~r~spento~w~.");
- car.IsDriveable = false;
- car.IsEngineRunning = false;
- }
- else {
- Screen.ShowNotification("Il motore è ~g~acceso~w~.");
- car.IsDriveable = true;
- car.IsEngineRunning = true;
- }
- }
- private void AddOpenDoorItem(UIMenu menu) {
- List<dynamic> doors = new List<dynamic> {
- "Avanti Sinistra",
- "Avanti Destra",
- "Dietro Sinistra",
- "Dietro Destra",
- "Cofano",
- "Bagagliaio"
- };
- var newItem = new UIMenuListItem("Gestisci Portiera", doors, 0);
- menu.AddItem(newItem);
- menu.OnItemSelect += (sender, item, index) => {
- if (item != newItem) {
- return;
- }
- int itemIndex = newItem.Index;
- string doorName = newItem.IndexToItem(itemIndex);
- Vehicle car = LocalPlayer.Character.CurrentVehicle;
- if (car == null && savedVehicle == null) {
- Screen.ShowNotification(ERROR_NOCAR);
- return;
- }
- if (car != null) {
- ToggleDoor(car, itemIndex, doorName);
- }
- else {
- ToggleDoor(savedVehicle, itemIndex, doorName);
- }
- };
- }
- private void ToggleDoor(Vehicle car, int index, string doorName) {
- bool doorBroken = Function.Call<bool>(Hash.IS_VEHICLE_DOOR_DAMAGED, car, index);
- if (doorBroken) {
- Screen.ShowNotification(ERROR + "Portiera rotta!");
- return;
- }
- float doorAngle = Function.Call<float>(Hash.GET_VEHICLE_DOOR_ANGLE_RATIO, car, index);
- if (doorAngle == 0) // Door chiusa
- {
- Screen.ShowNotification("La portiera: " + doorName + " è ~g~aperta~w~.");
- Function.Call(Hash.SET_VEHICLE_DOOR_OPEN, car, index, false, false);
- }
- else {
- Screen.ShowNotification("La portiera: " + doorName + " è ~r~chiusa~w~.");
- Function.Call(Hash.SET_VEHICLE_DOOR_SHUT, car, index, false);
- }
- }
- private void AddSaveVehicleItem(UIMenu menu) {
- var newItem = new UIMenuItem("Salva Veicolo");
- menu.AddItem(newItem);
- menu.OnItemSelect += (sender, item, index) => {
- if (item != newItem) {
- return;
- }
- Vehicle car = LocalPlayer.Character.CurrentVehicle;
- if (car == null) {
- Screen.ShowNotification(ERROR_NOCAR);
- return;
- }
- SaveVehicle(car);
- Screen.ShowNotification("Veicolo Salvato.");
- };
- }
- private void AddCredits(UIMenu menu) {
- var newItem = new UIMenuItem("Crediti");
- menu.AddItem(newItem);
- menu.OnItemSelect += (sender, item, index) => {
- if (item != newItem) {
- return;
- }
- Screen.ShowNotification("Resource sviluppata da: ~o~Zio_Pagnotta");
- };
- }
- private void SaveVehicle(Vehicle car) {
- if (savedVehicle != null) {
- foreach (Blip vehBlip in savedVehicle.AttachedBlips) {
- vehBlip.Alpha = 0;
- }
- }
- Blip blip = car.AttachBlip();
- blip.Sprite = BlipSprite.PersonalVehicleCar;
- savedVehicle = car;
- }
- public VehicleControls() {
- MenuPool menuPool = new MenuPool();
- UIMenu menu = new UIMenu("TheFinalRoad", "Gestione Veicolo");
- menuPool.Add(menu);
- AddEngineItem(menu);
- AddOpenDoorItem(menu);
- AddSaveVehicleItem(menu);
- AddCredits(menu);
- menu.RefreshIndex();
- Tick += new Func<Task>(async delegate {
- await Task.FromResult(0);
- menuPool.ProcessMenus();
- if (Game.IsControlJustReleased(1, Control.InteractionMenu)) {
- menu.Visible = !menu.Visible;
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement