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

GetItemCount export #500

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,31 @@ end

exports('HasItem', HasItem)

function GetItemCount(items)
assert((type(items) == 'table' or type(items) == 'string') and table.type(table) == 'hash', "Table in ^3GetItemCount^7 cannot be dictionary!")

local check = type(items) == 'table' and 1 or 2
local count = 0

for _,item in pairs(PlayerData.items) do
if check == 1 then
for k,v in pairs(items) do
if v == item.name then
count+=item.amount
end
end
elseif check == 2 then
if items == item.name then
count+=item.amount
end
end
end

return count
end

exports('GetItemCount', GetItemCount)

---Gets the closest vending machine object to the client
---@return integer closestVendingMachine
local function GetClosestVending()
Expand Down
27 changes: 27 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,33 @@ end

exports('HasItem', HasItem)

function GetItemCount(source, items)
assert((type(items) == 'table' or type(items) == 'string') and table.type(table) == 'hash', "Table in ^3GetItemCount^7 cannot be dictionary!")

local Player = QBCore.Functions.GetPlayer(source)
if not Player then return 0 end
local check = type(items) == 'table' and 1 or 2
local count = 0

for _,item in pairs(Player.PlayerData.items) do
if check == 1 then
for k,v in pairs(items) do
if v == item.name then
count+=item.amount
end
end
else
if items == item.name then
count+=item.amount
end
end
end

return count
end

exports('GetItemCount', GetItemCount)

---Create a usable item with a callback on use
---@param itemName string The name of the item to make usable
---@param data any
Expand Down
Loading