From 65c1eb70c916a6a9654559f79422898b2fb2a4f5 Mon Sep 17 00:00:00 2001 From: BerkieBb <82737367+BerkieBb@users.noreply.github.com> Date: Sat, 19 Jun 2021 14:48:19 +0200 Subject: [PATCH] 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. --- server/events.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/server/events.lua b/server/events.lua index ae0a4e7..6412567 100644 --- a/server/events.lua +++ b/server/events.lua @@ -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