Skip to content

Commit

Permalink
refactor(client): item notifications
Browse files Browse the repository at this point in the history
Not well tested but should be okay, if a little more "spammy".
  • Loading branch information
thelindat committed Apr 24, 2023
1 parent 23de1a5 commit 4a54140
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -859,15 +859,24 @@ local function updateInventory(items, weight)
items[i].inventory = 'player'
local v = items[i].item
local item = PlayerData.inventory[v.slot]
local count = 0

if item?.name then
count -= item.count
itemCount[item.name] = (itemCount[item.name] or 0) - item.count
end

if v.count then
count += v.count
itemCount[v.name] = (itemCount[v.name] or 0) + v.count
end

if count < 1 then
Utils.ItemNotify({ item?.name and item or v, 'ui_removed', -count })
else
Utils.ItemNotify({ v, 'ui_added', count })
end

changes[v.slot] = v.count and v or false
if not v.count then v.name = nil end
PlayerData.inventory[v.slot] = v.name and v or nil
Expand Down Expand Up @@ -932,14 +941,6 @@ RegisterNetEvent('ox_inventory:updateSlots', function(items, weights)
TriggerEvent('ox_inventory:currentWeapon', currentWeapon)
end

-- if count then
-- if not item.name then
-- item = PlayerData.inventory[item.slot]
-- end

-- Utils.ItemNotify({ item, removed and 'ui_removed' or 'ui_added', count })
-- end

updateInventory(items, weights)
end)

Expand Down

0 comments on commit 4a54140

Please sign in to comment.