From 4a54140cff91a04bb4f31d99666e671c076fd566 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 10 Apr 2023 10:10:20 +1000 Subject: [PATCH] refactor(client): item notifications Not well tested but should be okay, if a little more "spammy". --- client.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/client.lua b/client.lua index cc5476f35d..283751b685 100644 --- a/client.lua +++ b/client.lua @@ -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 @@ -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)