Skip to content

Mission UI ​

Image 1

A Native mission HUD with timer, icons, and subtitle. Layout stacks dynamically based on visible sections. Uses aspect-ratio correction for consistent display across resolutions.


Get the module ​

lua
local MissionUI = exports.bln_lib:missionUi()

API ​

Core ​

MethodDescription
MissionUI.visible(show)Show (true) or hide (false - State will still active). Call with no args to get current state.
MissionUI.isVisible()Returns whether the UI is visible
MissionUI.destroy()Full cleanup (stops timer, clears all, no callback)

Timer ​

MissionUI.startTimer(opts)

Start a countdown. UI shows automatically. When time reaches 0, UI hides and onEnd runs (if set).

OptionTypeDefaultDescription
timenumber60Duration in seconds
lowTimenumber5Seconds left before low-time color
onEndfunctionβ€”Called when timer reaches 0
fontnumber6Text font ID
timeColortableβ€”RGBA for normal time text
lowTimeColortableβ€”RGBA when time ≀ lowTime
bgColortableβ€”RGBA for timer background

MissionUI.stopTimer()

Pause the countdown. UI stays visible.

MissionUI.resumeTimer()

Resume the countdown from current value (after stopTimer).

MissionUI.endTimer()

Stop the countdown and hide the UI.


Subtitle ​

MissionUI.setSubtitle(opts)

Set or update subtitle. Use text = nil or text = "" to remove.

OptionTypeDefaultDescription
textstringβ€”Subtitle text (nil or "" to remove)
colortableβ€”RGBA
scalenumber0.35Text scale
fontnumber6Font ID
xnumber0.5Horizontal position

MissionUI.removeSubtitle()

Remove subtitle.


Icons ​

MissionUI.addIcon(opts) β†’ id

Add an icon. Returns an ID for later updates.

OptionTypeDefaultDescription
dictstring"BLIPS"Texture dictionary
namestring"blip_ambient_gang_leader"Texture name
colortableβ€”RGBA for icon
bgColortableβ€”RGBA for icon background
bgDictstringβ€”Background texture dict
bgNamestringβ€”Background texture name

MissionUI.updateIcon(id, opts)

Update an icon by ID. Pass only the options you want to change.

MissionUI.removeIcon(id)

Remove one icon.

MissionUI.removeAllIcons()

Remove all icons.


Full example ​

lua
local MissionUI = exports.bln_lib:missionUi()

-- Start mission with timer, subtitle, and objectives
function StartMission()
    -- 2-minute timer, low-time at 15 seconds, red when low
    MissionUI.startTimer({
        time = 120,
        lowTime = 15,
        timeColor = { 255, 255, 255, 255 },
        lowTimeColor = { 255, 80, 80, 255 },
        bgColor = { 0, 0, 0, 255 },
        onEnd = function()
            TriggerEvent("mission:failed", "Time expired")
        end,
    })

    -- Subtitle
    MissionUI.setSubtitle({
        text = "Escape before time runs out!",
        color = { 255, 255, 255, 255 },
    })

    -- Objective icons
    local icon1 = MissionUI.addIcon({
        dict = "BLIPS",
        name = "blip_ambient_gang_leader",
        color = { 255, 255, 255, 255 },
    })
    local icon2 = MissionUI.addIcon({
        dict = "BLIPS",
        name = "blip_ambient_sheriff",
        color = { 255, 200, 100, 255 },
    })

    -- Update icon when objective completes
    MissionUI.updateIcon(icon1, { color = { 100, 255, 100, 255 } })

    -- Update subtitle
    MissionUI.setSubtitle({ text = "1/2 objectives complete" })
end

-- Complete mission
function CompleteMission()
    MissionUI.endTimer()
    MissionUI.removeSubtitle()
    MissionUI.removeAllIcons()
end

-- Toggle UI visibility (e.g. when opening a menu)
MissionUI.visible(false)  -- hide
MissionUI.visible(true)   -- show
MissionUI.visible(not MissionUI.isVisible())  -- toggle

-- Pause/resume timer
MissionUI.stopTimer()
MissionUI.resumeTimer()

-- Cleanup on resource stop
AddEventHandler("onResourceStop", function(resourceName)
    if GetCurrentResourceName() == resourceName then
        MissionUI.destroy()
    end
end)