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
onEndfunctionCalled when timer reaches 0
fontnumber6Text font ID
timeColortableRGBA for normal time text
lowTimeColortableRGBA when time ≤ lowTime
bgColortableRGBA 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
textstringSubtitle text (nil or "" to remove)
colortableRGBA
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. Up to 10 icons are shown at once; extra icons are queued (FIFO) and auto-shown when an active icon is removed.

OptionTypeDefaultDescription
dictstring"BLIPS"Texture dictionary
namestring"blip_ambient_gang_leader"Texture name
colortableRGBA for icon
bgColortableRGBA for icon background
bgDictstringBackground texture dict
bgNamestringBackground texture name
sizenumber | stringSize preset (xs, s, md, lg, xl, 2xl) or numeric value (ex: 0.03);
iconWnumberIcon width override
iconHnumberIcon height override
bgWnumberBackground width override
bgHnumberBackground height override

MissionUI.updateIcon(id, opts)

Update an icon by ID (active or queued). Pass only the options you want to change. Supports the same visual fields as addIcon (dict, name, color, bg*, size, iconW, iconH), where size can be a preset or numeric value and keeps default icon/background proportions.

MissionUI.removeIcon(id)

Remove one icon.

MissionUI.removeAllIcons()

Remove all icons.

MissionUI.setIconSpacing(value)

Set icon spacing with a simple normalized level or raw value.

values = 1, 2, 3, ....

MissionUI.setStartLineY(value)

Set where the first mission line starts on Y (vertical screen position).

values = 1, 2, 3, ....


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
    -- Normalized spacing: 2 = default, 1 = half, 3 = bigger gaps
    MissionUI.setIconSpacing(2)

    -- Start lines lower on screen (5 ~= around half)
    MissionUI.setStartLineY(5)

    local icon1 = MissionUI.addIcon({
        dict = "BLIPS",
        name = "blip_ambient_gang_leader",
        color = { 255, 255, 255, 255 },
        size = "lg",
        bgW = 0.034,
        bgH = 0.048,
    })
    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 },
        size = 0.024,
    })

    -- 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)