SetVehicleAutoRepairDisabled Still repairs vehicle

The SetVehicleAutoRepairDisabled native still repairs the vehicle the player is in.

SetVehicleAutoRepairDisabled(vehicle, true)

Is this a known bug? Or how to make it so the car doenst get fixed? No other “fix” or “repair” terms in the code!

What’s your use case and why is the vehicle getting “fixed”? That requires some other action, without sharing what that is and what you’re trying to achieve nobody can possibly help you

It is an ELS system which toggles extra’s. Nowehere in the script is a fix or repair mentioned, still, it keeps repairing the vehicle when the lights are on (toggling extra’s).

Enabling an extra on a vehicle repairs it, that’s base game behavior and it cannot be prevented in any way. If it’s an issue for your players, disable the ability to apply extras when the vehicle is damaged instead

With qb-radialmenu I am able to do that.

-- [...]
RegisterNetEvent('qb-radialmenu:client:setExtra', function(data)
    local string = data.id
    local replace = string:gsub('extra', '')
    local extra = tonumber(replace)
    local ped = PlayerPedId()
    local veh = GetVehiclePedIsIn(ped)
    if veh ~= nil then
        if GetPedInVehicleSeat(veh, -1) == ped then
            SetVehicleAutoRepairDisabled(veh, true) -- Forces Auto Repair off when Toggling Extra [GTA 5 Niche Issue]
            if DoesExtraExist(veh, extra) then
                if IsVehicleExtraTurnedOn(veh, extra) then
                    SetVehicleExtra(veh, extra, 1)
                else
                    SetVehicleExtra(veh, extra, 0)
                end
            else
-- error notify
            end
        else
            QBCore.Functions.Notify(Lang:t('error.not_driver'), 'error', 2500)
        end
    end
end)

But in my ELS:

-- [...]
    SetVehicleAutoRepairDisabled(vehicle, true)

    local intensityMultiplier = GetIntensityMultiplier(GetClockHours())

    local vehicleExtras = Config.Vehicles[vehicleModel].Extras
    for extra, pattern in pairs(patternTable) do
        CreateThread(function()
            local shouldThreadBeActive = true
            local extraHasLightEnabled = false

            CreateThread(function()
                while shouldThreadBeActive do
                    Wait(0)
                    for key, disableExtra in pairs(pattern) do
                        if (not shouldThreadBeActive) then break end
                        SetVehicleExtra(vehicle, extra, disableExtra)
-- [...]

It doesn’t work? Would you know how this comes?

The problem is related to the placement/scope of SetVehicleAutoRepairDisabled(vehicle, true).

In your qb-radialmenu snippet (which works), SetVehicleAutoRepairDisabled is called immediately before SetVehicleExtra.

However, in your ELS snippet, SetVehicleAutoRepairDisabled is called exactly once, outside of multiple nested threads (CreateThread) and a while ... Wait(0) loop.

Because FiveM and GTA V’s engine can execute thousands of ticks between that single declaration and the actual extra toggling, other scripts, game engine ticks, or the rapid toggling of multiple extras in the ELS strobe patterns can reset the vehicle’s repair state.

To fix this, you need to mirror the behavior from qb-radialmenu and call SetVehicleAutoRepairDisabled inside your loop, right before you toggle the extra.

Here is the corrected ELS snippet:

local intensityMultiplier = GetIntensityMultiplier(GetClockHours())
local vehicleExtras = Config.Vehicles[vehicleModel].Extras
for extra, pattern in pairs(patternTable) do
    CreateThread(function()
        local shouldThreadBeActive = true
        local extraHasLightEnabled = false
        
        CreateThread(function()
            while shouldThreadBeActive do
                Wait(0)
                for key, disableExtra in pairs(pattern) do
                    if (not shouldThreadBeActive) then break end
                    
                    -- Call it RIGHT HERE before modifying the extra
                    SetVehicleAutoRepairDisabled(vehicle, true)
                    SetVehicleExtra(vehicle, extra, disableExtra)
                    
                    -- [...]

Try and let me know!

1 Like

Issue was solved by this! Thank you so much! :blue_heart:

1 Like

No problem Odinsson! Happy to hear that i was able to help!

:wink:

1 Like