forked from Simnation/Main
ed
This commit is contained in:
parent
31ddbf70b2
commit
55ce22c3de
2 changed files with 241 additions and 237 deletions
|
@ -1,12 +1,12 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Liste der Prop-Modelle für sofortige Schredder
|
-- List of prop models that should be targetable as immediate shredders
|
||||||
local shredderPropModels = {
|
local shredderPropModels = {
|
||||||
'p_secret_weapon_02',
|
'p_secret_weapon_02',
|
||||||
'prop_bin_08a'
|
'prop_bin_08a'
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Liste der Prop-Modelle für zeitverzögerte Mülltonnen
|
-- List of prop models that should be targetable as trash bins with delayed deletion
|
||||||
local trashBinPropModels = {
|
local trashBinPropModels = {
|
||||||
'prop_bin_01a',
|
'prop_bin_01a',
|
||||||
'prop_bin_03a',
|
'prop_bin_03a',
|
||||||
|
@ -18,78 +18,86 @@ local trashBinPropModels = {
|
||||||
'prop_dumpster_3a'
|
'prop_dumpster_3a'
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Variable zum Speichern der aktuellen Entität
|
-- Variable to store the current entity being interacted with
|
||||||
local currentEntity = nil
|
local currentEntity = nil
|
||||||
local currentType = nil
|
local currentType = nil
|
||||||
|
|
||||||
-- QB-Target zu allen passenden Props in der Welt hinzufügen
|
-- Add QB-Target to all matching props in the world
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
-- Schredder-Optionen definieren
|
-- Add target to shredder props
|
||||||
local shredderOptions = {
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
event = "disposal:openInventory",
|
|
||||||
icon = "fas fa-dumpster",
|
|
||||||
label = "Müllschredder öffnen",
|
|
||||||
action = function(entity)
|
|
||||||
currentEntity = entity
|
|
||||||
currentType = "shredder"
|
|
||||||
TriggerEvent('disposal:openInventory')
|
|
||||||
end,
|
|
||||||
canInteract = function()
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
event = "disposal:openMenu",
|
|
||||||
icon = "fas fa-fire",
|
|
||||||
label = "Items vernichten",
|
|
||||||
action = function(entity)
|
|
||||||
currentEntity = entity
|
|
||||||
currentType = "shredder"
|
|
||||||
TriggerEvent('disposal:openMenu')
|
|
||||||
end,
|
|
||||||
canInteract = function()
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Mülltonnen-Optionen definieren
|
|
||||||
local trashOptions = {
|
|
||||||
{
|
|
||||||
type = "client",
|
|
||||||
event = "disposal:openInventory",
|
|
||||||
icon = "fas fa-trash",
|
|
||||||
label = "Mülltonne öffnen",
|
|
||||||
action = function(entity)
|
|
||||||
currentEntity = entity
|
|
||||||
currentType = "trash"
|
|
||||||
TriggerEvent('disposal:openInventory')
|
|
||||||
end,
|
|
||||||
canInteract = function()
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- QB-Target für Schredder hinzufügen
|
|
||||||
exports['qb-target']:AddTargetModel(shredderPropModels, {
|
exports['qb-target']:AddTargetModel(shredderPropModels, {
|
||||||
options = shredderOptions,
|
options = {
|
||||||
|
{
|
||||||
|
type = "client",
|
||||||
|
event = "disposal:openInventory",
|
||||||
|
icon = "fas fa-dumpster",
|
||||||
|
label = "Müllschredder öffnen",
|
||||||
|
action = function(entity)
|
||||||
|
currentEntity = entity
|
||||||
|
currentType = "shredder"
|
||||||
|
TriggerEvent('disposal:openInventory')
|
||||||
|
end,
|
||||||
|
canInteract = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "client",
|
||||||
|
event = "disposal:openMenu",
|
||||||
|
icon = "fas fa-fire",
|
||||||
|
label = "Items vernichten",
|
||||||
|
action = function(entity)
|
||||||
|
currentEntity = entity
|
||||||
|
currentType = "shredder"
|
||||||
|
TriggerEvent('disposal:openMenu')
|
||||||
|
end,
|
||||||
|
canInteract = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
},
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
-- QB-Target für Mülltonnen hinzufügen
|
-- Add target to trash bin props
|
||||||
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
||||||
options = trashOptions,
|
options = {
|
||||||
|
{
|
||||||
|
type = "client",
|
||||||
|
event = "disposal:openInventory",
|
||||||
|
icon = "fas fa-trash",
|
||||||
|
label = "Mülltonne öffnen",
|
||||||
|
action = function(entity)
|
||||||
|
currentEntity = entity
|
||||||
|
currentType = "trash"
|
||||||
|
TriggerEvent('disposal:openInventory')
|
||||||
|
end,
|
||||||
|
canInteract = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type = "client",
|
||||||
|
event = "disposal:openMenu",
|
||||||
|
icon = "fas fa-clock",
|
||||||
|
label = "Müll entsorgen",
|
||||||
|
action = function(entity)
|
||||||
|
currentEntity = entity
|
||||||
|
currentType = "trash"
|
||||||
|
TriggerEvent('disposal:openMenu')
|
||||||
|
end,
|
||||||
|
canInteract = function()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
},
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
print("^2[DISPOSAL]^7 QB-Target zu " .. #shredderPropModels .. " Schredder-Modellen und " .. #trashBinPropModels .. " Mülltonnen-Modellen hinzugefügt")
|
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Funktion zum Abrufen der Container-ID aus der Entität
|
-- Function to get container ID from entity
|
||||||
function GetContainerIDFromEntity(entity, type)
|
function GetContainerIDFromEntity(entity, type)
|
||||||
if not entity or not DoesEntityExist(entity) then return nil end
|
if not entity or not DoesEntityExist(entity) then return nil end
|
||||||
|
|
||||||
|
@ -98,7 +106,7 @@ function GetContainerIDFromEntity(entity, type)
|
||||||
return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Container-Inventar öffnen
|
-- Open container inventory
|
||||||
RegisterNetEvent('disposal:openInventory', function()
|
RegisterNetEvent('disposal:openInventory', function()
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
local coords = GetEntityCoords(playerPed)
|
local coords = GetEntityCoords(playerPed)
|
||||||
|
@ -112,49 +120,46 @@ RegisterNetEvent('disposal:openInventory', function()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Container-ID abrufen
|
-- Get container ID
|
||||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
||||||
if not containerID then return end
|
if not containerID then return end
|
||||||
|
|
||||||
-- Inventar mit dieser eindeutigen ID öffnen
|
-- Open inventory with this unique ID
|
||||||
TriggerServerEvent('disposal:server:openInventory', containerID, currentType)
|
TriggerServerEvent('disposal:server:openInventory', containerID, currentType)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Vernichtungsmenü öffnen (nur für Schredder)
|
-- Open disposal menu
|
||||||
RegisterNetEvent('disposal:openMenu', function()
|
RegisterNetEvent('disposal:openMenu', function()
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
local coords = GetEntityCoords(playerPed)
|
local coords = GetEntityCoords(playerPed)
|
||||||
|
|
||||||
if not currentEntity or not DoesEntityExist(currentEntity) or currentType ~= "shredder" then
|
if not currentEntity or not DoesEntityExist(currentEntity) then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Müllschredder',
|
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||||
description = 'Kein Schredder gefunden!',
|
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Container-ID abrufen
|
-- Get container ID
|
||||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
||||||
if not containerID then return end
|
if not containerID then return end
|
||||||
|
|
||||||
-- Items in diesem Container abrufen
|
-- Get items in this container
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, currentType)
|
TriggerServerEvent('disposal:server:getItems', containerID, currentType)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Menü mit Items anzeigen (nur für Schredder)
|
-- Show menu with items
|
||||||
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining)
|
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining)
|
||||||
-- Nur für Schredder fortfahren
|
-- Make sure items is a table
|
||||||
if type ~= "shredder" then return end
|
|
||||||
|
|
||||||
-- Sicherstellen, dass items eine Tabelle ist
|
|
||||||
items = items or {}
|
items = items or {}
|
||||||
|
|
||||||
-- Prüfen, ob items leer ist
|
-- Check if items is empty
|
||||||
if next(items) == nil then
|
if next(items) == nil then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Müllschredder',
|
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||||
description = 'Der Schredder ist leer!',
|
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -162,23 +167,40 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
|
|
||||||
local menuOptions = {}
|
local menuOptions = {}
|
||||||
|
|
||||||
-- Alle Items vernichten Option
|
-- All items action option
|
||||||
|
local actionText = type == "shredder" and "ALLE ITEMS VERNICHTEN" or "ALLE ITEMS ENTSORGEN"
|
||||||
|
local actionDesc = type == "shredder"
|
||||||
|
and 'Vernichtet alle Items im Schredder permanent!'
|
||||||
|
or 'Entsorgt alle Items in der Mülltonne (automatische Löschung nach Zeit)!'
|
||||||
|
|
||||||
table.insert(menuOptions, {
|
table.insert(menuOptions, {
|
||||||
title = '🔥 ALLE ITEMS VERNICHTEN',
|
title = '🔥 ' .. actionText,
|
||||||
description = 'Vernichtet alle Items im Schredder permanent!',
|
description = actionDesc,
|
||||||
icon = 'fire',
|
icon = type == "shredder" and 'fire' or 'trash',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
confirmDestroyAll(containerID)
|
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:',
|
||||||
disabled = true
|
disabled = true
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Einzelne Items zum Menü hinzufügen
|
-- Add individual items to menu
|
||||||
local hasItems = false
|
local hasItems = false
|
||||||
for slot, item in pairs(items) do
|
for slot, item in pairs(items) do
|
||||||
if item and item.amount and item.amount > 0 then
|
if item and item.amount and item.amount > 0 then
|
||||||
|
@ -188,7 +210,7 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
|
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
|
||||||
icon = 'trash',
|
icon = 'trash',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
confirmDestroySingle(item.name, item.amount, slot, containerID)
|
confirmDestroySingle(item.name, item.amount, slot, containerID, type)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -196,8 +218,8 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
|
|
||||||
if not hasItems then
|
if not hasItems then
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = 'Müllschredder',
|
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
||||||
description = 'Der Schredder ist leer!',
|
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -205,25 +227,30 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'disposal_menu',
|
id = 'disposal_menu',
|
||||||
title = '🗑️ Müllschredder Verwaltung',
|
title = type == "shredder" and '🗑️ Müllschredder Verwaltung' or '🗑️ Mülltonne Verwaltung',
|
||||||
options = menuOptions
|
options = menuOptions
|
||||||
})
|
})
|
||||||
|
|
||||||
lib.showContext('disposal_menu')
|
lib.showContext('disposal_menu')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Einzelnes Item vernichten bestätigen (nur für Schredder)
|
-- Confirm single item disposal
|
||||||
function confirmDestroySingle(itemName, amount, slot, containerID)
|
function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
||||||
|
local actionText = type == "shredder" and "vernichten" or "entsorgen"
|
||||||
|
local actionDesc = type == "shredder"
|
||||||
|
and (itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!')
|
||||||
|
or (itemName .. ' (' .. amount .. 'x) wird entsorgt und nach Zeit gelöscht!')
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'dispose_single_confirm',
|
id = 'dispose_single_confirm',
|
||||||
title = '⚠️ Item vernichten?',
|
title = '⚠️ Item ' .. actionText .. '?',
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
title = '🔥 Ja, vernichten',
|
title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen',
|
||||||
description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
|
description = actionDesc,
|
||||||
icon = 'fire',
|
icon = 'check',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, "shredder")
|
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -231,7 +258,7 @@ function confirmDestroySingle(itemName, amount, slot, containerID)
|
||||||
description = 'Zurück zum Hauptmenü',
|
description = 'Zurück zum Hauptmenü',
|
||||||
icon = 'times',
|
icon = 'times',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, "shredder")
|
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,18 +267,23 @@ function confirmDestroySingle(itemName, amount, slot, containerID)
|
||||||
lib.showContext('dispose_single_confirm')
|
lib.showContext('dispose_single_confirm')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Alle Items vernichten bestätigen (nur für Schredder)
|
-- Confirm all items disposal
|
||||||
function confirmDestroyAll(containerID)
|
function confirmDestroyAll(containerID, type)
|
||||||
|
local actionText = type == "shredder" and "VERNICHTEN" or "ENTSORGEN"
|
||||||
|
local actionDesc = type == "shredder"
|
||||||
|
and 'ALLE Items im Schredder werden permanent gelöscht!'
|
||||||
|
or 'ALLE Items in der Mülltonne werden nach Zeit automatisch gelöscht!'
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'dispose_all_confirm',
|
id = 'dispose_all_confirm',
|
||||||
title = '⚠️ WARNUNG ⚠️',
|
title = '⚠️ WARNUNG ⚠️',
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
title = '🔥 JA, ALLES VERNICHTEN',
|
title = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN',
|
||||||
description = 'ALLE Items im Schredder werden permanent gelöscht!',
|
description = actionDesc,
|
||||||
icon = 'fire',
|
icon = type == "shredder" and 'fire' or 'trash',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeAll', containerID, "shredder")
|
TriggerServerEvent('disposal:server:disposeAll', containerID, type)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -259,7 +291,7 @@ function confirmDestroyAll(containerID)
|
||||||
description = 'Zurück zum Hauptmenü',
|
description = 'Zurück zum Hauptmenü',
|
||||||
icon = 'times',
|
icon = 'times',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, "shredder")
|
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,7 +300,7 @@ function confirmDestroyAll(containerID)
|
||||||
lib.showContext('dispose_all_confirm')
|
lib.showContext('dispose_all_confirm')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Erfolgs-Notification mit Effekt
|
-- 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 'Mülltonne',
|
||||||
|
@ -277,7 +309,7 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||||
duration = 4000
|
duration = 4000
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Partikel-Effekt
|
-- Particle effect
|
||||||
local playerPed = PlayerPedId()
|
local playerPed = PlayerPedId()
|
||||||
local coords = GetEntityCoords(playerPed)
|
local coords = GetEntityCoords(playerPed)
|
||||||
|
|
||||||
|
@ -288,35 +320,14 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||||
|
|
||||||
UseParticleFxAssetNextCall("core")
|
UseParticleFxAssetNextCall("core")
|
||||||
|
|
||||||
-- Unterschiedliche Effekte je nach Typ
|
-- Different effects for shredder vs trash
|
||||||
if type == "shredder" then
|
if type == "shredder" then
|
||||||
-- Intensiverer Effekt für Schredder
|
-- 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
|
||||||
-- Subtiler Effekt für Mülltonnen
|
-- Subtle effect for trash
|
||||||
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
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Informationen über zeitverzögerte Löschung anzeigen
|
|
||||||
RegisterNetEvent('disposal:client:showTrashInfo', function(deleteTime)
|
|
||||||
local days = math.floor(deleteTime / 86400)
|
|
||||||
local hours = math.floor((deleteTime % 86400) / 3600)
|
|
||||||
local minutes = math.floor((deleteTime % 3600) / 60)
|
|
||||||
|
|
||||||
local timeString = ""
|
|
||||||
if days > 0 then
|
|
||||||
timeString = days .. " Tag" .. (days > 1 and "e" or "") .. ", "
|
|
||||||
end
|
|
||||||
timeString = timeString .. hours .. " Stunde" .. (hours > 1 and "n" or "") .. ", "
|
|
||||||
timeString = timeString .. minutes .. " Minute" .. (minutes > 1 and "n" or "")
|
|
||||||
|
|
||||||
lib.notify({
|
|
||||||
title = 'Mülltonne',
|
|
||||||
description = 'Items werden in ' .. timeString .. ' automatisch gelöscht!',
|
|
||||||
type = 'info',
|
|
||||||
duration = 6000
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Tabelle zum Speichern von geplanten Löschungen
|
-- Table to store items scheduled for deletion
|
||||||
local scheduledDeletions = {}
|
local scheduledDeletions = {}
|
||||||
|
|
||||||
-- Standard-Zeit für Mülltonnen-Löschung (2 Tage = 48 Stunden = 172800 Sekunden)
|
-- Default time for trash bin deletion (2 days = 48 hours = 172800 seconds)
|
||||||
local DEFAULT_TRASH_DELETE_TIME = 172800 -- seconds
|
local DEFAULT_TRASH_DELETE_TIME = 172800 -- seconds
|
||||||
|
|
||||||
-- Funktion zum Planen der Item-Löschung
|
-- Function to schedule item deletion
|
||||||
function ScheduleItemDeletion(containerID, deleteTime)
|
function ScheduleItemDeletion(containerID, deleteTime)
|
||||||
-- Standard-Löschzeit verwenden, wenn nicht angegeben
|
-- Use default time if not specified
|
||||||
deleteTime = deleteTime or DEFAULT_TRASH_DELETE_TIME
|
deleteTime = deleteTime or DEFAULT_TRASH_DELETE_TIME
|
||||||
|
|
||||||
-- Bestehenden Timer abbrechen, falls vorhanden
|
-- Cancel existing timer if there is one
|
||||||
if scheduledDeletions[containerID] and scheduledDeletions[containerID].timer then
|
if scheduledDeletions[containerID] and scheduledDeletions[containerID].timer then
|
||||||
clearTimeout(scheduledDeletions[containerID].timer)
|
clearTimeout(scheduledDeletions[containerID].timer)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Löschung planen
|
-- Schedule the deletion
|
||||||
scheduledDeletions[containerID] = {
|
scheduledDeletions[containerID] = {
|
||||||
deleteAt = os.time() + deleteTime,
|
deleteAt = os.time() + deleteTime,
|
||||||
timer = setTimeout(function()
|
timer = setTimeout(function()
|
||||||
|
@ -24,18 +24,16 @@ function ScheduleItemDeletion(containerID, deleteTime)
|
||||||
end, deleteTime * 1000)
|
end, deleteTime * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Items in " .. containerID .. " werden in " .. deleteTime .. " Sekunden gelöscht")
|
print("^3[DISPOSAL]^7 Items in " .. containerID .. " scheduled for deletion in " .. deleteTime .. " seconds")
|
||||||
|
|
||||||
return deleteTime
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Funktion zum Löschen von Items aus einer Mülltonne
|
-- Function to delete items from a trash bin
|
||||||
function DeleteTrashBinItems(containerID)
|
function DeleteTrashBinItems(containerID)
|
||||||
-- Alle Items in der Mülltonne abrufen
|
-- 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 Keine Items zum Löschen in " .. containerID)
|
print("^3[DISPOSAL]^7 No items to delete in " .. containerID)
|
||||||
scheduledDeletions[containerID] = nil
|
scheduledDeletions[containerID] = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -43,7 +41,7 @@ function DeleteTrashBinItems(containerID)
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
local disposedItems = {}
|
local disposedItems = {}
|
||||||
|
|
||||||
-- Alle Items löschen
|
-- Delete all items
|
||||||
for slot, item in pairs(items) do
|
for slot, item in pairs(items) do
|
||||||
if item and item.amount and item.amount > 0 then
|
if item and item.amount and item.amount > 0 then
|
||||||
exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
||||||
|
@ -52,22 +50,22 @@ function DeleteTrashBinItems(containerID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Automatisch " .. totalItems .. " Items aus " .. containerID .. " gelöscht")
|
print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID)
|
||||||
|
|
||||||
-- Log der automatischen Löschung
|
-- Log the automatic 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', 'Automatische Müllentsorgung', 'yellow',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Automatic Trash Deletion', 'yellow',
|
||||||
'**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList)
|
'**Container:** ' .. containerID .. '\n**Anzahl Items:** ' .. totalItems .. '\n**Items:**\n' .. itemList)
|
||||||
|
|
||||||
-- Aus geplanten Löschungen entfernen
|
-- Remove from scheduled deletions
|
||||||
scheduledDeletions[containerID] = nil
|
scheduledDeletions[containerID] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Verbleibende Zeit für eine geplante Löschung abrufen
|
-- Get time remaining for a scheduled deletion
|
||||||
function GetTimeRemaining(containerID)
|
function GetTimeRemaining(containerID)
|
||||||
if scheduledDeletions[containerID] then
|
if scheduledDeletions[containerID] then
|
||||||
local currentTime = os.time()
|
local currentTime = os.time()
|
||||||
|
@ -83,131 +81,121 @@ function GetTimeRemaining(containerID)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Container-Inventar öffnen
|
-- Container inventory open
|
||||||
RegisterNetEvent('disposal:server:openInventory', function(containerID, type)
|
RegisterNetEvent('disposal:server:openInventory', function(containerID, type)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Inventar öffnen
|
-- Open the inventory
|
||||||
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 'Mülltonne'
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Wenn es eine Mülltonne ist, nach Items prüfen und Löschung planen
|
-- If it's a trash bin, schedule deletion if not already scheduled
|
||||||
if type == "trash" then
|
if type == "trash" and not scheduledDeletions[containerID] then
|
||||||
-- Kurze Verzögerung, um sicherzustellen, dass das Inventar geladen ist
|
-- Check if there are items in the container
|
||||||
SetTimeout(500, function()
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
||||||
-- Prüfen, ob Items in der Mülltonne sind
|
if items and next(items) then
|
||||||
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
ScheduleItemDeletion(containerID)
|
||||||
if items and next(items) then
|
end
|
||||||
-- Nur planen, wenn noch nicht geplant
|
|
||||||
if not scheduledDeletions[containerID] then
|
|
||||||
local deleteTime = ScheduleItemDeletion(containerID)
|
|
||||||
|
|
||||||
-- Spieler über die geplante Löschung informieren
|
|
||||||
local days = math.floor(deleteTime / 86400)
|
|
||||||
local hours = math.floor((deleteTime % 86400) / 3600)
|
|
||||||
local minutes = math.floor((deleteTime % 3600) / 60)
|
|
||||||
|
|
||||||
local timeString = ""
|
|
||||||
if days > 0 then
|
|
||||||
timeString = days .. " Tag" .. (days > 1 and "e" or "") .. ", "
|
|
||||||
end
|
|
||||||
timeString = timeString .. hours .. " Stunde" .. (hours > 1 and "n" or "") .. ", "
|
|
||||||
timeString = timeString .. minutes .. " Minute" .. (minutes > 1 and "n" or "")
|
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:showTrashInfo', src, deleteTime)
|
|
||||||
else
|
|
||||||
-- Wenn bereits geplant, verbleibende Zeit anzeigen
|
|
||||||
local remainingTime = GetTimeRemaining(containerID)
|
|
||||||
if remainingTime then
|
|
||||||
TriggerClientEvent('disposal:client:showTrashInfo', src, remainingTime)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Items aus Container abrufen (nur für Schredder)
|
-- Get items from container
|
||||||
RegisterNetEvent('disposal:server:getItems', function(containerID, type)
|
RegisterNetEvent('disposal:server:getItems', function(containerID, type)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Nur für Schredder fortfahren
|
-- Get items from the container
|
||||||
if type ~= "shredder" then return end
|
|
||||||
|
|
||||||
-- Items aus dem Container abrufen
|
|
||||||
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", containerID)
|
||||||
|
|
||||||
-- Wenn items nil ist, leere Tabelle bereitstellen
|
-- If items is nil, provide an empty table
|
||||||
if items == nil then items = {} end
|
if items == nil then items = {} end
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type)
|
-- Get time remaining for trash bins
|
||||||
|
local timeRemaining = nil
|
||||||
|
if type == "trash" then
|
||||||
|
timeRemaining = GetTimeRemaining(containerID)
|
||||||
|
end
|
||||||
|
|
||||||
|
TriggerClientEvent('disposal:client:showMenu', src, items, containerID, type, timeRemaining)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Einzelnes Item entsorgen (nur für Schredder)
|
-- Dispose single item
|
||||||
RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID, type)
|
RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID, type)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Nur für Schredder fortfahren
|
-- Remove the item from the container
|
||||||
if type ~= "shredder" then return end
|
|
||||||
|
|
||||||
-- Item aus dem Container entfernen
|
|
||||||
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot)
|
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, itemName, amount, slot)
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
-- Log für Admins
|
-- Log for admins
|
||||||
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') hat ' .. amount .. 'x ' .. itemName .. ' vernichtet')
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' ..
|
||||||
|
(type == "shredder" and 'destroyed' or 'disposed') .. ' ' .. amount .. 'x ' .. itemName)
|
||||||
|
|
||||||
-- Discord Webhook
|
-- Discord Webhook
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Item Vernichtet', 'orange',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
||||||
'**Spieler:** ' .. GetPlayerName(src) ..
|
type == "shredder" and 'Item Destroyed' or 'Item Disposed',
|
||||||
|
type == "shredder" and 'orange' or 'blue',
|
||||||
|
'**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**Aktion:** Item vernichtet')
|
'\n**Action:** ' .. (type == "shredder" and 'Item destroyed' or 'Item disposed'))
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:itemDisposed', src, amount .. 'x ' .. itemName .. ' wurde vernichtet!', type)
|
-- 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
|
||||||
|
|
||||||
-- Menü neu laden
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
||||||
|
|
||||||
|
-- Reload menu
|
||||||
Wait(1000)
|
Wait(1000)
|
||||||
TriggerEvent('disposal:server:getItems', containerID, type)
|
TriggerEvent('disposal:server:getItems', containerID, type)
|
||||||
else
|
else
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Vernichten des Items!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Alle Items entsorgen (nur für Schredder)
|
-- Dispose all items
|
||||||
RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Nur für Schredder fortfahren
|
-- Get all items in the container
|
||||||
if type ~= "shredder" then return end
|
|
||||||
|
|
||||||
-- Alle Items im Container abrufen
|
|
||||||
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
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Der Schredder ist bereits leer!', 'error')
|
TriggerClientEvent('QBCore:Notify', src,
|
||||||
|
type == "shredder" and 'Der Schredder ist bereits leer!' or 'Die Mülltonne ist bereits leer!',
|
||||||
|
'error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local disposedItems = {}
|
local disposedItems = {}
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
|
|
||||||
-- Alle Items entsorgen
|
-- Dispose all items
|
||||||
for slot, item in pairs(items) do
|
for slot, item in pairs(items) do
|
||||||
if item and item.amount and item.amount > 0 then
|
if item and item.amount and item.amount > 0 then
|
||||||
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
local success = exports["tgiann-inventory"]:RemoveItemFromSecondaryInventory("stash", containerID, item.name, item.amount, slot)
|
||||||
|
@ -219,45 +207,50 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
if #disposedItems > 0 then
|
if #disposedItems > 0 then
|
||||||
-- Log für Admins
|
-- Log for admins
|
||||||
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') hat ALLE Items vernichtet (' .. totalItems .. ' Items)')
|
print('^3[DISPOSAL]^7 ' .. GetPlayerName(src) .. ' (' .. Player.PlayerData.citizenid .. ') has ' ..
|
||||||
|
(type == "shredder" and 'destroyed' or 'disposed') .. ' ALL items (' .. totalItems .. ' items)')
|
||||||
|
|
||||||
-- Discord Webhook mit Item-Liste
|
-- Discord Webhook with item list
|
||||||
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', 'Alle Items Vernichtet', 'red',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
||||||
'**Spieler:** ' .. GetPlayerName(src) ..
|
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**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
||||||
'\n**Aktion:** Alle Items vernichtet' ..
|
'\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') ..
|
||||||
'\n**Anzahl Items:** ' .. totalItems ..
|
'\n**Total Items:** ' .. totalItems ..
|
||||||
'\n**Items:**\n' .. itemList)
|
'\n**Items:**\n' .. itemList)
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:itemDisposed', src, 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!', type)
|
-- Different messages based on type
|
||||||
else
|
local message = ""
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Vernichten gefunden!', 'error')
|
if type == "shredder" then
|
||||||
end
|
message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!'
|
||||||
end)
|
else
|
||||||
|
message = 'ALLE Items (' .. totalItems .. ' Stück) wurden entsorgt!'
|
||||||
-- Export-Funktion, die von tgiann-inventory aufgerufen werden kann, wenn Items hinzugefügt werden
|
|
||||||
exports('OnItemAddedToStash', function(stashId, itemName, amount, slot, metadata)
|
-- For trash bins, schedule deletion if not already scheduled
|
||||||
-- Prüfen, ob dies eine Mülltonne ist
|
if not scheduledDeletions[containerID] then
|
||||||
if string.find(stashId, "trash_") then
|
ScheduleItemDeletion(containerID)
|
||||||
-- Löschung planen, wenn noch nicht geplant
|
end
|
||||||
if not scheduledDeletions[stashId] then
|
|
||||||
ScheduleItemDeletion(stashId)
|
|
||||||
print("^3[DISPOSAL]^7 Timer für " .. stashId .. " gestartet, nachdem Item hinzugefügt wurde")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
||||||
|
else
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error')
|
||||||
end
|
end
|
||||||
return true
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Geplante Löschungen speichern, wenn die Ressource gestoppt wird
|
-- Save scheduled deletions when resource stops
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
if resourceName ~= GetCurrentResourceName() then return end
|
if resourceName ~= GetCurrentResourceName() then return end
|
||||||
|
|
||||||
|
-- Here you could save scheduledDeletions to a database
|
||||||
|
-- Example with KVP:
|
||||||
local savedData = {}
|
local savedData = {}
|
||||||
for containerID, data in pairs(scheduledDeletions) do
|
for containerID, data in pairs(scheduledDeletions) do
|
||||||
savedData[containerID] = {
|
savedData[containerID] = {
|
||||||
|
@ -266,15 +259,16 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
end
|
end
|
||||||
|
|
||||||
SaveResourceFile(GetCurrentResourceName(), "scheduled_deletions.json", json.encode(savedData), -1)
|
SaveResourceFile(GetCurrentResourceName(), "scheduled_deletions.json", json.encode(savedData), -1)
|
||||||
print("^3[DISPOSAL]^7 " .. #savedData .. " geplante Löschungen gespeichert")
|
print("^3[DISPOSAL]^7 Saved " .. #savedData .. " scheduled deletions")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Geplante Löschungen wiederherstellen, wenn die Ressource gestartet wird
|
-- Restore scheduled deletions when resource starts
|
||||||
AddEventHandler('onResourceStart', function(resourceName)
|
AddEventHandler('onResourceStart', function(resourceName)
|
||||||
if resourceName ~= GetCurrentResourceName() then return end
|
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 "{}")
|
local savedData = json.decode(LoadResourceFile(GetCurrentResourceName(), "scheduled_deletions.json") or "{}")
|
||||||
local restoredCount = 0
|
|
||||||
|
|
||||||
for containerID, data in pairs(savedData) do
|
for containerID, data in pairs(savedData) do
|
||||||
local currentTime = os.time()
|
local currentTime = os.time()
|
||||||
|
@ -282,12 +276,11 @@ AddEventHandler('onResourceStart', function(resourceName)
|
||||||
|
|
||||||
if remainingTime > 0 then
|
if remainingTime > 0 then
|
||||||
ScheduleItemDeletion(containerID, remainingTime)
|
ScheduleItemDeletion(containerID, remainingTime)
|
||||||
restoredCount = restoredCount + 1
|
|
||||||
else
|
else
|
||||||
-- Wenn die Zeit bereits abgelaufen ist, sofort löschen
|
-- If the time has already passed, delete immediately
|
||||||
DeleteTrashBinItems(containerID)
|
DeleteTrashBinItems(containerID)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 " .. restoredCount .. " geplante Löschungen wiederhergestellt")
|
print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions")
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue