forked from Simnation/Main
ed
This commit is contained in:
parent
5845490f4c
commit
92d275a753
2 changed files with 60 additions and 309 deletions
|
@ -1,26 +1,13 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- List of prop models that should be targetable as immediate shredders
|
-- List of prop models that should be targetable as shredders
|
||||||
local shredderPropModels = {
|
local shredderPropModels = {
|
||||||
'p_secret_weapon_02',
|
'p_secret_weapon_02',
|
||||||
'prop_bin_08a'
|
'prop_bin_08a'
|
||||||
}
|
}
|
||||||
|
|
||||||
-- List of prop models that should be targetable as trash bins with delayed deletion
|
|
||||||
local trashBinPropModels = {
|
|
||||||
'prop_bin_01a',
|
|
||||||
'prop_bin_03a',
|
|
||||||
'prop_bin_04a',
|
|
||||||
'prop_bin_07a',
|
|
||||||
'prop_dumpster_01a',
|
|
||||||
'prop_dumpster_02a',
|
|
||||||
'prop_dumpster_02b',
|
|
||||||
'prop_dumpster_3a'
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Variable to store the current entity being interacted with
|
-- Variable to store the current entity being interacted with
|
||||||
local currentEntity = nil
|
local currentEntity = nil
|
||||||
local currentType = nil
|
|
||||||
|
|
||||||
-- Add QB-Target to all matching props in the world
|
-- Add QB-Target to all matching props in the world
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
|
@ -34,7 +21,6 @@ Citizen.CreateThread(function()
|
||||||
label = "Müllschredder öffnen",
|
label = "Müllschredder öffnen",
|
||||||
action = function(entity)
|
action = function(entity)
|
||||||
currentEntity = entity
|
currentEntity = entity
|
||||||
currentType = "shredder"
|
|
||||||
TriggerEvent('disposal:openInventory')
|
TriggerEvent('disposal:openInventory')
|
||||||
end,
|
end,
|
||||||
canInteract = function()
|
canInteract = function()
|
||||||
|
@ -48,7 +34,6 @@ Citizen.CreateThread(function()
|
||||||
label = "Items vernichten",
|
label = "Items vernichten",
|
||||||
action = function(entity)
|
action = function(entity)
|
||||||
currentEntity = entity
|
currentEntity = entity
|
||||||
currentType = "shredder"
|
|
||||||
TriggerEvent('disposal:openMenu')
|
TriggerEvent('disposal:openMenu')
|
||||||
end,
|
end,
|
||||||
canInteract = function()
|
canInteract = function()
|
||||||
|
@ -59,51 +44,16 @@ Citizen.CreateThread(function()
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Add target to trash bin props
|
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models")
|
||||||
exports['qb-target']:AddTargetModel(trashBinPropModels, {
|
|
||||||
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
|
|
||||||
})
|
|
||||||
|
|
||||||
print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models and " .. #trashBinPropModels .. " trash bin models")
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Function to get container ID from entity
|
-- Function to get container ID from entity
|
||||||
function GetContainerIDFromEntity(entity, type)
|
function GetContainerIDFromEntity(entity)
|
||||||
if not entity or not DoesEntityExist(entity) then return nil end
|
if not entity or not DoesEntityExist(entity) then return nil end
|
||||||
|
|
||||||
local model = GetEntityModel(entity)
|
local model = GetEntityModel(entity)
|
||||||
local entityCoords = GetEntityCoords(entity)
|
local entityCoords = GetEntityCoords(entity)
|
||||||
return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
return "shredder" .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Open container inventory
|
-- Open container inventory
|
||||||
|
@ -113,19 +63,19 @@ 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 = 'Müllschredder',
|
||||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
description = 'Kein Schredder gefunden!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get container ID
|
-- Get container ID
|
||||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
local containerID = GetContainerIDFromEntity(currentEntity)
|
||||||
if not containerID then return end
|
if not containerID then return end
|
||||||
|
|
||||||
-- Open inventory with this unique ID
|
-- Open inventory with this unique ID
|
||||||
TriggerServerEvent('disposal:server:openInventory', containerID, currentType)
|
TriggerServerEvent('disposal:server:openInventory', containerID)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Open disposal menu
|
-- Open disposal menu
|
||||||
|
@ -135,31 +85,31 @@ 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 = 'Müllschredder',
|
||||||
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
|
description = 'Kein Schredder gefunden!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get container ID
|
-- Get container ID
|
||||||
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
|
local containerID = GetContainerIDFromEntity(currentEntity)
|
||||||
if not containerID then return end
|
if not containerID then return end
|
||||||
|
|
||||||
-- Get items in this container
|
-- Get items in this container
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, currentType)
|
TriggerServerEvent('disposal:server:getItems', containerID)
|
||||||
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)
|
||||||
-- 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 = 'Müllschredder',
|
||||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
description = 'Der Schredder ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -168,32 +118,15 @@ 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 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 = '🔥 ' .. actionText,
|
title = '🔥 ALLE ITEMS VERNICHTEN',
|
||||||
description = actionDesc,
|
description = 'Vernichtet alle Items im Schredder permanent!',
|
||||||
icon = type == "shredder" and 'fire' or 'trash',
|
icon = 'fire',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
confirmDestroyAll(containerID, type)
|
confirmDestroyAll(containerID)
|
||||||
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:',
|
||||||
|
@ -210,7 +143,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, type)
|
confirmDestroySingle(item.name, item.amount, slot, containerID)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -218,8 +151,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 = 'Müllschredder',
|
||||||
description = type == "shredder" and 'Der Schredder ist leer!' or 'Die Mülltonne ist leer!',
|
description = 'Der Schredder ist leer!',
|
||||||
type = 'error'
|
type = 'error'
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
@ -227,7 +160,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 = '🗑️ Müllschredder Verwaltung',
|
||||||
options = menuOptions
|
options = menuOptions
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -235,22 +168,17 @@ RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type,
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Confirm single item disposal
|
-- Confirm single item disposal
|
||||||
function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
function confirmDestroySingle(itemName, amount, slot, containerID)
|
||||||
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 ' .. actionText .. '?',
|
title = '⚠️ Item vernichten?',
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
title = type == "shredder" and '🔥 Ja, vernichten' or '🗑️ Ja, entsorgen',
|
title = '🔥 Ja, vernichten',
|
||||||
description = actionDesc,
|
description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
|
||||||
icon = 'check',
|
icon = 'check',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, type)
|
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -258,7 +186,7 @@ function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
||||||
description = 'Zurück zum Hauptmenü',
|
description = 'Zurück zum Hauptmenü',
|
||||||
icon = 'times',
|
icon = 'times',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
TriggerServerEvent('disposal:server:getItems', containerID)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -268,22 +196,17 @@ function confirmDestroySingle(itemName, amount, slot, containerID, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Confirm all items disposal
|
-- Confirm all items disposal
|
||||||
function confirmDestroyAll(containerID, type)
|
function confirmDestroyAll(containerID)
|
||||||
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 = type == "shredder" and '🔥 JA, ALLES VERNICHTEN' or '🗑️ JA, ALLES ENTSORGEN',
|
title = '🔥 JA, ALLES VERNICHTEN',
|
||||||
description = actionDesc,
|
description = 'ALLE Items im Schredder werden permanent gelöscht!',
|
||||||
icon = type == "shredder" and 'fire' or 'trash',
|
icon = 'fire',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:disposeAll', containerID, type)
|
TriggerServerEvent('disposal:server:disposeAll', containerID)
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -291,7 +214,7 @@ function confirmDestroyAll(containerID, type)
|
||||||
description = 'Zurück zum Hauptmenü',
|
description = 'Zurück zum Hauptmenü',
|
||||||
icon = 'times',
|
icon = 'times',
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
TriggerServerEvent('disposal:server:getItems', containerID, type)
|
TriggerServerEvent('disposal:server:getItems', containerID)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,9 +224,9 @@ function confirmDestroyAll(containerID, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Success notification with effect
|
-- Success notification with effect
|
||||||
RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
RegisterNetEvent('disposal:client:itemDisposed', function(message)
|
||||||
lib.notify({
|
lib.notify({
|
||||||
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
|
title = 'Müllschredder',
|
||||||
description = message,
|
description = message,
|
||||||
type = 'success',
|
type = 'success',
|
||||||
duration = 4000
|
duration = 4000
|
||||||
|
@ -320,14 +243,7 @@ RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
|
||||||
|
|
||||||
UseParticleFxAssetNextCall("core")
|
UseParticleFxAssetNextCall("core")
|
||||||
|
|
||||||
-- Different effects for shredder vs trash
|
-- Intense effect for shredder
|
||||||
if type == "shredder" then
|
StartParticleFxNonLoopedAtCoord("ent_sht_flame", coords.x, coords.y, coords.z + 1.0, 0.0, 0.0, 0.0, 1.0, false, false, false)
|
||||||
-- More intense effect for shredder
|
PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
|
||||||
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)
|
|
||||||
else
|
|
||||||
-- 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)
|
|
||||||
PlaySoundFrontend(-1, "PICK_UP", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
|
@ -1,88 +1,7 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Table to store items scheduled for deletion
|
|
||||||
local scheduledDeletions = {}
|
|
||||||
|
|
||||||
-- 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)
|
|
||||||
|
|
||||||
if not items or next(items) == nil then
|
|
||||||
print("^3[DISPOSAL]^7 No items to delete in " .. containerID)
|
|
||||||
scheduledDeletions[containerID] = nil
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local totalItems = 0
|
|
||||||
local disposedItems = {}
|
|
||||||
|
|
||||||
-- Delete all items
|
|
||||||
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
|
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Automatically deleted " .. totalItems .. " items from " .. containerID)
|
|
||||||
|
|
||||||
-- Log the automatic deletion
|
|
||||||
local itemList = ""
|
|
||||||
for _, item in pairs(disposedItems) do
|
|
||||||
itemList = itemList .. '• ' .. item.amount .. 'x ' .. item.name .. '\n'
|
|
||||||
end
|
|
||||||
|
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal', 'Automatic Trash Deletion', 'yellow',
|
|
||||||
'**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
|
|
||||||
|
|
||||||
-- Container inventory open
|
-- Container inventory open
|
||||||
RegisterNetEvent('disposal:server:openInventory', function(containerID, type)
|
RegisterNetEvent('disposal:server:openInventory', function(containerID)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
@ -92,21 +11,12 @@ 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 = 'Müllschredder'
|
||||||
})
|
})
|
||||||
|
|
||||||
-- 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
|
||||||
RegisterNetEvent('disposal:server:getItems', function(containerID, type)
|
RegisterNetEvent('disposal:server:getItems', function(containerID)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
@ -118,17 +28,11 @@ 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)
|
||||||
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
|
||||||
RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID, type)
|
RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slot, containerID)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
@ -139,44 +43,30 @@ RegisterNetEvent('disposal:server:disposeSingle', function(itemName, amount, slo
|
||||||
|
|
||||||
if success then
|
if success 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 destroyed ' .. 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 Destroyed',
|
||||||
type == "shredder" and 'orange' or 'blue',
|
'orange',
|
||||||
'**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 destroyed')
|
||||||
|
|
||||||
-- Different messages based on type
|
local message = amount .. 'x ' .. itemName .. ' wurde vernichtet!'
|
||||||
local message = ""
|
TriggerClientEvent('disposal:client:itemDisposed', src, 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)
|
||||||
else
|
else
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Fehler beim Entsorgen des Items!', 'error')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Dispose all items
|
-- Dispose all items
|
||||||
RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
RegisterNetEvent('disposal:server:disposeAll', function(containerID)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
@ -186,9 +76,7 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
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,
|
TriggerClientEvent('QBCore:Notify', src, 'Der Schredder ist bereits leer!', 'error')
|
||||||
type == "shredder" and 'Der Schredder ist bereits leer!' or 'Die Mülltonne ist bereits leer!',
|
|
||||||
'error')
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -208,8 +96,7 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
|
|
||||||
if #disposedItems > 0 then
|
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 destroyed 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 = ""
|
||||||
|
@ -218,69 +105,17 @@ RegisterNetEvent('disposal:server:disposeAll', function(containerID, type)
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
TriggerEvent('qb-log:server:CreateLog', 'disposal',
|
||||||
type == "shredder" and 'All Items Destroyed' or 'All Items Disposed',
|
'All Items Destroyed',
|
||||||
type == "shredder" and 'red' or 'green',
|
'red',
|
||||||
'**Player:** ' .. GetPlayerName(src) ..
|
'**Player:** ' .. GetPlayerName(src) ..
|
||||||
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
'\n**Citizen ID:** ' .. Player.PlayerData.citizenid ..
|
||||||
'\n**Action:** ' .. (type == "shredder" and 'All items destroyed' or 'All items disposed') ..
|
'\n**Action:** All items destroyed' ..
|
||||||
'\n**Total Items:** ' .. totalItems ..
|
'\n**Total Items:** ' .. totalItems ..
|
||||||
'\n**Items:**\n' .. itemList)
|
'\n**Items:**\n' .. itemList)
|
||||||
|
|
||||||
-- Different messages based on type
|
local message = 'ALLE Items (' .. totalItems .. ' Stück) wurden vernichtet!'
|
||||||
local message = ""
|
TriggerClientEvent('disposal:client:itemDisposed', src, 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
|
|
||||||
|
|
||||||
TriggerClientEvent('disposal:client:itemDisposed', src, message, type)
|
|
||||||
else
|
else
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, 'Keine Items zum Entsorgen gefunden!', 'error')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Save scheduled deletions when resource stops
|
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
|
||||||
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
|
|
||||||
ScheduleItemDeletion(containerID, remainingTime)
|
|
||||||
else
|
|
||||||
-- If the time has already passed, delete immediately
|
|
||||||
DeleteTrashBinItems(containerID)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
print("^3[DISPOSAL]^7 Restored " .. #savedData .. " scheduled deletions")
|
|
||||||
end)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue