Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: amount is nil in GetTotalWeight + misc lint issues #517

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
14 changes: 7 additions & 7 deletions client/drops.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local holdingDrop = false
HoldingDrop = false
local bagObject = nil
local heldDrop = nil
CurrentDrop = nil
Expand All @@ -18,7 +18,7 @@ function GetDrops()
label = Lang:t('menu.o_bag'),
action = function()
TriggerServerEvent('qb-inventory:server:openDrop', k)
CurrentDrop = dropId
CurrentDrop = k
end,
},
},
Expand Down Expand Up @@ -59,9 +59,9 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId)
label = 'Pick up bag',
action = function()
if IsPedArmed(PlayerPedId(), 4) then
return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500)
return QBCore.Functions.Notify("You can not be holding a Gun and a Bag!", "error", 5500)
end
if holdingDrop then
if HoldingDrop then
return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500)
end
AttachEntityToEntity(
Expand All @@ -77,7 +77,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId)
true, true, false, true, 1, true
)
bagObject = bag
holdingDrop = true
HoldingDrop = true
heldDrop = newDropId
exports['qb-core']:DrawText('Press [G] to drop the bag')
end,
Expand Down Expand Up @@ -109,7 +109,7 @@ end)

CreateThread(function()
while true do
if holdingDrop then
if HoldingDrop then
if IsControlJustPressed(0, 47) then
DetachEntity(bagObject, true, true)
local coords = GetEntityCoords(PlayerPedId())
Expand All @@ -119,7 +119,7 @@ CreateThread(function()
FreezeEntityPosition(bagObject, true)
exports['qb-core']:HideText()
TriggerServerEvent('qb-inventory:server:updateDrop', heldDrop, coords)
holdingDrop = false
HoldingDrop = false
bagObject = nil
heldDrop = nil
end
Expand Down
36 changes: 22 additions & 14 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
QBCore = exports['qb-core']:GetCoreObject()
local hotbarShown = false
local PlayerData = nil

-- Handlers

Expand All @@ -11,7 +12,7 @@ end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
LocalPlayer.state:set('inv_busy', true, true)
PlayerData = {}
PlayerData = nil
end)

RegisterNetEvent('QBCore:Client:UpdateObject', function()
Expand Down Expand Up @@ -78,19 +79,21 @@ function HasItem(items, amount)
for _ in pairs(items) do totalItems = totalItems + 1 end
end

for _, itemData in pairs(PlayerData.items) do
if isTable then
for k, v in pairs(items) do
if itemData and itemData.name == (isArray and v or k) and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then
count = count + 1
if count == totalItems then
return true
if PlayerData and type(PlayerData.items) == "table" then
for _, itemData in pairs(PlayerData.items) do
if isTable then
for k, v in pairs(items) do
if itemData and itemData.name == (isArray and v or k) and ((amount and itemData.amount >= amount) or (not isArray and itemData.amount >= v) or (not amount and isArray)) then
count = count + 1
if count == totalItems then
return true
end
end
end
end
else -- Single item as string
if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then
return true
else -- Single item as string
if itemData and itemData.name == items and (not amount or (itemData and amount and itemData.amount >= amount)) then
return true
end
end
end
end
Expand Down Expand Up @@ -137,9 +140,14 @@ RegisterNetEvent('qb-inventory:client:closeInv', function()
end)

RegisterNetEvent('qb-inventory:client:updateInventory', function()
local items = {}
if PlayerData and type(PlayerData.items) == "table" then
items = PlayerData.items
end

SendNUIMessage({
action = 'update',
inventory = PlayerData.items
inventory = items
})
end)

Expand Down Expand Up @@ -301,7 +309,7 @@ for i = 1, 5 do
local itemData = PlayerData.items[i]
if not itemData then return end
if itemData.type == "weapon" then
if holdingDrop then
if HoldingDrop then
return QBCore.Functions.Notify("Your already holding a bag, Go Drop it!", "error", 5500)
end
end
Expand Down
7 changes: 6 additions & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,12 @@ function GetTotalWeight(items)
if not items then return 0 end
local weight = 0
for _, item in pairs(items) do
weight = weight + (item.weight * item.amount)
local amount = item.amount
if type(amount) ~= "number" then
amount = 1
end

weight = weight + (item.weight * amount)
end
return tonumber(weight)
end
Expand Down
Loading