Skip to content

Commit

Permalink
fix(server): set inventory.weapon after item use
Browse files Browse the repository at this point in the history
Item use may be cancelled or fail for some reason.
With e363dc this also properly resolves #1310.
  • Loading branch information
thelindat committed May 11, 2023
1 parent 0bf8fe5 commit 5e855af
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m
if item and data and data.count > 0 and data.name == item.name then
data = {name=data.name, label=label, count=data.count, slot=slot, metadata=data.metadata}

if item.weapon then
inventory.weapon = inventory.weapon ~= slot and slot or nil
elseif item.ammo then
if item.ammo then
if inventory.weapon then
local weapon = inventory.items[inventory.weapon]

Expand Down Expand Up @@ -336,6 +334,10 @@ lib.callback.register('ox_inventory:useItem', function(source, itemName, slot, m

local success = lib.callback.await('ox_inventory:usingItem', source, data)

if item.weapon then
inventory.weapon = success and slot or nil
end

if not success then return end

if consume and consume ~= 0 and not data.component then
Expand Down

0 comments on commit 5e855af

Please sign in to comment.