public static void OpenVehicleShop(Client client)
        {
            if (!client.hasData("player"))
            {
                return;
            }
            Player      player      = client.getData("player");
            VehicleShop vehicleShop = VehShopList.FirstOrDefault(x => x.Position.DistanceTo(client.position) <= 2f);

            if (vehicleShop == null)
            {
                return;
            }

            if (vehicleShop.FactionType != FactionType.Citizen)
            {
                if (vehicleShop.FactionType != player.Character.Faction)
                {
                    return;
                }
            }

            if (vehicleShop.SellingVehicles.Count == 0)
            {
                API.shared.sendPictureNotificationToPlayer(client, "Sorry, we don't sell anything at the moment..", "CHAR_BLOCKED", 0, 0, "ID: ~b~" + vehicleShop.Id, "Vehicle Shop");
                return;
            }
            List <VehicleShopMenuItem> MenuItems = new List <VehicleShopMenuItem>();

            vehicleShop.SellingVehicles.ToList().ForEach(vehicle => {
                MenuItems.Add(new VehicleShopMenuItem {
                    Name         = vehicle.Key,
                    Description  = vehicle.Value + " $",
                    VehHash      = API.shared.getHashKey(vehicle.Key),
                    InfoFuel     = VehicleService.GetVehicleInfo(vehicle.Key).Fuel.ToString(),
                    InfoStorage  = VehicleService.GetVehicleInfo(vehicle.Key).MaxStorage.ToString(),
                    InfoMaxSpeed = Math.Round(Convert.ToDouble(API.shared.getVehicleMaxSpeed(API.shared.vehicleNameToModel(vehicle.Key))) * 3.6).ToString()
                });
            });

            API.shared.triggerClientEvent(client, "VehicleShop_OpenMenu", JsonConvert.SerializeObject(MenuItems), vehicleShop.PreviewPosition, vehicleShop.PreviewRotation, vehicleShop.PreviewCamera, vehicleShop.Name);
        }
Exemple #2
0
        public static void StartRefill(Client client, OwnedVehicle ownedVehicle, FuelType fuelType)
        {
            if (!client.hasData("player"))
            {
                return;
            }
            Player player = client.getData("player");

            if (ownedVehicle.ActiveHandle.engineStatus)
            {
                API.shared.sendNotificationToPlayer(client, "~r~You must first turn off the engine before you start refuel.");
                return;
            }
            GasStation gasStation = GasStationList.FirstOrDefault(x => x.Position.DistanceTo(client.position) <= 20);

            client.setData("gasStation", gasStation);
            if (gasStation == null)
            {
                return;
            }

            if (VehicleService.GetVehicleInfo(ownedVehicle.ModelName).Fuel != fuelType)
            {
                API.shared.sendNotificationToPlayer(client, "~o~You don't wont fill " + fuelType.ToString() + " in your " + ownedVehicle.ModelName + "(" +
                                                    VehicleService.GetVehicleInfo(ownedVehicle.ModelName).Fuel.ToString() + ").. ~r~~n~Remember that..");
                return;
            }

            int    maxFuel   = VehicleService.GetVehicleInfo(ownedVehicle.ModelName).MaxFuel;
            int    startFuel = ownedVehicle.Fuel;
            double price     = 0;

            switch (fuelType)
            {
            case FuelType.Petrol:
                price = gasStation.StationFuelPrices.Petrol;
                break;

            case FuelType.Diesel:
                price = gasStation.StationFuelPrices.Diesel;
                break;

            case FuelType.Gas:
                price = gasStation.StationFuelPrices.Gas;
                break;

            case FuelType.Electricity:
                price = gasStation.StationFuelPrices.Electricity;
                break;

            case FuelType.Kerosene:
                price = gasStation.StationFuelPrices.Kerosene;
                break;
            }

            API.shared.triggerClientEvent(client, "ShowRefuelProgressbar", ownedVehicle.Fuel, maxFuel);
            client.setData("fuelStartPosition", client.position);
            client.setSyncedData("currentfuel", ownedVehicle.Fuel);
            client.setData("fuelcar", ownedVehicle);
            client.setData("fuelcarstart", ownedVehicle.Fuel);
            client.setData("fueltype", fuelType);
            Timer timer = API.shared.startTimer(1000, false, () => {
                if (ownedVehicle.Fuel < VehicleService.GetVehicleInfo(ownedVehicle.ModelName).MaxFuel)
                {
                    Vector3 startPositon = client.getData("fuelStartPosition");
                    if (startPositon.DistanceTo(client.position) > 4f)
                    {
                        StopRefill(client);
                        return;
                    }

                    switch (fuelType)
                    {
                    case FuelType.Petrol:
                        if (gasStation.Storage.Petrol > 0)
                        {
                            gasStation.Storage.Petrol--;
                        }
                        else
                        {
                            StopRefill(client);
                            API.shared.sendNotificationToPlayer(client, "~o~This gas station has no more ~b~Petrol~o~ in stock..");
                            return;
                        }
                        break;

                    case FuelType.Diesel:
                        if (gasStation.Storage.Diesel > 0)
                        {
                            gasStation.Storage.Diesel--;
                        }
                        else
                        {
                            StopRefill(client);
                            API.shared.sendNotificationToPlayer(client, "~o~This gas station has no more ~b~Diesel~o~ in stock..");
                            return;
                        }
                        break;

                    case FuelType.Gas:
                        if (gasStation.Storage.Gas > 0)
                        {
                            gasStation.Storage.Gas--;
                        }
                        else
                        {
                            StopRefill(client);
                            API.shared.sendNotificationToPlayer(client, "~o~This gas station has no more ~b~Gas~o~ in stock..");
                            return;
                        }
                        break;
                    }

                    if (player.Character.Bank < GetFuelPrice(gasStation, fuelType))
                    {
                        StopRefill(client);
                        API.shared.sendNotificationToPlayer(client, "~r~You don't have enough Money to continue the Refuel..");
                        return;
                    }


                    ownedVehicle.Fuel++;
                    player.Character.Bank   -= price;
                    gasStation.MoneyStorage += price;
                    ownedVehicle.ActiveHandle.setSyncedData("fuel", ownedVehicle.Fuel);
                    client.setSyncedData("currentfuel", ownedVehicle.Fuel);
                }
                else
                {
                    StopRefill(client);
                }
            });

            client.setData("refuelTimer", timer);
        }