forked from Simnation/Main
ed
This commit is contained in:
parent
55ce22c3de
commit
b960315876
2 changed files with 141 additions and 223 deletions
|
@ -6,7 +6,7 @@ local shredderPropModels = {
|
||||||
'prop_bin_08a'
|
'prop_bin_08a'
|
||||||
}
|
}
|
||||||
|
|
||||||
-- List of prop models that should be targetable as trash bins with delayed deletion
|
-- List of prop models that should be targetable as storage containers (formerly trash bins)
|
||||||
local trashBinPropModels = {
|
local trashBinPropModels = {
|
||||||
'prop_bin_01a',
|
'prop_bin_01a',
|
||||||
'prop_bin_03a',
|
'prop_bin_03a',
|
||||||
|
@ -59,14 +59,14 @@ Citizen.CreateThread(function()
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Add target to trash bin props
|
-- Add target to storage container props (formerly trash bins)
|
||||||
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
type = "client",
|
type = "client",
|
||||||
event = "disposal:openInventory",
|
event = "disposal:openInventory",
|
||||||
icon = "fas fa-trash",
|
icon = "fas fa-box-open",
|
||||||
label = "Mülltonne öffnen",
|
label = "Lager öffnen",
|
||||||
action = function(entity)
|
action = function(entity)
|
||||||
currentEntity = entity
|
currentEntity = entity
|
||||||
currentType = "trash"
|
currentType = "trash"
|
||||||
|
@ -79,8 +79,8 @@ Citizen.CreateThread(function()
|
||||||
{
|
{
|
||||||
type = "client",
|
type = "client",
|
||||||
event = "disposal:openMenu",
|
event = "disposal:openMenu",
|
||||||
icon = "fas fa-clock",
|
icon = "fas fa-archive",
|
||||||
label = "Müll entsorgen",
|
label = "Items lagern",
|
||||||
action = function(entity)
|
action = function(entity)
|
||||||
currentEntity = entity
|
currentEntity = entity
|
||||||
currentType = "trash"
|
currentType = "trash"
|
||||||
|
@ -94,7 +94,7 @@ Citizen.CreateThread(function()
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models")
|
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " storage container models")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Function to get container ID from entity
|
-- Function to get container ID from entity
|
||||||
|
@ -113,8 +113,8 @@ RegisterNetEvent('disposal:openInventory', function()
|
||||||
|
|
||||||
if not currentEntity or not DoesEntityExist(currentEntity) then
|
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = currentType == "shredder" and 'Müllschredder' or 'Lager',
|
||||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -135,8 +135,8 @@ RegisterNetEvent('disposal:openMenu', function()
|
||||||
|
|
||||||
if not currentEntity or not DoesEntityExist(currentEntity) then
|
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = currentType == "shredder" and 'Müllschredder' or 'Lager',
|
||||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Kein Lager gefunden!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -151,15 +151,15 @@ RegisterNetEvent('disposal:openMenu', function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Show menu with items
|
-- Show menu with items
|
||||||
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining)
|
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type)
|
||||||
-- Make sure items is a table
|
-- Make sure items is a table
|
||||||
items = items or {}
|
items = items or {}
|
||||||
|
|
||||||
-- Check if items is empty
|
-- Check if items is empty
|
||||||
if next(items) == nil then
|
if next(items) == nil then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = type == "shredder" and 'Müllschredder' or 'Lager',
|
||||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -168,32 +168,20 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
local menuOptions = {}
|
local menuOptions = {}
|
||||||
|
|
||||||
-- All items action option
|
-- All items action option
|
||||||
local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN"
|
local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS LAGERN"
|
||||||
local actionDesc = type == "shredder"
|
local actionDesc = type == "shredder"
|
||||||
and 'Vernichtet alle Items im Schredder permanent!'
|
and 'Vernichtet alle Items im Schredder permanent!'
|
||||||
or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!'
|
or 'Lagert alle Items im Container!'
|
||||||
|
|
||||||
table.insert(menuOptions, {
|
table.insert(menuOptions, {
|
||||||
title = '🔥 ' .. actionText,
|
title = type == "shredder" and '🔥 ' .. actionText or '📦 ' .. actionText,
|
||||||
description = actionDesc,
|
description = actionDesc,
|
||||||
icon = type == "shredder" and 'fire' or 'trash',
|
icon = type == "shredder" and 'fire' or 'archive',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
confirmDestroyAll(containerID, type)
|
confirmDestroyAll(containerID, type)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
-- If it's a trash bin with scheduled deletion, show the time remaining
|
|
||||||
if type == "trash" and timeRemaining then
|
|
||||||
local minutes = math.floor(timeRemaining / 60)
|
|
||||||
local seconds = timeRemaining % 60
|
|
||||||
|
|
||||||
table.insert(menuOptions, {
|
|
||||||
title = '⏱️ Automatische Leerung',
|
|
||||||
description = string.format('In %d Minuten und %d Sekunden', minutes, seconds),
|
|
||||||
disabled = true
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(menuOptions, {
|
table.insert(menuOptions, {
|
||||||
title = '─────────────────',
|
title = '─────────────────',
|
||||||
description = 'Einzelne Items:',
|
description = 'Einzelne Items:',
|
||||||
|
@ -208,7 +196,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
table.insert(menuOptions, {
|
table.insert(menuOptions, {
|
||||||
title = (item.label or item.name),
|
title = (item.label or item.name),
|
||||||
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
|
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
|
||||||
icon = 'trash',
|
icon = type == "shredder" and 'trash' or 'box',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
confirmDestroySingle(item.name, item.amount, slot, containerID, type)
|
confirmDestroySingle(item.name, item.amount, slot, containerID, type)
|
||||||
end
|
end
|
||||||
|
@ -218,8 +206,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
|
|
||||||
if not hasItems then
|
if not hasItems then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = type == "shredder" and 'Müllschredder' or 'Lager',
|
||||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
description = type == "shredder" and 'Der Schredder ist leer!' or 'Das Lager ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -227,7 +215,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'disposal_menu',
|
id = 'disposal_menu',
|
||||||
title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung',
|
title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '📦 Lager Verwaltung',
|
||||||
options = menuOptions
|
options = menuOptions
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -236,19 +224,19 @@ end)
|
||||||
|
|
||||||
-- Confirm single item disposal
|
-- Confirm single item disposal
|
||||||
function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
||||||
local actionText = type == "shredder" and "vernichten" or "entsorgen"
|
local actionText = type == "shredder" and "vernichten" or "lagern"
|
||||||
local actionDesc = type == "shredder"
|
local actionDesc = type == "shredder"
|
||||||
and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!')
|
and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!')
|
||||||
or (itemName .. ' (' .. amount .. 'x) wird entsorgt und nach Zeit gelöscht!')
|
or (itemName .. ' (' .. amount .. 'x) wird im Lager gespeichert!')
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'dispose_single_confirm',
|
id = 'dispose_single_confirm',
|
||||||
title = '⚠️ Item ' .. actionText .. '?',
|
title = '⚠️ Item ' .. actionText .. '?',
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen',
|
title = type == "shredder" and '🔥 Ja, vernichten' or '📦 Ja, lagern',
|
||||||
description = actionDesc,
|
description = actionDesc,
|
||||||
icon = 'check',
|
icon = type == "shredder" and 'check' or 'box',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type)
|
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type)
|
||||||
end
|
end
|
||||||
|
@ -269,19 +257,19 @@ end
|
||||||
|
|
||||||
-- Confirm all items disposal
|
-- Confirm all items disposal
|
||||||
function confirmDestroyAll(containerID, type)
|
function confirmDestroyAll(containerID, type)
|
||||||
local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN"
|
local actionText = type == "shredder" and "VERNICHTEN" or "LAGERN"
|
||||||
local actionDesc = type == "shredder"
|
local actionDesc = type == "shredder"
|
||||||
and 'ALLE Items im Schredder werden permanent gelöscht!'
|
and 'ALLE Items im Schredder werden permanent gelöscht!'
|
||||||
or 'ALLE Items in der Mülltonne werden nach Zeit automatisch gelöscht!'
|
or 'ALLE Items werden im Lager gespeichert!'
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'dispose_all_confirm',
|
id = 'dispose_all_confirm',
|
||||||
title = '⚠️ WARNUNG ⚠️',
|
title = type == "shredder" and '⚠️ WARNUNG ⚠️' or '📦 LAGERUNG',
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN',
|
title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '📦 JA, ALLES LAGERN',
|
||||||
description = actionDesc,
|
description = actionDesc,
|
||||||
icon = type == "shredder" and 'fire' or 'trash',
|
icon = type == "shredder" and 'fire' or 'archive',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeAll', containerID, type)
|
TriggerServerEvent('disposal:server:disposeAll', containerID, type)
|
||||||
end
|
end
|
||||||
|
@ -303,7 +291,7 @@ end
|
||||||
-- Success notification with effect
|
-- Success notification with effect
|
||||||
RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = type == "shredder" and 'Müllschredder' or 'Lager',
|
||||||
description = message,
|
description = message,
|
||||||
type = 'success',
|
type = 'success',
|
||||||
duration = 4000
|
duration = 4000
|
||||||
|
@ -320,13 +308,13 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||||
|
|
||||||
UseParticleFxAssetNextCall("core")
|
UseParticleFxAssetNextCall("core")
|
||||||
|
|
||||||
-- Different effects for shredder vs trash
|
-- Different effects for shredder vs storage
|
||||||
if type == "shredder" then
|
if type == "shredder" then
|
||||||
-- More intense effect for shredder
|
-- More intense effect for shredder
|
||||||
StartParticleFxNonLoopedAtCoord("ent_sht_flame", coords.x, coords.y, coords.z + 1.0, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
StartParticleFxNonLoopedAtCoord("ent_sht_flame", coords.x, coords.y, coords.z + 1.0, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
||||||
PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
|
PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
|
||||||
else
|
else
|
||||||
-- Subtle effect for trash
|
-- Subtle effect for storage
|
||||||
StartParticleFxNonLoopedAtCoord("ent_sht_dust", coords.x, coords.y, coords.z + 0.5, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
StartParticleFxNonLoopedAtCoord("ent_sht_dust", coords.x, coords.y, coords.z + 0.5, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
||||||
PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
|
PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,40 +1,12 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Table to store items scheduled for deletion
|
-- Function to delete items from a shredder
|
||||||
local scheduledDeletions = {}
|
function DeleteShredderItems(containerID)
|
||||||
|
-- Get all items in the shredder
|
||||||
-- Default time for trash bin deletion (2 days = 48 hours = 172800 seconds)
|
|
||||||
local DEFAULT_TRASH_DELETE_TIME = 172800 -- seconds
|
|
||||||
|
|
||||||
-- Function to schedule item deletion
|
|
||||||
function ScheduleItemDeletion(containerID, deleteTime)
|
|
||||||
-- Use default time if not specified
|
|
||||||
deleteTime = deleteTime or DEFAULT_TRASH_DELETE_TIME
|
|
||||||
|
|
||||||
-- Cancel existing timer if there is one
|
|
||||||
if scheduledDeletions[containerID] and scheduledDeletions[containerID].timer then
|
|
||||||
clearTimeout(scheduledDeletions[containerID].timer)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Schedule the deletion
|
|
||||||
scheduledDeletions[containerID] = {
|
|
||||||
deleteAt = os.time() + deleteTime,
|
|
||||||
timer = setTimeout(function()
|
|
||||||
DeleteTrashBinItems(containerID)
|
|
||||||
end, deleteTime * 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Items in " .. containerID .. " scheduled for deletion in " .. deleteTime .. " seconds")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Function to delete items from a trash bin
|
|
||||||
function DeleteTrashBinItems(containerID)
|
|
||||||
-- Get all items in the trash bin
|
|
||||||
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
||||||
|
|
||||||
if not items or next(items) == nil then
|
if not items or next(items) == nil then
|
||||||
print("^3[DISPOSAL]^7 No items to delete in " .. containerID)
|
print("^3[DISPOSAL]^7 No items to delete in " .. containerID)
|
||||||
scheduledDeletions[containerID] = nil
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,35 +22,16 @@ function DeleteTrashBinItems(containerID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID)
|
print("^3[DISPOSAL]^7 Deleted " .. totalItems .. " items from shredder " .. containerID)
|
||||||
|
|
||||||
-- Log the automatic deletion
|
-- Log the deletion
|
||||||
local itemList = ""
|
local itemList = ""
|
||||||
for _, item in pairs(disposedItems) do
|
for _, item in pairs(disposedItems) do
|
||||||
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Automatic Trash Deletion', 'yellow',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Shredder Items Destroyed', 'orange',
|
||||||
'**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList)
|
'**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList)
|
||||||
|
|
||||||
-- Remove from scheduled deletions
|
|
||||||
scheduledDeletions[containerID] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get time remaining for a scheduled deletion
|
|
||||||
function GetTimeRemaining(containerID)
|
|
||||||
if scheduledDeletions[containerID] then
|
|
||||||
local currentTime = os.time()
|
|
||||||
local deleteAt = scheduledDeletions[containerID].deleteAt
|
|
||||||
local remaining = deleteAt - currentTime
|
|
||||||
|
|
||||||
if remaining < 0 then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return remaining
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Container inventory open
|
-- Container inventory open
|
||||||
|
@ -92,17 +45,8 @@ RegisterNetEvent('disposal:server:openInventory', function(containerID, type)
|
||||||
exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, {
|
exports["tgiann-inventory"]:OpenInventory(src, "stash", containerID, {
|
||||||
maxweight = 50000, -- 50kg max
|
maxweight = 50000, -- 50kg max
|
||||||
slots = 20, -- 20 Slots
|
slots = 20, -- 20 Slots
|
||||||
label = type == "shredder" and 'Müllschredder' or 'Mülltonne'
|
label = type == "shredder" and 'Müllschredder' or 'Lager'
|
||||||
})
|
})
|
||||||
|
|
||||||
-- If it's a trash bin, schedule deletion if not already scheduled
|
|
||||||
if type == "trash" and not scheduledDeletions[containerID] then
|
|
||||||
-- Check if there are items in the container
|
|
||||||
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
|
||||||
if items and next(items) then
|
|
||||||
ScheduleItemDeletion(containerID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Get items from container
|
-- Get items from container
|
||||||
|
@ -118,13 +62,7 @@ RegisterNetEvent('disposal:server:getItems', function(containerID, type)
|
||||||
-- If items is nil, provide an empty table
|
-- If items is nil, provide an empty table
|
||||||
if items == nil then items = {} end
|
if items == nil then items = {} end
|
||||||
|
|
||||||
-- Get time remaining for trash bins
|
TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type)
|
||||||
local timeRemaining = nil
|
|
||||||
if type == "trash" then
|
|
||||||
timeRemaining = GetTimeRemaining(containerID)
|
|
||||||
end
|
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type, timeRemaining)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Dispose single item
|
-- Dispose single item
|
||||||
|
@ -134,44 +72,53 @@ RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slo
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Remove the item from the container
|
if type == "shredder" then
|
||||||
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot)
|
-- For shredders, remove the item permanently
|
||||||
|
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot)
|
||||||
if success then
|
|
||||||
|
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)
|
||||||
|
|
||||||
-- Log for admins
|
-- Log for admins
|
||||||
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' ..
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ' .. amount .. 'x ' .. itemName)
|
||||||
(type == "shredder" and 'destroyed' or 'disposed') .. ' ' .. amount .. 'x ' .. itemName)
|
|
||||||
|
|
||||||
-- Discord Webhook
|
-- Discord Webhook
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
||||||
type == "shredder" and 'Item Destroyed' or 'Item Disposed',
|
'Item Stored',
|
||||||
type == "shredder" and 'orange' or 'blue',
|
'blue',
|
||||||
'**Player:** ' .. GetPlayerName(src) ..
|
'**Player:** ' .. GetPlayerName(src) ..
|
||||||
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
||||||
'\n**Item:** ' .. amount .. 'x ' .. itemName ..
|
'\n**Item:** ' .. amount .. 'x ' .. itemName ..
|
||||||
'\n**Action:** ' .. (type == "shredder" and 'Item destroyed' or 'Item disposed'))
|
'\n**Action:** Item stored in container')
|
||||||
|
|
||||||
-- Different messages based on type
|
|
||||||
local message = ""
|
|
||||||
if type == "shredder" then
|
|
||||||
message = amount .. 'x ' .. itemName .. ' wurde vernichtet!'
|
|
||||||
else
|
|
||||||
message = amount .. 'x ' .. itemName .. ' wurde entsorgt!'
|
|
||||||
|
|
||||||
-- Schedule deletion if this is the first item in the trash bin
|
|
||||||
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
|
||||||
if items and next(items) and not scheduledDeletions[containerID] then
|
|
||||||
ScheduleItemDeletion(containerID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
|
||||||
|
|
||||||
-- Reload menu
|
-- Reload menu
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
TriggerEvent('disposal:server:getItems', containerID, type)
|
TriggerEvent('disposal:server:getItems', containerID, type)
|
||||||
else
|
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error')
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -187,100 +134,83 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
|
|
||||||
if not items or next(items) == nil then
|
if not items or next(items) == nil then
|
||||||
TriggerClientEvent('QBCore:Notify', src,
|
TriggerClientEvent('QBCore:Notify', src,
|
||||||
type == "shredder" and 'Der Schredder ist bereits leer!' or 'Die Mülltonne ist bereits leer!',
|
type == "shredder" and 'Der Schredder ist bereits leer!' or 'Das Lager ist bereits leer!',
|
||||||
'error')
|
'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local disposedItems = {}
|
if type == "shredder" then
|
||||||
local totalItems = 0
|
-- For shredders, remove all items permanently
|
||||||
|
local disposedItems = {}
|
||||||
-- Dispose all items
|
local totalItems = 0
|
||||||
for slot, item in pairs(items) do
|
|
||||||
if item and item.amount and item.amount > 0 then
|
-- Dispose all items
|
||||||
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
for slot, item in pairs(items) do
|
||||||
if success then
|
if item and item.amount and item.amount > 0 then
|
||||||
table.insert(disposedItems, {name = item.name, amount = item.amount})
|
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
|
||||||
totalItems = totalItems + item.amount
|
totalItems = totalItems + item.amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if #disposedItems > 0 then
|
|
||||||
-- Log for admins
|
-- Log for admins
|
||||||
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' ..
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has stored ALL items (' .. totalItems .. ' items)')
|
||||||
(type == "shredder" and 'destroyed' or 'disposed') .. ' ALL items (' .. totalItems .. ' items)')
|
|
||||||
|
|
||||||
-- Discord Webhook with item list
|
-- Discord Webhook with item list
|
||||||
local itemList = ""
|
local itemList = ""
|
||||||
for _, item in pairs(disposedItems) do
|
for slot, item in pairs(items) do
|
||||||
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
if item and item.amount and item.amount > 0 then
|
||||||
end
|
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
||||||
|
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
|
||||||
type == "shredder" and 'All Items Destroyed' or 'All Items Disposed',
|
|
||||||
type == "shredder" and 'red' or 'green',
|
|
||||||
'**Player:** ' .. GetPlayerName(src) ..
|
|
||||||
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
|
||||||
'\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') ..
|
|
||||||
'\n**Total Items:** ' .. totalItems ..
|
|
||||||
'\n**Items:**\n' .. itemList)
|
|
||||||
|
|
||||||
-- Different messages based on type
|
|
||||||
local message = ""
|
|
||||||
if type == "shredder" then
|
|
||||||
message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!'
|
|
||||||
else
|
|
||||||
message = 'ALLE Items (' .. totalItems .. ' Stück) wurden entsorgt!'
|
|
||||||
|
|
||||||
-- For trash bins, schedule deletion if not already scheduled
|
|
||||||
if not scheduledDeletions[containerID] then
|
|
||||||
ScheduleItemDeletion(containerID)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
||||||
else
|
'All Items Stored',
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error')
|
'green',
|
||||||
end
|
'**Player:** ' .. GetPlayerName(src) ..
|
||||||
end)
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
||||||
|
'\n**Action:** All items stored in container' ..
|
||||||
-- Save scheduled deletions when resource stops
|
'\n**Total Items:** ' .. totalItems ..
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
'\n**Items:**\n' .. itemList)
|
||||||
if resourceName ~= GetCurrentResourceName() then return end
|
|
||||||
|
|
||||||
-- Here you could save scheduledDeletions to a database
|
|
||||||
-- Example with KVP:
|
|
||||||
local savedData = {}
|
|
||||||
for containerID, data in pairs(scheduledDeletions) do
|
|
||||||
savedData[containerID] = {
|
|
||||||
deleteAt = data.deleteAt
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
SaveResourceFile(GetCurrentResourceName(), "scheduled_deletions.json", json.encode(savedData), -1)
|
|
||||||
print("^3[DISPOSAL]^7 Saved " .. #savedData .. " scheduled deletions")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Restore scheduled deletions when resource starts
|
|
||||||
AddEventHandler('onResourceStart', function(resourceName)
|
|
||||||
if resourceName ~= GetCurrentResourceName() then return end
|
|
||||||
|
|
||||||
-- Here you could load scheduled deletions from a database
|
|
||||||
-- Example with KVP:
|
|
||||||
local savedData = json.decode(LoadResourceFile(GetCurrentResourceName(), "scheduled_deletions.json") or "{}")
|
|
||||||
|
|
||||||
for containerID, data in pairs(savedData) do
|
|
||||||
local currentTime = os.time()
|
|
||||||
local remainingTime = data.deleteAt - currentTime
|
|
||||||
|
|
||||||
if remainingTime > 0 then
|
-- Notification message
|
||||||
ScheduleItemDeletion(containerID, remainingTime)
|
local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden im Lager gespeichert!'
|
||||||
else
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
||||||
-- If the time has already passed, delete immediately
|
|
||||||
DeleteTrashBinItems(containerID)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions")
|
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue