Skip to content
Open
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
23 changes: 18 additions & 5 deletions client/data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ local function GetVehicles()
return vehicles
end

-- Returns a list of items from QBCore.Shared.Items
-- Returns a list of items from ox_inventory or qb-inventory
local function GetItems()
local items = {}
local ItemsData = QBCore.Shared.Items

if Config.Inventory == "ox_inventory" then
ItemsData = exports.ox_inventory:Items()
local ItemsData = exports.ox_inventory:Items()

for _, v in pairs(ItemsData) do
items[#items + 1] = {
label = v.label or v.name,
value = v.name
}
end
end

for name, v in pairs(ItemsData) do
items[#items + 1] = { label = v.label, value = name }
if Config.Inventory == "qb-inventory" then
local ItemsData = QBCore.Shared.Items

for name, v in pairs(ItemsData) do
items[#items + 1] = {
label = v.label,
value = name
}
end
end

return items
Expand Down
32 changes: 22 additions & 10 deletions server/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ RegisterNetEvent('ps-adminmenu:server:GiveItem', function(data, selectedData)

local target = selectedData["Player"].value
local item = selectedData["Item"].value
local amount = selectedData["Amount"].value
local amount = tonumber(selectedData["Amount"].value)
local Player = QBCore.Functions.GetPlayer(target)

if not item or not amount then return end
if not item or not amount or amount <= 0 then return end
if not Player then
return QBCore.Functions.Notify(source, locale("not_online"), 'error', 7500)
end

Player.Functions.AddItem(item, amount)
if Config.Inventory == "ox_inventory" then
exports.ox_inventory:AddItem(target, item, amount)
elseif Config.Inventory == "qb-inventory" then
Player.Functions.AddItem(item, amount)
end

QBCore.Functions.Notify(source,
locale("give_item", tonumber(amount) .. " " .. item,
locale("give_item", amount .. " " .. item,
Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname), "success", 7500)
end)

Expand All @@ -96,14 +101,21 @@ RegisterNetEvent('ps-adminmenu:server:GiveItemAll', function(data, selectedData)
if not data or not CheckPerms(source, data.perms) then return end

local item = selectedData["Item"].value
local amount = selectedData["Amount"].value
local amount = tonumber(selectedData["Amount"].value)
local players = QBCore.Functions.GetPlayers()

if not item or not amount then return end
if not item or not amount or amount <= 0 then return end

for _, id in pairs(players) do
local Player = QBCore.Functions.GetPlayer(id)
Player.Functions.AddItem(item, amount)
QBCore.Functions.Notify(source, locale("give_item_all", amount .. " " .. item), "success", 7500)
if Config.Inventory == "ox_inventory" then
exports.ox_inventory:AddItem(id, item, amount)
elseif Config.Inventory == "qb-inventory" then
local Player = QBCore.Functions.GetPlayer(id)
if Player then
Player.Functions.AddItem(item, amount)
end
end
end
end)

QBCore.Functions.Notify(source, locale("give_item_all", amount .. " " .. item), "success", 7500)
end)