Exemple #1
0
        public FRFuel()
        {
            EventHandlers["onClientMapStart"] += new Action <dynamic>((dynamic res) => {
                CreateBlips();
            });

            blips = new Blip[gasStations.Length];

            var fuelBarBackdropPosition = new PointF(20f, 569f); // Right above the radar HUD
            var fuelBarBackPosition     = new PointF(20f, 572f);
            var fuelBarPosition         = fuelBarBackPosition;

            var fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f);
            var fuelBarBackSize     = new SizeF(fuelBarWidth, fuelBarHeight);
            var fuelBarSize         = fuelBarBackSize;

            var fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0);
            var fuelBarBackColour     = Color.FromArgb(50, 255, 179, 0);

            fuelBarColourNormal  = Color.FromArgb(150, 255, 179, 0);
            fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220);

            fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
            fuelBarBack     = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
            fuelBar         = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);

            CreateBlips();

            Tick += OnTick;

            EntityDecoration.RegisterProperty(fuelLevelPropertyName, DecorationType.Float);
        }
Exemple #2
0
        /// <summary>
        /// Processes fuel consumption
        /// </summary>
        /// <param name="vehicle"></param>
        public void ConsumeFuel(Vehicle vehicle)
        {
            float fuel = vehicle.FuelLevel;

            // Consuming
            if (fuel > 0 && vehicle.IsEngineRunning)
            {
                float normalizedRPMValue = (float)Math.Pow(vehicle.CurrentRPM, 1.5);

                fuel -= normalizedRPMValue * fuelRPMImpact;
                fuel -= vehicle.Acceleration * fuelAccelerationImpact;
                fuel -= vehicle.MaxTraction * fuelTractionImpact;
            }

            // Refueling
            if (
                // If we have gas station near us
                currentGasStation != null &&
                // And ped is in range of sqrt(80) to it
                Vector3.DistanceSquared(currentGasStation.Position, vehicle.Position) <= 80f
                )
            {
                if (vehicle.IsEngineRunning)
                {
                    helpTextTurnOff.Draw();
                }
                else
                {
                    if (fuelTankCapacity - fuel < 2f)
                    {
                        helpTextTurnOn.Draw();
                    }
                    else
                    {
                        helpTextRefuel.Draw();
                    }

                    if (Game.IsControlPressed(0, Control.Jump))
                    {
                        if (fuel < fuelTankCapacity)
                        {
                            fuel += 0.1f;
                        }

                        if (fuel > fuelTankCapacity)
                        {
                            fuel = fuelTankCapacity;
                        }
                    }
                }
            }

            vehicle.FuelLevel = fuel;
            EntityDecoration.Set(vehicle, fuelLevelPropertyName, fuel);
        }
Exemple #3
0
        /// <summary>
        /// Inits fuel for given vehicle
        /// </summary>
        /// <param name="vehicle"></param>
        public void InitFuel(Vehicle vehicle)
        {
            initialized = true;

            if (VehiclesPetrolTanks.Has(vehicle))
            {
                fuelTankCapacity = VehiclesPetrolTanks.Get(vehicle);
            }
            else
            {
                fuelTankCapacity = 65f;
            }

            if (!EntityDecoration.ExistOn(vehicle, fuelLevelPropertyName))
            {
                EntityDecoration.Set(
                    vehicle,
                    fuelLevelPropertyName,
                    RandomizeFuelLevel(vehicle.FuelLevel)
                    );
            }

            vehicle.FuelLevel = EntityDecoration.Get <float>(vehicle, fuelLevelPropertyName);
        }