Skip to content

Commit

Permalink
fix(client): update inventory when buying items
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Apr 24, 2023
1 parent 2fc81b4 commit d000bc0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ local defaultInventory = {
maxWeight = shared.playerweight,
items = {}
}

local currentInventory = defaultInventory

local function closeTrunk()
Expand Down Expand Up @@ -830,6 +831,8 @@ end

RegisterNetEvent('ox_inventory:closeInventory', client.closeInventory)

---@param items updateSlot[]
---@param weight number | table<string, number>
local function updateInventory(items, weight)
-- todo: combine iterators
local changes = {}
Expand Down Expand Up @@ -1704,10 +1707,17 @@ RegisterNUICallback('swapItems', function(data, cb)
end)

RegisterNUICallback('buyItem', function(data, cb)
---@type boolean, false | { [1]: number, [2]: SlotWithItem, [3]: SlotWithItem | false, [4]: number}, NotifyProps
local response, data, message = lib.callback.await('ox_inventory:buyItem', 100, data)

if data then
updateInventory({ item = data[2], inventory = cache.serverId }, data[4])
updateInventory({
{
item = data[2],
inventory = cache.serverId
}
}, data[4])

SendNUIMessage({ action = 'refreshSlots', data = data[3] and {items = {{item = data[2]}, {item = data[3], inventory = 'shop'}}} or {items = {item = data[2]}}})
end

Expand Down

0 comments on commit d000bc0

Please sign in to comment.