コード例 #1
0
ファイル: ChatHandler.cs プロジェクト: Flashrex/altv-tutorial
        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!");
        }
コード例 #2
0
ファイル: ChatHandler.cs プロジェクト: Flashrex/altv-tutorial
        public static void CMD_FixVeh(MyPlayer player)
        {
            if (!player.IsInVehicle || player.Seat != 1)
            {
                return;
            }
            MyVehicle veh = (MyVehicle)player.Vehicle;

            veh.Repair();
        }
コード例 #3
0
ファイル: ChatHandler.cs プロジェクト: Flashrex/altv-tutorial
        public static void CMD_Engine(MyPlayer player)
        {
            if (!player.IsInVehicle || player.Seat != 1)
            {
                return;
            }
            MyVehicle veh = (MyVehicle)player.Vehicle;

            veh.ToggleEngine();
        }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        public bool RemoveVehicle(MyVehicle vehicle, bool deleteFromDisk = false)
        {
            if (!_vehicles.Contains(vehicle))
            {
                return(false);
            }

            _vehicles.Remove(vehicle);

            if (deleteFromDisk)
            {
                DeleteVehicle(vehicle);
            }

            return(true);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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.");
            }
        }
コード例 #10
0
 private string GetVehicleFileName(MyVehicle vehicle)
 {
     return($"{vehicle.ModelName}-{vehicle.LicensePlate}.json");
 }
コード例 #11
0
 public bool AddOrUpdateVehicle(MyVehicle vehicle, bool saveToDisk = false)
 {
     return(UpdateVehicle(vehicle, saveToDisk) || AddVehicle(vehicle, saveToDisk)); // Short-circuits if first is true.
 }
コード例 #12
0
 public void OnPlayerLeaveVehicle(MyVehicle vehicle, MyPlayer player, byte seat)
 {
     vehicle.SecondaryColorRgb = new Rgba(255, 255, 255, 255);
     player.SendNotification("Fahrzeug verlassen!");
 }
コード例 #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;
 }