Asaayu
7
It doesn’t include out of the box support for qs-inventory, but the server config is setup to allow you to easily add compatibility. I’ve included a snippet of the functions that are defined in the server config so you can see how it’s setup by default.
Server config snippet
-- Function to get the count of an item in a player's inventory (server side)
Config.GetItemCount = function(source, item)
-- For ESX
if ESX then
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return 0 end
local item = xPlayer.getInventoryItem(item)
return item and item.count or 0
-- For QBCore
elseif QBCore then
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return 0 end
local item = Player.Functions.GetItemByName(item)
return item and item.amount or 0
-- For custom framework
else
return 0
end
end
-- Function to remove an item from a player's inventory
Config.RemoveItem = function(source, item, amount)
if not amount or amount <= 0 then return end
-- For ESX
if ESX then
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return false end
xPlayer.removeInventoryItem(item, amount)
return true
-- For QBCore
elseif QBCore then
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return false end
Player.Functions.RemoveItem(item, amount)
return true
-- For custom framework
else
return true
end
end
-- Function to check if the player can carry an item
Config.CanCarryItem = function(source, item, amount)
if not amount or amount <= 0 then return false end
-- For ESX
if ESX then
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return false end
return xPlayer.canCarryItem(item, amount)
-- For QBCore
elseif QBCore then
return true -- QBCore auto checks this in the add item function
-- For custom framework
else
return true
end
end
-- Function to give an item to a player
Config.AddItem = function(source, item, amount)
if not amount or amount <= 0 then return end
-- For ESX
if ESX then
local xPlayer = ESX.GetPlayerFromId(source)
if not xPlayer then return false end
xPlayer.addInventoryItem(item, amount)
return true
-- For QBCore
elseif QBCore then
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return false end
Player.Functions.AddItem(item, amount)
return true
-- For custom framework
else
return true
end
end