2025-07-27 05:45:43 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
-- Function to delete items from a shredder
|
|
|
|
function DeleteShredderItems(containerID)
|
|
|
|
-- Get all items in the shredder
|
2025-07-28 01:05:18 +02:00
|
|
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
|
|
|
|
|
|
|
if not items or next(items) == nil then
|
2025-07-28 01:38:05 +02:00
|
|
|
print("^3[DISPOSAL]^7 No items to delete in " .. containerID)
|
2025-07-28 01:05:18 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local totalItems = 0
|
|
|
|
local disposedItems = {}
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Delete all items
|
2025-07-28 01:05:18 +02:00
|
|
|
for slot, item in pairs(items) do
|
|
|
|
if item and item.amount and item.amount > 0 then
|
|
|
|
exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
|
|
|
totalItems = totalItems + item.amount
|
|
|
|
table.insert(disposedItems, {name = item.name, amount = item.amount})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
print("^3[DISPOSAL]^7 Deleted " .. totalItems .. " items from shredder " .. containerID)
|
2025-07-28 01:05:18 +02:00
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
-- Log the deletion
|
2025-07-28 01:05:18 +02:00
|
|
|
local itemList = ""
|
|
|
|
for _, item in pairs(disposedItems) do
|
|
|
|
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
|
|
|
end
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Shredder Items Destroyed', 'orange',
|
2025-07-28 01:05:18 +02:00
|
|
|
'**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList)
|
|
|
|
end
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Container inventory open
|
2025-07-28 01:05:18 +02:00
|
|
|
RegisterNetEvent('disposal:server:openInventory', function(containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
local src = source
|
|
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
|
|
|
|
if not Player then return end
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Open the inventory
|
2025-07-28 01:05:18 +02:00
|
|
|
exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, {
|
2025-07-27 22:23:08 +02:00
|
|
|
maxweight = 50000, -- 50kg max
|
|
|
|
slots = 20, -- 20 Slots
|
2025-07-28 01:44:42 +02:00
|
|
|
label = type == "shredder" and 'Müllschredder' or 'Lager'
|
2025-07-27 22:23:08 +02:00
|
|
|
})
|
2025-07-27 05:45:43 +02:00
|
|
|
end)
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Get items from container
|
2025-07-28 01:05:18 +02:00
|
|
|
RegisterNetEvent('disposal:server:getItems', function(containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
local src = source
|
|
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
|
|
|
|
if not Player then return end
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Get items from the container
|
2025-07-28 01:05:18 +02:00
|
|
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
2025-07-27 22:17:12 +02:00
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- If items is nil, provide an empty table
|
2025-07-27 22:23:08 +02:00
|
|
|
if items == nil then items = {} end
|
2025-07-27 05:45:43 +02:00
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
end)
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Dispose single item
|
2025-07-28 01:05:18 +02:00
|
|
|
RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
local src = source
|
|
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
|
|
|
|
if not Player then return end
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
if type == "shredder" then
|
|
|
|
-- For shredders, remove the item permanently
|
|
|
|
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot)
|
|
|
|
|
|
|
|
if success then
|
|
|
|
-- Log for admins
|
|
|
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has destroyed ' .. amount .. 'x ' .. itemName)
|
|
|
|
|
|
|
|
-- Discord Webhook
|
|
|
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
|
|
|
'Item Destroyed',
|
|
|
|
'orange',
|
|
|
|
'**Player:** ' .. GetPlayerName(src) ..
|
|
|
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
|
|
|
'\n**Item:** ' .. amount .. 'x ' .. itemName ..
|
|
|
|
'\n**Action:** Item destroyed')
|
|
|
|
|
|
|
|
-- Notification message
|
|
|
|
local message = amount .. 'x ' .. itemName .. ' wurde vernichtet!'
|
|
|
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
|
|
|
|
|
|
|
-- Reload menu
|
|
|
|
Wait(1000)
|
|
|
|
TriggerEvent('disposal:server:getItems', containerID, type)
|
|
|
|
else
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Vernichten des Items!', 'error')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- For storage containers, just notify that the item is stored
|
|
|
|
local message = amount .. 'x ' .. itemName .. ' wurde im Lager gespeichert!'
|
|
|
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Log for admins
|
2025-07-28 01:44:42 +02:00
|
|
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ' .. amount .. 'x ' .. itemName)
|
2025-07-27 05:45:43 +02:00
|
|
|
|
|
|
|
-- Discord Webhook
|
2025-07-28 01:38:05 +02:00
|
|
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
2025-07-28 01:44:42 +02:00
|
|
|
'Item Stored',
|
|
|
|
'blue',
|
2025-07-28 01:38:05 +02:00
|
|
|
'**Player:** ' .. GetPlayerName(src) ..
|
2025-07-28 01:05:18 +02:00
|
|
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
|
|
|
'\n**Item:** ' .. amount .. 'x ' .. itemName ..
|
2025-07-28 01:44:42 +02:00
|
|
|
'\n**Action:** Item stored in container')
|
2025-07-27 05:45:43 +02:00
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Reload menu
|
2025-07-27 05:45:43 +02:00
|
|
|
Wait(1000)
|
2025-07-28 01:05:18 +02:00
|
|
|
TriggerEvent('disposal:server:getItems', containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Dispose all items
|
2025-07-28 01:05:18 +02:00
|
|
|
RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
local src = source
|
|
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
|
|
|
|
if not Player then return end
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Get all items in the container
|
2025-07-28 01:05:18 +02:00
|
|
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
2025-07-27 05:45:43 +02:00
|
|
|
|
|
|
|
if not items or next(items) == nil then
|
2025-07-28 01:38:05 +02:00
|
|
|
TriggerClientEvent('QBCore:Notify', src,
|
2025-07-28 01:44:42 +02:00
|
|
|
type == "shredder" and 'Der Schredder ist bereits leer!' or 'Das Lager ist bereits leer!',
|
2025-07-28 01:38:05 +02:00
|
|
|
'error')
|
2025-07-27 05:45:43 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
if type == "shredder" then
|
|
|
|
-- For shredders, remove all items permanently
|
|
|
|
local disposedItems = {}
|
|
|
|
local totalItems = 0
|
|
|
|
|
|
|
|
-- Dispose all items
|
|
|
|
for slot, item in pairs(items) do
|
|
|
|
if item and item.amount and item.amount > 0 then
|
|
|
|
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
|
|
|
if success then
|
|
|
|
table.insert(disposedItems, {name = item.name, amount = item.amount})
|
|
|
|
totalItems = totalItems + item.amount
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #disposedItems > 0 then
|
|
|
|
-- Log for admins
|
|
|
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has destroyed ALL items (' .. totalItems .. ' items)')
|
|
|
|
|
|
|
|
-- Discord Webhook with item list
|
|
|
|
local itemList = ""
|
|
|
|
for _, item in pairs(disposedItems) do
|
|
|
|
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
|
|
|
end
|
|
|
|
|
|
|
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
|
|
|
'All Items Destroyed',
|
|
|
|
'red',
|
|
|
|
'**Player:** ' .. GetPlayerName(src) ..
|
|
|
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
|
|
|
'\n**Action:** All items destroyed' ..
|
|
|
|
'\n**Total Items:** ' .. totalItems ..
|
|
|
|
'\n**Items:**\n' .. itemList)
|
|
|
|
|
|
|
|
-- Notification message
|
|
|
|
local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!'
|
|
|
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
|
|
|
else
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Vernichten gefunden!', 'error')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- For storage containers, just notify that all items are stored
|
|
|
|
local totalItems = 0
|
|
|
|
for slot, item in pairs(items) do
|
|
|
|
if item and item.amount and item.amount > 0 then
|
2025-07-27 05:45:43 +02:00
|
|
|
totalItems = totalItems + item.amount
|
|
|
|
end
|
|
|
|
end
|
2025-07-28 01:44:42 +02:00
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Log for admins
|
2025-07-28 01:44:42 +02:00
|
|
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ALL items (' .. totalItems .. ' items)')
|
2025-07-27 05:45:43 +02:00
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
-- Discord Webhook with item list
|
2025-07-27 05:45:43 +02:00
|
|
|
local itemList = ""
|
2025-07-28 01:44:42 +02:00
|
|
|
for slot, item in pairs(items) do
|
|
|
|
if item and item.amount and item.amount > 0 then
|
|
|
|
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
|
|
|
end
|
2025-07-27 05:45:43 +02:00
|
|
|
end
|
|
|
|
|
2025-07-28 01:38:05 +02:00
|
|
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
2025-07-28 01:44:42 +02:00
|
|
|
'All Items Stored',
|
|
|
|
'green',
|
2025-07-28 01:38:05 +02:00
|
|
|
'**Player:** ' .. GetPlayerName(src) ..
|
2025-07-28 01:05:18 +02:00
|
|
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
2025-07-28 01:44:42 +02:00
|
|
|
'\n**Action:** All items stored in container' ..
|
2025-07-28 01:38:05 +02:00
|
|
|
'\n**Total Items:** ' .. totalItems ..
|
2025-07-28 01:05:18 +02:00
|
|
|
'\n**Items:**\n' .. itemList)
|
|
|
|
|
2025-07-28 01:44:42 +02:00
|
|
|
-- Notification message
|
|
|
|
local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden im Lager gespeichert!'
|
2025-07-28 01:38:05 +02:00
|
|
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
2025-07-27 05:45:43 +02:00
|
|
|
end
|
|
|
|
end)
|