Events
The events and state bags nx_hud adds for other resources, next to the ox_lib, ox_inventory and ox_target events it keeps. Worn gear, player settings, armour plates and inventory weights.
nx_hud raises the events of ox_lib, ox_inventory and ox_target with the
same names and payloads, for example ox_inventory:updateSlots and
ox_lib:notify. They are documented by Overextended:
ox_lib,
ox_inventory and
ox_target.
The inventory's hook events (shopPrice, licencePrice, buyLicense,
craftResult, openLockedVehicle and the rest) are registered with
exports.ox_inventory:registerHook. The ones nx_hud adds are on the
Exports page.
This page lists what nx_hud adds. Listen only: none of these is meant
to be triggered by other resources.
Server events
nx_hud:wornChanged
A local server event, raised when what a player wears changes: an item
put on or taken off, moved to another socket, or gone from the player's
inventory. It carries the player's server id and the same table as
getWornAccessories:
{ [socket] = { name, slot, label, metadata } }, empty when the player
wears nothing. It fires once per change, a moment after it, and not for
a change that leaves the worn gear as it was. Listen with
AddEventHandler: it does not come from a client.
AddEventHandler('nx_hud:wornChanged', function(playerId, worn)
local hasVest = worn.vest ~= nil
Player(playerId).state:set('wearsVest', hasVest, true)
end)Client events
nx_hud:settingsChanged
A local client event with the local player's F7 settings: once when
the HUD has loaded them after the player joins, and again after every
change they make. It carries settings and changed, the same tables as
getSettings. Listen with
AddEventHandler.
AddEventHandler('nx_hud:settingsChanged', function(settings, changed)
useKmh = settings.units == 'kmh'
end)nxinv:plateBroke
A net event the server sends to a player when one of the armour plates
in their worn vest breaks. It carries the plate's item name. The broken
plate leaves the vest, and NxInventory.armour.broken goes into the
player's pockets.
RegisterNetEvent('nxinv:plateBroke', function(plateName)
PlaySoundFrontend(-1, 'CHECKPOINT_MISSED', 'HUD_MINI_GAME_SOUNDSET', true)
end)nxinv:weight
A net event the server sends to every player who has an inventory open
next to their own, right after ox_inventory:updateSlots, whenever that
other inventory changes. It carries the other inventory's id and its new
total weight in grams. ox_inventory tells a viewer only their own weight.
RegisterNetEvent('nxinv:weight', function(inventoryId, weight)
print(('%s now weighs %d g'):format(inventoryId, weight))
end)State bags
seatbelt (player)
LocalPlayer.state.seatbelt is true while the local player wears
nx_hud's own seatbelt. It is written only while that belt is in use
(Config.seatbelt = 'own', or 'auto' with no seatbelt script running),
and is not replicated, so read it on the player's own client. The
isSeatbeltOn export works in
every mode.
AddStateBagChangeHandler('seatbelt', ('player:%s'):format(GetPlayerServerId(PlayerId())), function(_, _, value)
print('seatbelt', value)
end)nxhud:settings (player)
A player's F7 settings, replicated so the server can read them:
{ s = settings, c = changed }. The player's own client writes it when
the HUD loads and after a change, at most once a second. Read it through
getSettings on the
server, which checks the values first.
nxhud:ind (vehicle)
A vehicle's turn signals, replicated to every client: 0 off, 1 left,
2 right, 3 hazard lights. Only the driver sets it.
local signal = Entity(vehicle).state['nxhud:ind'] or 0
if signal == 3 then
-- the hazard lights are on
end