Ability Bar flashing constantly

Hi, i`m trying to create a resource that shows your current fuel state in the ability bar. The problem is that the ability bar isn’t showing constantly, it is flashing behind the blue bar-



CreateThread(function()
    while true do
        Wait(1000)
        local ped = PlayerPedId()
        if IsPedInAnyVehicle(ped, false) then
            local vehicle = GetVehiclePedIsIn(ped, false)
            local fuel = GetVehicleFuelLevel(vehicle)
            SetAbilityBarVisibilityInMultiplayer(true)
            SetAbilityBarValue(fuel, 100)
        else
            SetAbilityBarVisibilityInMultiplayer(false)
          end
    end
end)



Does it work if you are outside of the car? (change IsPedInAnyVehicle() to just true). If not, try to use SetAllowAbilityBarInMultiplayer - FiveM Natives @ Cfx.re Docs first, in the CreateThread(), before you start the loop.

If it does show while on-foot, try to set this SetVehicleKersAllowed - FiveM Natives @ Cfx.re Docs to true on the vehicle.

Thank you!

There was no problem while i was outside of a car so i tried the SetVehicleKresAllowed.

No change, it is flashing like before :frowning:


CreateThread(function()
    SetAllowAbilityBarInMultiplayer(true)
    print("[Fuel Display] SetAllowAbilityBarInMultiplayer im Thread gesetzt")
    
    while true do
        Wait(1000)
        local ped = PlayerPedId()
        
        if IsPedInAnyVehicle(ped, false) then
            local vehicle = GetVehiclePedIsIn(ped, false)
            local fuel = GetVehicleFuelLevel(vehicle)
            
            SetVehicleKersAllowed(vehicle, true)
            
            SetAbilityBarVisibilityInMultiplayer(true)
            SetAbilityBarValue(fuel, 100)
            print("[Fuel Display] Im Fahrzeug - Fuel: " .. math.floor(fuel) .. "% (mit KERS)")
        else
            SetAbilityBarVisibilityInMultiplayer(false)
            print("[Fuel Display] Zu Fuß - Bar versteckt")
        end
    end
end)



@CritteR

Huh… seems that I have the same issue. Kinda like the minimap not wanting to keep the UI while in-vehicle. I am checking now to see if I can find something in the scaleform

I have made a similiar script like 3 years ago with no even 10 lines of code. But i don’t know the code anymore :frowning: xd

Try this ghoul-ish nightmare.

--lua, client-side.
Citizen.CreateThread(function()
    local minimap = RequestScaleformMovie("minimap") --get the minimap scaleform A.K.A minimap.gfx
    SetRadarBigmapEnabled(true, false)      --]
    Wait(0)                                 --] This whole nonsense is to not fuck up the other parts of the minimap... not sure why, but it works.
    SetRadarBigmapEnabled(false, false)     --]
    
    while true do -- forever-loop. You can extend this logic to only hide the bars for specific players, or during a specific time, idk
        Wait(1000)
        local ped = PlayerPedId()
        if IsPedInAnyVehicle(ped, false) then
            local vehicle = GetVehiclePedIsIn(ped, false)
            local fuel = GetVehicleFuelLevel(vehicle)

            BeginScaleformMovieMethod(minimap, "SET_ABILITY_BAR_VISIBILITY_IN_MULTIPLAYER") -- Force the Scaleform to accept Ability bar in multiplayer.
            ScaleformMovieMethodAddParamBool(true) 
            EndScaleformMovieMethod() -- end the function, so the game can run it.
            BeginScaleformMovieMethod(minimap, "SET_ABILITY_BAR") -- Setup the ability bar value.
            ScaleformMovieMethodAddParamInt(math.floor(fuel)) -- Ability level. From 0 to 100 by default. Use int only. Floats will break it.
            EndScaleformMovieMethod() -- end the function, so the game can run it.
            BeginScaleformMovieMethod(minimap, "SET_ABILITY_BAR_VISIBLE") -- Set the bar to actually be visible.
            ScaleformMovieMethodAddParamBool(true)
            EndScaleformMovieMethod() -- end the function, so the game can run it.
        else
            BeginScaleformMovieMethod(minimap, "SET_ABILITY_BAR_VISIBILITY_IN_MULTIPLAYER") -- Force the Scaleform to hid Ability bar in multiplayer.
            ScaleformMovieMethodAddParamBool(false)
            EndScaleformMovieMethod() -- end the function, so the game can run it.
            BeginScaleformMovieMethod(minimap, "SET_ABILITY_BAR_VISIBLE") -- Set the bar to actually be hidden.
            ScaleformMovieMethodAddParamBool(false)
            EndScaleformMovieMethod() -- end the function, so the game can run it.
        end
    end
end)

This will overwrite the rocket boost / nitrous UI, but not the air bar (for when you are drowning).

:face_with_spiral_eyes: Thank you so much