GhiaccioScripts

HUD

Commands, exports & events

Commands, client and server exports, and how to hook up hunger, thirst and stress.

#Commands

Names and keys come from Config.Commands and Config.Editor.

CommandDefault keyDescription
/hudF7Opens the in-game editor
/togglehudnoneShow / hide the HUD
/cinematicnoneCinematic mode (black bars, HUD hidden)
/carcontrolnoneCar control panel (doors, windows, engine, lights, seats)
/seatbeltBBuilt-in seatbelt
/cruisenoneBuilt-in cruise control
/limiternoneBuilt-in speed limiter

Keys use RegisterKeyMapping, so each player can rebind them in Settings > Key Bindings > FiveM.

#Client exports

lua
exports.ghiaccio_hud:toggleHud(true)          -- show/hide (no argument: toggle)
exports.ghiaccio_hud:isHudVisible()
exports.ghiaccio_hud:openEditor() / closeEditor()
exports.ghiaccio_hud:setStress(v) / addStress(d) / removeStress(d) / getStress()   -- built-in stress
exports.ghiaccio_hud:setStatus('hunger'|'thirst'|'stress', 0..100) / getStatus(name)
exports.ghiaccio_hud:setCinematic(bool) / isCinematic()
exports.ghiaccio_hud:setStreamerMode(bool)
exports.ghiaccio_hud:setSeatbelt(bool) / isSeatbeltOn()
exports.ghiaccio_hud:hideWidget('cash', true)  -- registry id
exports.ghiaccio_hud:getLayout()

#Server exports

lua
exports.ghiaccio_hud:setStress(src, v)          -- 0..100; QBCore/Qbox: metadata, otherwise the client's built-in stress
exports.ghiaccio_hud:addStress(src, delta)
exports.ghiaccio_hud:getServerDefault()         -- JSON | false
exports.ghiaccio_hud:publishDefault(jsonString) -- no ACE check (console / other resources)

#Events

Local client events:

  • Emitted: ghiaccio_hud:client:visibility (bool).
  • Listened: ghiaccio_hud:client:toggle (bool) and ghiaccio_hud:client:seatbelt (bool). An external seatbelt script can report its state with the latter.

#Hooking up hunger, thirst and stress

#(a) Automatic

On ESX the esx_status adapter reads hunger and thirst (and stress if a third-party script adds it to esx_status). On QBCore / Qbox the player metadata (hunger, thirst, stress) and the hud:client:UpdateNeeds / hud:client:UpdateStress events are read. Nothing to configure (Config.Integrations.status = 'auto').

#(b) setStatus / getStatus exports

For a metabolism or any script that manages hunger, thirst or stress. On the client:

lua
-- name: 'hunger' | 'thirst' | 'stress'; value: number 0..100
-- (out of range is clamped; non-number types are rejected and return false)
RegisterNetEvent('my_metabolism:update', function(h, t)
    exports.ghiaccio_hud:setStatus('hunger', h)
    exports.ghiaccio_hud:setStatus('thirst', t)
end)
local hunger = exports.ghiaccio_hud:getStatus('hunger')     -- value shown by the HUD, or nil

It turns itself on at the first call of setStatus (or right away with Config.Integrations.status = 'exports', in which case hunger / thirst stay hidden until some script sets them). If another adapter (esx_status, qb) is already active, export values win; entries never set through the export keep coming from the other adapter. With Config.Integrations.status = false the export is disabled (setStatus returns false).

setStatus('stress', v) stays consistent with setStress / addStress.

#(c) Writing an adapter

Create adapters/status/my_metabolism.lua (copy esx_status.lua; files in adapters/ are not encrypted):

lua
local cache = {}
GHUD.Adapters.register('status', 'my_metabolism', {
    resource = 'my_metabolism',                                  -- detected when the resource is started
    provides = { hunger = true, thirst = true, stress = false }, -- what it provides: the rest stays hidden
    start = function()
        AddEventHandler('my_metabolism:tick', function(hunger, thirst)
            if type(hunger) == 'number' then cache.hunger = hunger end
            if type(thirst) == 'number' then cache.thirst = thirst end
            GHUD.Adapters.changed('status')                      -- the HUD rereads and sends the diff to the NUI
        end)
    end,
    read = function() return cache.hunger, cache.thirst, nil end, -- hunger, thirst, stress (0..100, nil = not provided)
})

Then add 'adapters/status/my_metabolism.lua', to fxmanifest.lua (client_scripts, after adapters/status/qb.lua) and, to force it, set Config.Integrations.status = 'my_metabolism'. With 'auto', adapters are tried in manifest order.

#(d) No source

If hunger and thirst are not configured (no adapter, no setStatus call) the icons are hidden and the other icons of the group close the gap automatically.