Orbit StudiosOrbit Studios
Orbit Studios Resourcesorbit-dynamichud-stress

Stress Relief Items

Add inventory or framework items that relieve DynamicHUD stress.

Stress Relief Items

Stress relief items lower the replicated stress state value that DynamicHUD reads. The examples below show where the item logic belongs for each inventory or framework style.

ox_inventory implementation

The ox_inventory example uses the same server-side item export pattern as the GitBook docs. Put the export in ox_inventory/modules/items/server.lua, not in a custom client export.

Add the item handler in ox_inventory/modules/items/server.lua:

ox_inventory/modules/items/server.lua
exports('cigarette', function(event, item, inventory, slot, data)
    local src = inventory.id

    -- Player is attempting to use the item
    if event == 'usingItem' then
        local currentStress = Player(src)?.state?.stress or 0
        local relief = math.random(5, 10)
        local newStress = math.max(currentStress - relief, 0)

        Player(src)?.state:set("stress", newStress, true)
    end

    -- Player finished using the item
    if event == 'usedItem' then
        TriggerClientEvent('ox_lib:notify', src, {
            description = 'You feel better already'
        })
    end
end)

Then define the usable item in ox_inventory/data/items.lua:

ox_inventory/data/items.lua
cigarette = {
    label = "Cigarette",
    weight = 10,
    stack = true,
    consume = 1
}

usingItem runs when the player starts using the item. The handler reads the current stress state, removes a random amount from 5 to 10, clamps the result so it never goes below 0, and replicates the new value with Player(src)?.state:set("stress", newStress, true).

usedItem runs after the item finishes consuming. The GitBook implementation uses this event to show an ox_lib notification.

To change the relief amount, only change the relief line:

ox_inventory/modules/items/server.lua
local relief = 10
ox_inventory/modules/items/server.lua
local relief = math.random(5, 10)
ox_inventory/modules/items/server.lua
local relief = math.random(20, 30)

Use this pattern when your server uses QBCore usable items instead of ox_inventory item exports. Put the server callback in any started server resource, then trigger the stress resource server event with the amount you want to remove.

resources/[custom]/server/main.lua
QBCore.Functions.CreateUseableItem('stress_relief', function(source)
    TriggerClientEvent('my_resource:client:relieveStress', source, 20)
end)
resources/[custom]/client/main.lua
RegisterNetEvent('my_resource:client:relieveStress', function(amount)
    TriggerServerEvent('hud:server:RelieveStress', amount)
end)

Add the item to your QB inventory item list using the same item name, stress_relief. If the inventory item name does not match the usable item name, the callback will never run.

Use this pattern when your server uses ESX usable items. The ESX callback runs on the server, sends a small client event to the player, and the client asks the stress addon to remove stress.

resources/[custom]/server/main.lua
ESX.RegisterUsableItem('stress_relief', function(source)
    TriggerClientEvent('my_resource:client:relieveStress', source, 20)
end)
resources/[custom]/client/main.lua
RegisterNetEvent('my_resource:client:relieveStress', function(amount)
    TriggerServerEvent('hud:server:RelieveStress', amount)
end)

Add the stress_relief item to your ESX inventory or item database before testing the usable item callback.

On this page