local function RemoveItem(source, item, amount, slot)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return false end
amount = tonumber(amount) or 1
slot = tonumber(slot)
if slot then
if not Player.PlayerData.items[slot] then
DropPlayer(source, 'Failed to remove item, most likely cheating')
return false
end
if Player.PlayerData.items[slot].amount > amount then
Player.PlayerData.items[slot].amount = Player.PlayerData.items[slot].amount - amount
Player.Functions.SetPlayerData('items', Player.PlayerData.items)
if item == 'fruit_basket' then
TriggerClientEvent("ds-fruitpicker:removebasket", source)
end
if not Player.Offline then
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. Player.PlayerData.items[slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[slot].amount)
end
return true
elseif Player.PlayerData.items[slot].amount == amount then
Player.PlayerData.items[slot] = nil
Player.Functions.SetPlayerData('items', Player.PlayerData.items)
if item == 'fruit_basket' then
TriggerClientEvent("ds-fruitpicker:removebasket", source)
end
if Player.Offline then return true end
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')
return true
end
else
local slots = GetSlotsByItem(Player.PlayerData.items, item)
local amountToRemove = amount
if not slots then return false end
for _, _slot in pairs(slots) do
if not Player.PlayerData.items[_slot] then
DropPlayer(source, 'Failed to remove item, most likely cheating')
return false
end
if Player.PlayerData.items[_slot].amount > amountToRemove then
Player.PlayerData.items[_slot].amount = Player.PlayerData.items[_slot].amount - amountToRemove
Player.Functions.SetPlayerData('items', Player.PlayerData.items)
if item == 'fruit_basket' then
TriggerClientEvent("ds-fruitpicker:removebasket", source)
end
if not Player.Offline then
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. Player.PlayerData.items[_slot].name .. ', removed amount: ' .. amount .. ', new total amount: ' .. Player.PlayerData.items[_slot].amount)
end
return true
elseif Player.PlayerData.items[_slot].amount == amountToRemove then
Player.PlayerData.items[_slot] = nil
Player.Functions.SetPlayerData('items', Player.PlayerData.items)
if item == 'fruit_basket' then
TriggerClientEvent("ds-fruitpicker:removebasket", source)
end
if Player.Offline then return true end
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'RemoveItem', 'red', '**' .. GetPlayerName(source) .. ' (citizenid: ' .. Player.PlayerData.citizenid .. ' | id: ' .. source .. ')** lost item: [slot:' .. _slot .. '], itemname: ' .. item .. ', removed amount: ' .. amount .. ', item removed')
return true
end
end
end
return false
end