Inventory
server/custom/inventory
Config.Inventory = 'default' -- default, ox_inventory, axr_inventory, qs-inventory or custom
if Config.Inventory ~= 'default' then
return
end
local ESX, QBCore
if Config.Framework == 'qb-core' then
QBCore = exports['qb-core']:GetCoreObject()
exports['qb-core']:AddItem(Config.Item.Name, {
name = Config.Item.Name,
label = Config.Item.Label,
weight = 10,
type = 'item',
image = 'dark_tablet.png',
unique = false,
useable = true,
shouldClose = true,
combinable = nil,
description = Config.Item.Description
})
elseif Config.Framework == 'esx' then
ESX = exports['es_extended']:getSharedObject()
end
function CreateItem(name, callback)
if Config.Framework == 'qb-core' then
QBCore.Functions.CreateUseableItem(name, function(source)
local identifier = Framework.GetPlayerIdentifier(source)
callback(identifier)
end)
elseif Config.Framework == 'esx' then
ESX.RegisterUsableItem(name, callback)
elseif Config.Framework == 'vrp' then
vRP.defInventoryItem({ name, 'Dark Tablet', 'Dark tablet for illegal activities', function()
local choices = {}
choices['Use'] = function(player, choice)
local user_id = vRP.getUserId({ player })
if user_id then
callback(user_id)
end
end
return choices
end, 0.01 })
end
end
function HasItem(identifier, item, amount)
amount = tonumber(amount) or 1
if Config.Framework == 'qb-core' then
local source = QBCore.Functions.GetPlayerByCitizenId(identifier).PlayerData.source
local items = exports['qb-inventory']:GetItemsByName(source, item)
return #items >= amount
elseif Config.Framework == 'esx' then
local player = ESX.GetPlayerFromIdentifier(identifier)
local items = player.getInventoryItem(item).count
return items >= amount
elseif Config.Framework == 'vrp' then
local items = vRP.getInventoryItemAmount({ identifier, item })
return items >= amount
end
end
function GiveItem(identifier, item, amount)
if Config.Framework == 'qb-core' then
local source = QBCore.Functions.GetPlayerByCitizenId(identifier).PlayerData.source
exports['qb-inventory']:AddItem(source, item, amount)
elseif Config.Framework == 'esx' then
local player = ESX.GetPlayerFromIdentifier(identifier)
player.addInventoryItem(item, amount)
elseif Config.Framework == 'vrp' then
vRP.giveInventoryItem({ identifier, item, amount, true })
end
end
Last updated
Was this helpful?