[Request] Always keep vehicles clean

Not sure how it would be done or if it’s even possible but is there a way to make all vehicles stay clean? I’m sure others have the same frustration when window dirt builds up as you drive and obstructs lights on emergency vehicles, but it’s annoying have to use at trainer or command to clean the vehicle constantly. Anyone know a way to do it for all vehicles?

SetVehicleDirtLevel and run it once every once in a while

You should give search a try, There is all kinds of good info.

Or you could edit the car its self and alpha out the dirt layer as well using Open IV.

1 Like

Sorry maybe I should have been a bit clearer, I’m wanting to know whether anybody knows how to do it for all vehicles. Doing it in the vehicles.meta would only be useful for add-on or modified vehicles since AFAIK there isn’t a vehicles.meta for all base game vehicles I can just edit?

function GetVehicles()
    local vehicles = {}
    local success = true;
    local searchHandle, vehicleHandle = FindFirstVehicle();

    repeat
        table.insert(vehicles, vehicleHandle);
        success, vehicleHandle = FindNextVehicle(searchHandle)
    while not success

    EndFindVehicles(searchHandle)
    return vehicles;
end

function CleanAllVehicles(vehicleList)
    -- We probably want to create a delta list,
    -- Because calling natives is not exactly cheap.
    -- Especially not for _every_ vehicle.
    for i = 1, #vehicleList do
        SetVehicleDirtLevel(vehicleList[i], 0.0);
    end
end

Citizen.CreateThread(function() 
    while true do
        local vehicles = GetAllVehicles();
        Citizen.Wait(1000);
    end
end)
Disclaimer: This code is for educational purposes, I did not test nor do I intend to provide support for the given code snippet.

In case the vehicles.meta thing doesn’t pan out, you could iterate over all the vehicles. It’s definitely not the most efficient way of getting only clean vehicles.

1 Like