Skip to content

Commit 337dcdb

Browse files
committed
fix(vehicles): keep clean now catches slowly building dirt
1 parent fb231d7 commit 337dcdb

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/Client/vMenu.Enhanced.Events/LocalVehicleTicks.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CitizenFX.FiveM.Client;
1+
using CitizenFX.FiveM.Client;
22

33
using vMenu.Enhanced.Data.Ticks;
44
using vMenu.Enhanced.Ticks;
@@ -456,14 +456,21 @@ private static void PollDirt()
456456

457457
var gained = dirt - _dirt;
458458

459-
_dirt = dirt;
460-
461459
// Washing moves the same number downwards, which is not getting dirty.
462460
if (vehicle == 0 || gained < DirtThreshold)
463461
{
462+
// Dirt builds up slower than the threshold per poll, so the baseline only moves once a gain is
463+
// reported. Moving it every poll would lose the whole build up a fraction at a time.
464+
if (gained < 0f)
465+
{
466+
_dirt = dirt;
467+
}
468+
464469
return;
465470
}
466471

472+
_dirt = dirt;
473+
467474
var dirtied = new VehicleDirtied(vehicle, dirt, gained);
468475

469476
Dispatch.Raise(_dirtied, dirtied, nameof(VehicleDirtied));

src/Client/vMenu.Enhanced.Menus/Vehicles/VehicleKeepClean.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using CitizenFX.FiveM.Client;
1+
using CitizenFX.FiveM.Client;
22

3+
using vMenu.Enhanced.Data.Ticks;
34
using vMenu.Enhanced.Events;
45
using vMenu.Enhanced.Permissions;
56
using vMenu.Enhanced.Storage;
7+
using vMenu.Enhanced.Ticks;
68

79
using VehicleOptionsPermissions = vMenu.Enhanced.Data.Permissions.Menus.VehicleOptions;
810

@@ -12,8 +14,14 @@ namespace vMenu.Enhanced.Menus.Vehicles;
1214
// same distinction VehicleWash makes.
1315
public static class VehicleKeepClean
1416
{
17+
// The dirt watcher only reports a gain big enough to be worth an event, so a slow drizzle of dirt can
18+
// sit under it. This sweep is what catches that.
19+
private const long SweepIntervalMs = 10000;
20+
1521
private static bool _watching;
1622

23+
private static TickHandle? _sweep;
24+
1725
public static bool Enabled => UserDefaults.VehicleKeepClean.Value && IsAllowed;
1826

1927
private static bool IsAllowed => ClientPermissions.IsAllowed(VehicleOptionsPermissions.KeepClean);
@@ -23,6 +31,8 @@ public static void Initialize()
2331
{
2432
ClientPermissions.PermissionsChanged += Apply;
2533

34+
_sweep = TickRegistry.Register("Vehicle.KeepClean", Sweep, TickRate.Every(SweepIntervalMs), () => Enabled);
35+
2636
Apply();
2737
}
2838

@@ -45,6 +55,8 @@ private static void Apply()
4555

4656
Watch(on);
4757

58+
_sweep?.Reevaluate();
59+
4860
if (!on)
4961
{
5062
return;
@@ -74,6 +86,8 @@ private static void Watch(bool watching)
7486
LocalVehicleTicks.VehicleChanged -= OnChanged;
7587
}
7688

89+
private static void Sweep() => Wash(OwnVehicle.Driven());
90+
7791
private static void OnDirtied(VehicleDirtied _) => Wash(OwnVehicle.Driven());
7892

7993
// The dirt watcher re-seeds on a new vehicle rather than reporting it, so getting into one that is

0 commit comments

Comments
 (0)