HasItem callback made compatible with multiple items

To add multiple items to the callback you use it like this

QBCore.Funtions.TriggerCallback('QBCore:HasItem', function(result)
    if result then
        print('has items')
    end
end, {"item1", "item2"})

Also still compatible with 1 item.
This commit is contained in:
BerkieBb
2021-06-19 14:48:19 +02:00
committed by GitHub
parent b2a2bf4090
commit 65c1eb70c9
+18 -4
View File
@@ -249,12 +249,26 @@ Citizen.CreateThread(function()
end)
end)
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, itemName)
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items)
local retval = false
local Player = QBCore.Functions.GetPlayer(source)
if Player ~= nil then
if Player.Functions.GetItemByName(itemName) ~= nil then
retval = true
if type(items) == "table" then
local count = 0
for k, v in pairs(items) do
if Player ~= nil then
if Player.Functions.GetItemByName(v) ~= nil then
count = count + 1
if count == #items then
retval = true
end
end
end
end
else
if Player ~= nil then
if Player.Functions.GetItemByName(items) ~= nil then
retval = true
end
end
end