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.
Requirements
- The base stress resource must initialize
Player(source).state.stressbefore the item is tested. - The item name must exist in the selected inventory or framework item list.
- The server-side usable-item handler and inventory definition must use the same item name.
- Relief values should remain positive; the stress event or state write must clamp the final result at
0.
Implementation by framework
Add the item handler in 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:
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:
local relief = 10local relief = math.random(5, 10)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.
QBCore.Functions.CreateUseableItem('stress_relief', function(source)
TriggerClientEvent('my_resource:client:relieveStress', source, 20)
end)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.
ESX.RegisterUsableItem('stress_relief', function(source)
TriggerClientEvent('my_resource:client:relieveStress', source, 20)
end)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.
Testing checklist
- Give the item to a test player and confirm the inventory recognizes it as usable.
- Set the player's stress above the configured relief amount.
- Use one item and confirm only one item is consumed.
- Verify the replicated stress value decreases once and never falls below
0. - Confirm DynamicHUD updates without reconnecting.
- Test the success notification and any progress/animation owned by the inventory or framework.
- Repeat at
0stress and with an invalid player/item path to confirm the integration fails safely.