mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 02:01:33 +00:00
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:
+18
-4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user