Skip to content

Commit

Permalink
Fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
thers committed Jun 27, 2017
1 parent 17866fe commit 05e7a72
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 8 additions & 0 deletions DevMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DevMenu

protected UIMenuItem vehicleModelId;
protected UIMenuItem vehicleFuelTank;
protected UIMenuItem drainFuelTank;
protected UIMenuItem knownVehicle;

protected UIMenuItem netVehicleId;
Expand Down Expand Up @@ -54,13 +55,15 @@ public DevMenu()
knownVehicle.Enabled = false;

vehicleFuelTank = new UIMenuItem("Vehicle fuel tank");
drainFuelTank = new UIMenuItem("Almost drain fuel tank");

mainMenu.AddItem(position);
mainMenu.AddItem(teleport);
mainMenu.AddItem(deleteVehicle);
mainMenu.AddItem(knownVehicle);
mainMenu.AddItem(vehicleModelId);
mainMenu.AddItem(vehicleFuelTank);
mainMenu.AddItem(drainFuelTank);

mainMenu.OnItemSelect += (sende, item, index) =>
{
Expand All @@ -84,6 +87,11 @@ public DevMenu()
Screen.ShowNotification("Fuel to model saved");
}
if (item == drainFuelTank && Game.PlayerPed.IsInVehicle())
{
Game.PlayerPed.CurrentVehicle.SetDecor(FRFuel.fuelLevelPropertyName, .5f);
}
if (item == deleteVehicle)
{
if (Game.PlayerPed.LastVehicle != null)
Expand Down
21 changes: 17 additions & 4 deletions FRFuel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,25 @@ public void ConsumeFuel(Vehicle vehicle)
fuel -= normalizedRPMValue * fuelRPMImpact;
fuel -= vehicle.Acceleration * fuelAccelerationImpact;
fuel -= vehicle.MaxTraction * fuelTractionImpact;

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

// FIXME: Temp engine cut-off
if (fuel == 0f && vehicle.IsEngineRunning)
{
vehicle.IsEngineRunning = false;
}

// Refueling at gas station
if (
// If we have gas station near us
currentGasStationIndex != -1 &&
// And ped is in range of sqrt(80) to it
// And near any pump
IsVehicleNearAnyPump(vehicle)
)
{
if (vehicle.Speed < 0.1f)
if (vehicle.Speed < 0.1f && fuel != 0) // Temp check for out of fuel as we're cutting engine off before
{
ControlEngine(vehicle);
}
Expand All @@ -306,7 +314,7 @@ public void ConsumeFuel(Vehicle vehicle)
}
}

if (Game.IsControlJustReleased(0, Control.Jump))
if (Game.IsControlJustReleased(0, Control.Jump) && addedFuelCapacitor > 0f)
{
TriggerEvent("frfuel:fuelAdded", addedFuelCapacitor);
TriggerServerEvent("frfuel:fuelAdded", addedFuelCapacitor);
Expand All @@ -321,6 +329,12 @@ public void ConsumeFuel(Vehicle vehicle)
}
else
{
// FIXME: Temp engine cut-off
if (fuel != 0f && !vehicle.IsEngineRunning)
{
vehicle.IsEngineRunning = true;
}

hudActive = false;
}

Expand Down Expand Up @@ -581,7 +595,6 @@ public async Task OnTick()

ConsumeFuel(vehicle);
RenderUI(playerPed);

}
else
{
Expand Down

0 comments on commit 05e7a72

Please sign in to comment.