Envi Scripts Documentation
  • 👋Introduction
  • 🌉Envi-Bridge
  • ⚙️Compatibility
  • 🖨️Licensing
  • 📒Premium Scripts
    • ❔FAQ / COMMON ISSUES
    • ‼️FIRST STEPS (READ FIRST)
    • ⭐Useful Resources
    • 👀Envi FiveM Showcase Server
    • 📸Envi-Camera
      • ❗First Steps
      • Inventory Setup
      • Editable Functionality
      • Complete Lens Kit
      • Printing Photos
      • Ped Reactions
      • Exports
      • Config File
    • 🪚Envi-ChopShop
      • Inventory Setup
      • How to Chop
      • Props for AntiCheats
      • Editable Functionality
      • Config File
    • 🪣Envi-Dumpsters
      • Common Issues
      • Inventory Setup
      • Editable Functionality
      • Exports
      • Exclusive Zones
      • Survival Items
      • Shopping Carts
      • Hobo Bowling
      • Hobo Taxi
      • Rats and Racoons
      • Config File
      • V2 Config
    • 💺Envi-Ejector-Seats
      • Inventory Setup
      • How to Eject
      • Editable Functionality
      • Config File
    • 🔥Envi-Flamethrower (Standalone)
      • Common Issues
      • Inventory Setup
      • Refueling
      • Editable Functionality
      • Config File
    • 🪽Envi-Flight-Suits
      • Inventory Setup
      • Flight Suits
      • Config File
    • 🍜Envi-Food-Truck
      • ❗VooDoo Required
      • Common Issues
      • Inventory Setup
      • Adding Additional Grill Items
      • Unique Shops with Liveries
      • Spawning the Trucks
      • Using the Trucks
      • Exports
      • Config File
    • 💍Envi-Forever-Rings
      • Inventory Setup
      • Editable Functionality
      • Ring Shop MLO
      • Config File
    • 💻Envi-Hack-Minigames (Standalone)
      • The Worm
      • Password
      • Firewall
      • Node Runner
      • Config File
    • 🎞️Envi-HUD
      • ❗First Time Setup
      • Common Issues
      • Inventory Setup
      • Adding Custom Weapons
      • Change Logo
      • Custom Fonts
      • Converting Notifications
      • Converting Progress Bars
      • Editable Functionality
      • Settings Save Location
      • Exports and Events
      • Commands
      • Vehicle Control
      • Anti Muscle Spasm
      • Ragdoll
      • Config File
    • 🎇Envi-Items
      • Inventory Setup
      • Config File
    • 🚑Envi-Medic
      • Common Issues
      • Fully Disable Transport to Hospital
      • Failsafe
      • Ambulance Scripts
      • Vehicle Fuel
      • Vehicle Keys
      • Exports
      • Config File
    • ☄️Envi-MethVan
      • Common Issues
      • Inventory Setup
      • Cooking Process
      • Editable Functionality
      • Adding a Vehicle
      • Config File
    • 🍃Envi-Megablower9000 (Standalone)
      • Inventory Setup
      • Config File
    • 👯Envi-Population (Standalone)
      • ❗Initial Setup
      • Common Issues
      • Config File
    • 🗒️Envi-Prescriptions
      • Common Issues
      • Inventory Setup
      • Editable Functionality
      • Config File
    • 🔧Envi-Sabotage
      • ❗First Time Setup
      • Common Issues
      • Inventory Setup
      • Exports
    • 🛒Envi-Shops
      • Common Issues
      • Inventory Setup
      • Exports
      • Editable Functionality
      • Config File
    • 📱Envi-Trap-Phone
      • Common Issues
      • Inventory Setup
      • Commands
      • Exports
      • Adding Custom Drugs
      • Using the Phone
      • Disabling Extra Services
      • Config Files
        • config.lua
        • dialogueSettings.lua
        • extraServices.lua
        • gangZoneSettings.lua
        • personalitySettings.lua
        • specialContactSettings.lua
    • 👰Envi-Weddings
      • Inventory Setup
      • Starting Info
      • Manually Removing Data
      • Commands
      • Config File
    • 🎅Envi Xmas-Weapons (Standalone)
      • Inventory Setup
      • Config File
    • 🗡️Envi-Zombie-Weapons (Standalone)
      • Inventory Setup
    • 🧟‍♂️Envi-Zombies
Powered by GitBook
On this page
  1. Premium Scripts
  2. Envi-HUD

Converting Progress Bars

To Envi-Hud

Converting ox_lib progress bars to Envi-Hud

REQUIRES OX_LIB v3.3.0 OR HIGHER

  1. Navigate to ox_lib/resource/interface/client/progress.lua

  2. Delete every single line of code in this file

  3. Add the following of code to the now-empty file:

  4. local progress
    local DisableControlAction = DisableControlAction
    local DisablePlayerFiring = DisablePlayerFiring
    local playerState = LocalPlayer.state
    local createdProps = {}
    
    ---@class ProgressPropProps
    ---@field model string
    ---@field bone? number
    ---@field pos vector3
    ---@field rot vector3
    ---@field rotOrder? number
    
    ---@class ProgressProps
    ---@field label? string
    ---@field duration number
    ---@field position? 'middle' | 'bottom'
    ---@field useWhileDead? boolean
    ---@field allowRagdoll? boolean
    ---@field allowCuffed? boolean
    ---@field allowFalling? boolean
    ---@field allowSwimming? boolean
    ---@field canCancel? boolean
    ---@field anim? { dict?: string, clip: string, flag?: number, blendIn?: number, blendOut?: number, duration?: number, playbackRate?: number, lockX?: boolean, lockY?: boolean, lockZ?: boolean, scenario?: string, playEnter?: boolean }
    ---@field prop? ProgressPropProps | ProgressPropProps[]
    ---@field disable? { move?: boolean, sprint?: boolean, car?: boolean, combat?: boolean, mouse?: boolean }
    
    local function createProp(ped, prop)
        lib.requestModel(prop.model)
        local coords = GetEntityCoords(ped)
        local object = CreateObject(prop.model, coords.x, coords.y, coords.z, false, false, false)
    
        AttachEntityToEntity(object, ped, GetPedBoneIndex(ped, prop.bone or 60309), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true,
            true, false, true, prop.rotOrder or 0, true)
        SetModelAsNoLongerNeeded(prop.model)
    
        return object
    end
    
    local function interruptProgress(data)
        if not data.useWhileDead and IsEntityDead(cache.ped) then return true end
        if not data.allowRagdoll and IsPedRagdoll(cache.ped) then return true end
        if not data.allowCuffed and IsPedCuffed(cache.ped) then return true end
        if not data.allowFalling and IsPedFalling(cache.ped) then return true end
        if not data.allowSwimming and IsPedSwimming(cache.ped) then return true end
    end
    
    local isFivem = cache.game == 'fivem'
    
    local controls = {
        INPUT_LOOK_LR = isFivem and 1 or 0xA987235F,
        INPUT_LOOK_UD = isFivem and 2 or 0xD2047988,
        INPUT_SPRINT = isFivem and 21 or 0x8FFC75D6,
        INPUT_AIM = isFivem and 25 or 0xF84FA74F,
        INPUT_MOVE_LR = isFivem and 30 or 0x4D8FB4C1,
        INPUT_MOVE_UD = isFivem and 31 or 0xFDA83190,
        INPUT_DUCK = isFivem and 36 or 0xDB096B85,
        INPUT_VEH_MOVE_LEFT_ONLY = isFivem and 63 or 0x9DF54706,
        INPUT_VEH_MOVE_RIGHT_ONLY = isFivem and 64 or 0x97A8FD98,
        INPUT_VEH_ACCELERATE = isFivem and 71 or 0x5B9FD4E2,
        INPUT_VEH_BRAKE = isFivem and 72 or 0x6E1F639B,
        INPUT_VEH_EXIT = isFivem and 75 or 0xFEFAB9B4,
        INPUT_VEH_MOUSE_CONTROL_OVERRIDE = isFivem and 106 or 0x39CCABD5
    }
    
    ---@param data ProgressProps
    local function startProgress(data)
        playerState.invBusy = true
        progress = data
        local anim = data.anim
        local progressResult = false
        local progressCompleted = false
    
        if anim then
            if anim.dict then
                lib.requestAnimDict(anim.dict)
    
                TaskPlayAnim(cache.ped, anim.dict, anim.clip, anim.blendIn or 3.0, anim.blendOut or 1.0, anim.duration or -1, anim.flag or 49, anim.playbackRate or 0,
                    anim.lockX, anim.lockY, anim.lockZ)
                RemoveAnimDict(anim.dict)
            elseif anim.scenario then
                TaskStartScenarioInPlace(cache.ped, anim.scenario, 0, anim.playEnter == nil or anim.playEnter --[[@as boolean]])
            end
        end
    
        if data.prop then
            playerState:set('lib:progressProps', data.prop, true)
        end
    
        -- Convert ox_lib progress data to envi-hud format
        local enviHudData = {
            label = data.label,
            duration = data.duration,
            canCancel = data.canCancel,
            animation = nil,
            prop = nil,
            propTwo = nil,
            controlDisables = {
                disableMovement = data.disable and data.disable.move,
                disableCarMovement = data.disable and data.disable.car,
                disableMouse = data.disable and data.disable.mouse,
                disableCombat = data.disable and data.disable.combat
            },
            onComplete = function()
                progressCompleted = true
                progressResult = true
            end,
            onCancel = function()
                progressCompleted = true
                progressResult = false
            end
        }
    
        exports['envi-hud']:ProgressBar(enviHudData)
        
        local interruptCheckThread = CreateThread(function()
            while progress and not progressCompleted do
                if interruptProgress(progress) then
                    exports['envi-hud']:CancelProgressBar()
                    progress = false
                    progressResult = false
                    progressCompleted = true
                end
                Wait(100)
            end
        end)
    
        while not progressCompleted do
            Wait(100)
        end
    
        if data.prop then
            playerState:set('lib:progressProps', nil, true)
        end
    
        if anim then
            if anim.dict then
                StopAnimTask(cache.ped, anim.dict, anim.clip, 1.0)
                Wait(0)
            else
                ClearPedTasks(cache.ped)
            end
        end
    
        playerState.invBusy = false
        progress = nil
        
        return progressResult
    end
    
    ---@param data ProgressProps
    ---@return boolean?
    function lib.progressBar(data)
        while progress ~= nil do Wait(0) end
    
        if not interruptProgress(data) then
            return startProgress(data)
        end
    end
    
    ---@param data ProgressProps
    ---@return boolean?
    function lib.progressCircle(data)
        while progress ~= nil do Wait(0) end
    
        if not interruptProgress(data) then
            return startProgress(data)
        end
    end
    
    function lib.cancelProgress()
        if not progress then
            error('No progress bar is active')
        end
    
        exports['envi-hud']:CancelProgressBar()
        progress = false
    end
    
    ---@return boolean
    function lib.progressActive()
        return progress and true
    end
    
    RegisterCommand('cancelprogress', function()
        if progress?.canCancel then 
            exports['envi-hud']:CancelProgressBar()
            progress = false 
        end
    end)
    
    if isFivem then
        RegisterKeyMapping('cancelprogress', locale('cancel_progress'), 'keyboard', 'x')
    end
    
    local function deleteProgressProps(serverId)
        local playerProps = createdProps[serverId]
        if not playerProps then return end
        for i = 1, #playerProps do
            local prop = playerProps[i]
            if DoesEntityExist(prop) then
                DeleteEntity(prop)
            end
        end
        createdProps[serverId] = nil
    end
    
    RegisterNetEvent('onPlayerDropped', function(serverId)
        deleteProgressProps(serverId)
    end)
    
    AddStateBagChangeHandler('lib:progressProps', nil, function(bagName, key, value, reserved, replicated)
        if replicated then return end
    
        local ply = GetPlayerFromStateBagName(bagName)
        if ply == 0 then return end
    
        local ped = GetPlayerPed(ply)
        local serverId = GetPlayerServerId(ply)
    
        if not value then
            return deleteProgressProps(serverId)
        end
    
        createdProps[serverId] = {}
        local playerProps = createdProps[serverId]
    
        if value.model then
            playerProps[#playerProps + 1] = createProp(ped, value)
        else
            for i = 1, #value do
                local prop = value[i]
    
                if prop then
                    playerProps[#playerProps + 1] = createProp(ped, prop)
                end
            end
        end
    end)

Convert qb-core progress bars to Envi-Hud

  1. Navigate to qb-core/client/functions.lua

  2. Find the QBCore.Functions.Progressbar function

  3. Replace the entire function with the following:

  4. function QBCore.Functions.Progressbar(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel)
        if GetResourceState('envi-hud') ~= 'started' then error('envi-hud needs to be started in order for QBCore.Functions.Progressbar to work') end
    
        if animation and not next(animation) then
            animation = nil
        end
    
        if prop and not next(prop) then
            prop = nil
        end
    
        if propTwo and not next(propTwo) then
            propTwo = nil
        end
    
        local data = {
            label = label,
            duration = duration,
            canCancel = canCancel,
            animation = animation,
            prop = prop,
            propTwo = propTwo,
            controlDisables = disableControls,
            onComplete = function()
                if onFinish then
                    onFinish()
                end
            end,
            onCancel = function()
                if onCancel then
                    onCancel()
                end
            end
        }
    
        exports['envi-hud']:ProgressBar(data)
    end
PreviousConverting NotificationsNextEditable Functionality

Last updated 23 days ago

📒
🎞️