Example #1
0
        private void OnPlayerEnterVehicle(Client sender, NetHandle vehicle)
        {
            if (!FuelList.ContainsKey(vehicle))
            {
                FuelList.Add(vehicle, VehicleMaxFuelLevel(sender.vehicle));
            }

            API.triggerClientEvent(sender, "update_fuel_client", FuelList.Get(vehicle));
        }
Example #2
0
        public void OnClientEvent(Client player, string eventName, params object[] args)  //arguments param can contain multiple params
        {
            NetHandle vehicle = API.getPlayerVehicle(player);

            if (eventName == "GET_RPM")
            {
                float vehicleRPM    = (float)args[0];
                float vehicleSpeed  = (float)args[1];
                bool  isJumpPressed = (bool)args[2];
                int   TimeMatch     = (int)args[3];
                int   seconds       = (int)args[4];

                RenderUI(player);
                ConsumeFuel(player.vehicle, vehicleRPM, vehicleSpeed, isJumpPressed, player, API.getPlayerVehicle(player), TimeMatch, seconds);
            }
            if (eventName == "CAR_IS_REFUELING")
            {
                FuelList.Set(vehicle, VehicleMaxFuelLevel(player.vehicle));
                API.sendChatMessageToAll("Car Refuled");
                API.triggerClientEvent(player, "update_fuel_client", FuelList.Get(vehicle));
            }

            /*
             * if (eventName == "UPDATE_FUEL")
             * {
             *  float CurrentTank;
             *
             *  for (int i = FuelList.Count - 1; i >= 0; i--)
             *  {
             *      var item = FuelList.ElementAt(i);
             *      var itemKey = item.Key;
             *      var itemValue = item.Value;
             *      bool EngineStatus = API.getVehicleEngineStatus(itemKey);
             *
             *      if (EngineStatus)
             *      {
             *          CurrentTank = FuelList.Get(itemKey);
             *          CurrentTank = CurrentTank - 1f;
             *
             *          if (CurrentTank <= 0f)
             *          {
             *              CurrentTank = 0f;
             *              API.setVehicleEngineStatus(itemKey, false);
             *          }
             *
             *          //FuelList.Set(itemKey, CurrentTank);
             *          //API.sendChatMessageToAll("Car Refuled");
             *          if (API.isPlayerInAnyVehicle(player))
             *          {
             *              API.triggerClientEvent(player, "update_fuel_client", FuelList.Get(vehicle));
             *          }
             *      }
             *  }
             *
             *
             * }
             */
            if (eventName == "GET_VEHICLE_FUEL")
            {
                API.triggerClientEvent(player, "SEND_VEHICLE_FUEL", FuelList.Get(vehicle));
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="vehicleRPM"></param>
        /// <param name="vehicleSpeed"></param>
        /// <param name="isJumpPressed"></param>
        /// <param name="player"></param>
        /// <param name="NetVehicle"></param>
        public void ConsumeFuel(Vehicle vehicle, float vehicleRPM, float vehicleSpeed, bool isJumpPressed, Client player, NetHandle NetVehicle, int TimeMatch, int seconds)
        {
            float fuel          = FuelList.Get(NetVehicle);
            float VehicleConsum = GetVehicleConsume(vehicle);

            // Consuming
            if (fuel > 0 && vehicle.engineStatus && vehicleSpeed > 1)
            {
                //float normalizedRPMValue = (float)Math.Pow(vehicleRPM, 1.5);

                if (vehicleRPM > 0.7)
                {
                    fuel -= VehicleConsum;
                }

                fuel -= vehicleRPM * fuelRPMImpact;
                fuel -= (vehicleSpeed / 70) * fuelAccelerationImpact;
                fuel -= vehicle.maxTraction * fuelTractionImpact;

                fuel = fuel < 0f ? 0f : fuel;


                FuelList.Set(NetVehicle, fuel);


                if (fuel <= 0f)
                {
                    fuel = 0f;
                    API.setVehicleEngineStatus(NetVehicle, false);
                }

                API.triggerClientEvent(player, "update_fuel_client", FuelList.Get(NetVehicle));
            }

            // Refueling at gas station
            if (
                // If we have gas station near us
                currentGasStationIndex != -1 &&
                // And near any pump
                IsVehicleNearAnyPump(vehicle, player, isJumpPressed)
                )
            {
                if (vehicleSpeed < 0.1f)
                {
                    //ControlEngine(vehicle);
                }
                else
                {
                    if (isJumpPressed)
                    {
                        /* Tank aufüllen
                         * if (fuel < fuelTankCapacity)
                         * {
                         *  fuel += 0.1f;
                         *  addedFuelCapacitor += 0.1f;
                         * }
                         */
                    }

                    if (!isJumpPressed && addedFuelCapacitor > 0f)
                    {
                        //TriggerEvent("frfuel:fuelAdded", addedFuelCapacitor);
                        //TriggerServerEvent("frfuel:fuelAdded", addedFuelCapacitor);
                        addedFuelCapacitor = 0f;
                    }
                }
            }


            VehicleSetFuelLevel(vehicle, fuel, NetVehicle);
        }