Ejemplo n.º 1
0
        public static void CMD_CreateVehicle(MyPlayer player, string vehName, int r = 0, int g = 0, int b = 0)
        {
            uint vehHash = Alt.Hash(vehName);

            if (!Enum.IsDefined(typeof(AltV.Net.Enums.VehicleModel), vehHash))
            {
                player.SendChatMessage("[Server] Ungültiger Fahrzeugname!");
                return;
            }

            MyVehicle veh;

            if (player.HasData("altvtutorial:vehicle"))
            {
                player.GetData("altvtutorial:vehicle", out veh);
                veh.Remove();
            }

            //IVehicle veh = Alt.CreateVehicle(vehHash, GetRandomPositionAround(player.Position, 5.0f), player.Rotation);
            veh = new MyVehicle(vehHash, GetRandomPositionAround(player.Position, 5.0f), player.Rotation);
            veh.PrimaryColorRgb   = new Rgba(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b), 255);
            veh.SecondaryColorRgb = new Rgba(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b), 255);

            player.SetData("altvtutorial:vehicle", veh);

            player.SendChatMessage("Fahrzeug gespawnt!");
        }
Ejemplo n.º 2
0
        public static void CMD_FixVeh(MyPlayer player)
        {
            if (!player.IsInVehicle || player.Seat != 1)
            {
                return;
            }
            MyVehicle veh = (MyVehicle)player.Vehicle;

            veh.Repair();
        }
Ejemplo n.º 3
0
        public static void CMD_Engine(MyPlayer player)
        {
            if (!player.IsInVehicle || player.Seat != 1)
            {
                return;
            }
            MyVehicle veh = (MyVehicle)player.Vehicle;

            veh.ToggleEngine();
        }
        private void SaveVehicle(MyVehicle vehicle)
        {
            var serializedVehicle = JsonConvert.SerializeObject(vehicle, Formatting.Indented);

            try
            {
                File.WriteAllText(Path.Combine(_storageFolderPath, GetVehicleFileName(vehicle)), serializedVehicle, Encoding.UTF8);
            }
            catch (Exception e)
            {
                throw new Exception($"Couldn't save vehicle file '{GetVehicleFileName(vehicle)}' to folder '{_storageFolderPath}'. Error message: '{e.Message}'", e);
            }
        }
        public bool RemoveVehicle(MyVehicle vehicle, bool deleteFromDisk = false)
        {
            if (!_vehicles.Contains(vehicle))
            {
                return(false);
            }

            _vehicles.Remove(vehicle);

            if (deleteFromDisk)
            {
                DeleteVehicle(vehicle);
            }

            return(true);
        }
        public bool AddVehicle(MyVehicle vehicle, bool saveToDisk = false)
        {
            if (_vehicles.Contains(vehicle) || _vehicles.Any(v => vehicle.SameAs(v)))
            {
                return(false);
            }

            _vehicles.Add(vehicle);

            if (saveToDisk)
            {
                SaveVehicle(vehicle);
            }

            return(true);
        }
        public bool UpdateVehicle(MyVehicle vehicle, bool saveToDisk = false)
        {
            var vehicleIndex = _vehicles.FindIndex(v => vehicle.SameAs(v));

            if (vehicleIndex == -1)
            {
                return(false);
            }

            _vehicles[vehicleIndex] = vehicle; // If object instance is the same, there is obviously nothing to update, but does no harm either.

            if (saveToDisk)
            {
                SaveVehicle(vehicle);
            }

            return(true);
        }
        private void DeleteVehicle(MyVehicle vehicle)
        {
            var vehicleFilePath = Path.Combine(_storageFolderPath, GetVehicleFileName(vehicle));

            if (!File.Exists(vehicleFilePath))
            {
                return;
            }

            try
            {
                File.Delete(vehicleFilePath);
            }
            catch (Exception e)
            {
                throw new Exception($"Couldn't delete vehicle file '{GetVehicleFileName(vehicle)}' from folder '{_storageFolderPath}. Error message: '{e.Message}'", e);
            }
        }
        private void AddOrUpdateVehicle(Vehicle vehicle)
        {
            if (vehicle == null)
            {
                Stdout("There is no current vehicle to add or update.");
                return;
            }

            var myVehicle = new MyVehicle(vehicle);

            if (_vehicleRepository.UpdateVehicle(myVehicle, saveToDisk: true))
            {
                Stdout($"Successfully updated vehicle '{myVehicle.ModelName}' with license plate '{myVehicle.LicensePlate}'.");
            }
            else if (_vehicleRepository.AddVehicle(myVehicle, saveToDisk: true))
            {
                Stdout($"Successfully added vehicle '{myVehicle.ModelName}' with license plate '{myVehicle.LicensePlate}'.");
            }
            else
            {
                Stdout("Couldn't add or update vehicle.");
            }
        }
 private string GetVehicleFileName(MyVehicle vehicle)
 {
     return($"{vehicle.ModelName}-{vehicle.LicensePlate}.json");
 }
 public bool AddOrUpdateVehicle(MyVehicle vehicle, bool saveToDisk = false)
 {
     return(UpdateVehicle(vehicle, saveToDisk) || AddVehicle(vehicle, saveToDisk)); // Short-circuits if first is true.
 }
Ejemplo n.º 12
0
 public void OnPlayerLeaveVehicle(MyVehicle vehicle, MyPlayer player, byte seat)
 {
     vehicle.SecondaryColorRgb = new Rgba(255, 255, 255, 255);
     player.SendNotification("Fahrzeug verlassen!");
 }
Ejemplo n.º 13
0
 public void OnPlayerEnterVehicle(MyVehicle vehicle, MyPlayer player, byte seat)
 {
     vehicle.SecondaryColorRgb = new Rgba(255, 0, 0, 255);
     player.SendNotification("Fahrzeug betreten!");
     vehicle.RadioStation = (uint)RadioStation.FlyloFm;
 }