Skip to content

Commit

Permalink
fix(server): usingItem corrections
Browse files Browse the repository at this point in the history
Set usingItem when calling external useItem functions (ESX/QB).
Don't set usingItem if item use failed (e.g. error, canceled).
  • Loading branch information
thelindat committed Jan 1, 2024
1 parent dcc3b96 commit b690851
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m
return TriggerClientEvent('ox_lib:notify', source, { type = 'error', description = locale('item_not_enough', item.name) })
end
elseif not item.weapon and server.UseItem then
inventory.usingItem = data
-- This is used to call an external useItem function, i.e. ESX.UseItem / QBCore.Functions.CanUseItem
-- If an error is being thrown on item use there is no internal solution. We previously kept a list
-- of usable items which led to issues when restarting resources (for obvious reasons), but config
Expand All @@ -363,7 +364,6 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m
end

data.consume = consume
inventory.usingItem = data

---@type boolean
local success = lib.callback.await('ox_inventory:usingItem', source, data)
Expand All @@ -374,6 +374,8 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m

if not success then return end

inventory.usingItem = data

if consume and consume ~= 0 and not data.component then
data = inventory.items[data.slot]

Expand Down

0 comments on commit b690851

Please sign in to comment.