Skip to content

Commit a8648d2

Browse files
committed
Add events
1 parent 62bcad5 commit a8648d2

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

FRFuel.cs

+25-18
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ public class FRFuel : BaseScript {
2121
protected float fuelTractionImpact = 0.0001f;
2222
protected float fuelRPMImpact = 0.0005f;
2323

24-
protected Random random = new Random();
25-
26-
public HUD hud;
27-
24+
public float showMarkerInRangeSquared = 2500f;
25+
2826
#if DEBUG
2927
public Dev.DevMenu menu;
3028
#endif
3129

32-
public float showMarkerInRangeSquared = 2500f;
33-
public Blip currentGasStation;
34-
35-
public float totalFuelAddedToVehicle = 0f;
30+
public HUD hud;
31+
public Random random = new Random();
3632

33+
protected Blip currentGasStation;
3734
protected Vehicle lastVehicle;
35+
3836
protected bool currentVehicleFuelLevelInitialized = false;
3937
protected bool hudActive = false;
38+
protected bool refuelAllowed = true;
39+
protected float addedFuelCapacitor = 0f;
4040

4141
protected InLoopOutAnimation jerryCanAnimation;
4242
#endregion
@@ -58,6 +58,12 @@ public FRFuel() {
5858
CreateJerryCanPickUps();
5959
});
6060

61+
EventHandlers["frfuel:refuelAllowed"] += new Action<dynamic>((dynamic toggle) => {
62+
if (toggle.GetType() == typeof(bool)) {
63+
refuelAllowed = (bool) toggle;
64+
}
65+
});
66+
6167
blips = new Blip[GasStations.positions.Length];
6268
pickups = new Pickup[GasStations.positions.Length];
6369

@@ -160,19 +166,20 @@ public void ConsumeFuel(Vehicle vehicle) {
160166
} else {
161167
hud.InstructRefuelOrTurnOnEngine();
162168

163-
if (Game.IsControlPressed(0, Control.Jump)) {
164-
if (fuel < fuelTankCapacity) {
165-
fuel += 0.1f;
166-
totalFuelAddedToVehicle += 0.1f;
169+
if (refuelAllowed) {
170+
if (Game.IsControlPressed(0, Control.Jump)) {
171+
if (fuel < fuelTankCapacity) {
172+
fuel += 0.1f;
173+
addedFuelCapacitor += 0.1f;
174+
}
167175
}
168-
}
169176

170-
if (Game.IsControlJustReleased(0, Control.Jump)) {
171-
// Trigger onRefuelComplete Cient-Side Event. Return 1 argument with amount of fuel added to vehicle.
172-
TriggerEvent("onRefuelComplete", Math.Round(Convert.ToDouble(totalFuelAddedToVehicle)));
173-
totalFuelAddedToVehicle = 0f;
177+
if (Game.IsControlJustReleased(0, Control.Jump)) {
178+
TriggerEvent("frfuel:fuelAdded", addedFuelCapacitor);
179+
TriggerServerEvent("frfuel:fuelAdded", addedFuelCapacitor);
180+
addedFuelCapacitor = 0f;
181+
}
174182
}
175-
176183
}
177184

178185
hud.RenderInstructions();

0 commit comments

Comments
 (0)