hud.setField 5

Creates a custom field on the bar, or updates it if a field with the same id already exists. Fields are drawn in creation order, so the first setField call for a given id decides its position.


Return value

Return TypeDescription
voidThis function doesn't return anything

Parameters

ParameterTypeDescription
1stringIdentifier of the field. Reuse the same id to update a field you already created.
2stringName of the sprite to show next to the value, taken from the ItemsDatabase. Pass an empty string for a text-only field.
3stringThe text to display, already formatted. Numbers must be converted to string first.

Examples

Custom conquer bar

-- Replace the vanilla conquer bar with two fields of our own.
-- Runs on every client: no network sync needed.

hud.setVanillaBar(false)   -- hide flags, tickets and capture squares
hud.setPhases(false)       -- this mission does not advance through phases

local wave = 1
local left = 12

local function refresh()
    hud.setField("wave", "hud_icon_wave", "Wave " .. wave)
    hud.setField("enemies", "hud_icon_enemy", tostring(left))

    -- keep the counter from making the bar jump as digits change
    hud.setFieldWidth("enemies", 60)

    -- turn the counter red when the position is about to fall
    if left <= 3 then
        hud.setFieldColor("enemies", 1, 0.35, 0.35)
    else
        hud.setFieldColor("enemies", 1, 1, 1)
    end
end

refresh()

Back to Scripting API