Skip to content

Commit

Permalink
Merge pull request #517 from Z3rio/main
Browse files Browse the repository at this point in the history
fix: amount is nil in `GetTotalWeight` + misc lint issues
  • Loading branch information
GhzGarage authored Nov 13, 2024
2 parents eab758f + 260bb4d commit 05bac43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
10 changes: 5 additions & 5 deletions client/drops.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
holdingDrop = false
HoldingDrop = false
local bagObject = nil
local heldDrop = nil
CurrentDrop = nil
Expand Down Expand Up @@ -60,7 +60,7 @@ RegisterNetEvent('qb-inventory:client:setupDropTarget', function(dropId)
if IsPedArmed(PlayerPedId(), 4) then
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 @@ -76,7 +76,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 @@ -108,7 +108,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 @@ -118,7 +118,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
35 changes: 21 additions & 14 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,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 @@ -79,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 @@ -138,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 @@ -302,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 @@ -248,7 +248,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

0 comments on commit 05bac43

Please sign in to comment.