Functions

Integrating HUD with Your Framework: Exploring Built-in Functions, Parameters, and Responses.

All the functions listed below are exported so you can use them from any other resource.

InitHud(): void

Function to tell the script that HUD can be loaded. Usualy you would want to call as soon as player is loaded.

InitHud()

UpdateStatus(statuses: Object): void

Function used to update the status hud statuses. Should be used inside some kind of thread or your status system's update ticker.

Param

statuses - Object that keys are name of status and values are status value.

UpdateStatus({
    ['health'] = 98,
    ['armor'] = 0,
    ['hunger'] = 78.55,
    ['thirst'] = 41.38
})

UpdateInfo(info: Object): void

Function used to update the info hud infos. If you have infos that are static you don't need to pass them everytime you update other dynamic values. Should be used inside thread.

Param

info - Object that keys are name of info and values are the info value.

UpdateInfo({
    ['players'] = "15/128"
})

DisplayHud(bool: boolean): void

Function to set HUD display on/off.

Param

bool - should the hud be displayed.

DisplayHud(false)

IsHudDisplayed(): boolean

Function to get current HUD display status.

Response

true/false

print(IsHudDisplayed()) -- -> false

CreateNotification(message: string, duration: number, type: NotifType): void

Function to display notification. HUD has built-in notifications system that you can use. This function could be added inside your frameworks CreateNotification function or simply call it where you want to use it. Also HUD provides events that you can create notification from to make it easier for you to use.

-- If called from server-side
TriggerClientEvent('sx-hud:createNotification', source, message, duration, type)
-- If called from client-side
TriggerEvent('sx-hud:createNotification', message, duration, type)

Params

message - notification message.

duration - for how long does notification should be shown. In miliseconds.

type - success | error | info notification type. If you don't specify it, by default it will be info .

CreateNotification(
    "My cool message",
    3000,
    "success"
)

Notification text color

The notification system has built-in support for changing text color. You can change the entire text color or only specific words using HEX color codes. Everything between <#COLOR_CODE> and </> will be rendered in the desired color.

If you pass to `CreateNotification` params message like so:

CreateNotification(
    "My <#0000FF>cool</> message",
    3000,
    "success"
)

Notification message will be rendered as "My cool message".

Last updated