1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/nordi_schredder/client.lua

317 lines
10 KiB
Lua
Raw Normal View History

2025-07-27 05:45:43 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-07-28 01:20:56 +02:00
-- Liste der Prop-Modelle für sofortige Schredder
2025-07-27 21:33:14 +02:00
local shredderPropModels = {
'p_secret_weapon_02',
2025-07-28 01:05:18 +02:00
'prop_bin_08a'
}
2025-07-28 01:20:56 +02:00
-- Liste der Prop-Modelle für zeitverzögerte Mülltonnen
2025-07-28 01:05:18 +02:00
local trashBinPropModels = {
2025-07-27 21:33:14 +02:00
'prop_bin_01a',
'prop_bin_03a',
'prop_bin_04a',
'prop_bin_07a',
'prop_dumpster_01a',
'prop_dumpster_02a',
'prop_dumpster_02b',
'prop_dumpster_3a'
2025-07-27 05:45:43 +02:00
}
2025-07-28 01:20:56 +02:00
-- Variable zum Speichern der aktuellen Entität
2025-07-28 01:05:18 +02:00
local currentEntity = nil
local currentType = nil
2025-07-27 21:54:10 +02:00
2025-07-28 01:20:56 +02:00
-- QB-Target zu allen passenden Props in der Welt hinzufügen
2025-07-27 05:45:43 +02:00
Citizen.CreateThread(function()
2025-07-28 01:20:56 +02:00
-- Für sofortige Schredder
2025-07-28 01:05:18 +02:00
exports['qb-target']:AddTargetModel(shredderPropModels, {
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,
2025-07-27 05:45:43 +02:00
},
2025-07-28 01:05:18 +02:00
{
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
})
2025-07-27 21:33:14 +02:00
2025-07-28 01:20:56 +02:00
-- Für zeitverzögerte Mülltonnen - nur eine Option zum Öffnen
2025-07-28 01:05:18 +02:00
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,
}
},
distance = 2.0
})
2025-07-28 01:20:56 +02:00
print("^2[DISPOSAL]^7 QB-Target zu " .. #shredderPropModels .. " Schredder-Modellen und " .. #trashBinPropModels .. " Mülltonnen-Modellen hinzugefügt")
2025-07-27 05:45:43 +02:00
end)
2025-07-28 01:20:56 +02:00
-- Funktion zum Abrufen der Container-ID aus der Entität
2025-07-28 01:05:18 +02:00
function GetContainerIDFromEntity(entity, type)
2025-07-27 21:54:10 +02:00
if not entity or not DoesEntityExist(entity) then return nil end
local model = GetEntityModel(entity)
local entityCoords = GetEntityCoords(entity)
2025-07-28 01:05:18 +02:00
return type .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
2025-07-27 21:54:10 +02:00
end
2025-07-28 01:20:56 +02:00
-- Container-Inventar öffnen
2025-07-28 01:05:18 +02:00
RegisterNetEvent('disposal:openInventory', function()
2025-07-27 05:45:43 +02:00
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
2025-07-28 01:05:18 +02:00
if not currentEntity or not DoesEntityExist(currentEntity) then
2025-07-27 05:45:43 +02:00
lib.notify({
2025-07-28 01:05:18 +02:00
title = currentType == "shredder" and 'Müllschredder' or 'Mülltonne',
description = currentType == "shredder" and 'Kein Schredder gefunden!' or 'Keine Mülltonne gefunden!',
2025-07-27 05:45:43 +02:00
type = 'error'
})
return
end
2025-07-28 01:20:56 +02:00
-- Container-ID abrufen
2025-07-28 01:05:18 +02:00
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
if not containerID then return end
2025-07-27 21:33:14 +02:00
2025-07-28 01:20:56 +02:00
-- Inventar mit dieser eindeutigen ID öffnen
2025-07-28 01:05:18 +02:00
TriggerServerEvent('disposal:server:openInventory', containerID, currentType)
2025-07-27 05:45:43 +02:00
end)
2025-07-28 01:20:56 +02:00
-- Vernichtungsmenü öffnen (nur für Schredder)
2025-07-28 01:05:18 +02:00
RegisterNetEvent('disposal:openMenu', function()
2025-07-27 05:45:43 +02:00
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
2025-07-28 01:20:56 +02:00
if not currentEntity or not DoesEntityExist(currentEntity) or currentType ~= "shredder" then
2025-07-27 05:45:43 +02:00
lib.notify({
2025-07-28 01:20:56 +02:00
title = 'Müllschredder',
description = 'Kein Schredder gefunden!',
2025-07-27 05:45:43 +02:00
type = 'error'
})
return
end
2025-07-28 01:20:56 +02:00
-- Container-ID abrufen
2025-07-28 01:05:18 +02:00
local containerID = GetContainerIDFromEntity(currentEntity, currentType)
if not containerID then return end
2025-07-27 21:33:14 +02:00
2025-07-28 01:20:56 +02:00
-- Items in diesem Container abrufen
2025-07-28 01:05:18 +02:00
TriggerServerEvent('disposal:server:getItems', containerID, currentType)
2025-07-27 05:45:43 +02:00
end)
2025-07-28 01:20:56 +02:00
-- Menü mit Items anzeigen (nur für Schredder)
2025-07-28 01:05:18 +02:00
RegisterNetEvent('disposal:client:showMenu', function(items, containerID, type, timeRemaining)
2025-07-28 01:20:56 +02:00
-- Nur für Schredder fortfahren
if type ~= "shredder" then return end
-- Sicherstellen, dass items eine Tabelle ist
2025-07-27 22:17:12 +02:00
items = items or {}
2025-07-28 01:20:56 +02:00
-- Prüfen, ob items leer ist
2025-07-27 22:17:12 +02:00
if next(items) == nil then
2025-07-27 05:45:43 +02:00
lib.notify({
2025-07-28 01:20:56 +02:00
title = 'Müllschredder',
description = 'Der Schredder ist leer!',
2025-07-27 05:45:43 +02:00
type = 'error'
})
return
end
local menuOptions = {}
2025-07-28 01:20:56 +02:00
-- Alle Items vernichten Option
2025-07-27 05:45:43 +02:00
table.insert(menuOptions, {
2025-07-28 01:20:56 +02:00
title = '🔥 ALLE ITEMS VERNICHTEN',
description = 'Vernichtet alle Items im Schredder permanent!',
icon = 'fire',
2025-07-27 05:45:43 +02:00
onSelect = function()
2025-07-28 01:20:56 +02:00
confirmDestroyAll(containerID)
2025-07-27 05:45:43 +02:00
end
})
table.insert(menuOptions, {
title = '─────────────────',
description = 'Einzelne Items:',
disabled = true
})
2025-07-28 01:20:56 +02:00
-- Einzelne Items zum Menü hinzufügen
2025-07-27 22:17:12 +02:00
local hasItems = false
2025-07-27 05:45:43 +02:00
for slot, item in pairs(items) do
if item and item.amount and item.amount > 0 then
2025-07-27 22:17:12 +02:00
hasItems = true
2025-07-27 05:45:43 +02:00
table.insert(menuOptions, {
title = (item.label or item.name),
description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
icon = 'trash',
onSelect = function()
2025-07-28 01:20:56 +02:00
confirmDestroySingle(item.name, item.amount, slot, containerID)
2025-07-27 05:45:43 +02:00
end
})
end
end
2025-07-27 22:17:12 +02:00
if not hasItems then
lib.notify({
2025-07-28 01:20:56 +02:00
title = 'Müllschredder',
description = 'Der Schredder ist leer!',
2025-07-27 22:17:12 +02:00
type = 'error'
})
return
end
2025-07-27 05:45:43 +02:00
lib.registerContext({
2025-07-28 01:05:18 +02:00
id = 'disposal_menu',
2025-07-28 01:20:56 +02:00
title = '🗑️ Müllschredder Verwaltung',
2025-07-27 05:45:43 +02:00
options = menuOptions
})
2025-07-28 01:05:18 +02:00
lib.showContext('disposal_menu')
2025-07-27 05:45:43 +02:00
end)
2025-07-28 01:20:56 +02:00
-- Einzelnes Item vernichten bestätigen (nur für Schredder)
function confirmDestroySingle(itemName, amount, slot, containerID)
2025-07-27 05:45:43 +02:00
lib.registerContext({
2025-07-28 01:05:18 +02:00
id = 'dispose_single_confirm',
2025-07-28 01:20:56 +02:00
title = '⚠️ Item vernichten?',
2025-07-27 05:45:43 +02:00
options = {
{
2025-07-28 01:20:56 +02:00
title = '🔥 Ja, vernichten',
description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
icon = 'fire',
2025-07-27 05:45:43 +02:00
onSelect = function()
2025-07-28 01:20:56 +02:00
TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID, "shredder")
2025-07-27 05:45:43 +02:00
end
},
{
title = '❌ Abbrechen',
description = 'Zurück zum Hauptmenü',
icon = 'times',
onSelect = function()
2025-07-28 01:20:56 +02:00
TriggerServerEvent('disposal:server:getItems', containerID, "shredder")
2025-07-27 05:45:43 +02:00
end
}
}
})
2025-07-28 01:05:18 +02:00
lib.showContext('dispose_single_confirm')
2025-07-27 05:45:43 +02:00
end
2025-07-28 01:20:56 +02:00
-- Alle Items vernichten bestätigen (nur für Schredder)
function confirmDestroyAll(containerID)
2025-07-27 05:45:43 +02:00
lib.registerContext({
2025-07-28 01:05:18 +02:00
id = 'dispose_all_confirm',
2025-07-27 05:45:43 +02:00
title = '⚠️ WARNUNG ⚠️',
options = {
{
2025-07-28 01:20:56 +02:00
title = '🔥 JA, ALLES VERNICHTEN',
description = 'ALLE Items im Schredder werden permanent gelöscht!',
icon = 'fire',
2025-07-27 05:45:43 +02:00
onSelect = function()
2025-07-28 01:20:56 +02:00
TriggerServerEvent('disposal:server:disposeAll', containerID, "shredder")
2025-07-27 05:45:43 +02:00
end
},
{
title = '❌ Abbrechen',
description = 'Zurück zum Hauptmenü',
icon = 'times',
onSelect = function()
2025-07-28 01:20:56 +02:00
TriggerServerEvent('disposal:server:getItems', containerID, "shredder")
2025-07-27 05:45:43 +02:00
end
}
}
})
2025-07-28 01:05:18 +02:00
lib.showContext('dispose_all_confirm')
2025-07-27 05:45:43 +02:00
end
2025-07-28 01:20:56 +02:00
-- Erfolgs-Notification mit Effekt
2025-07-28 01:05:18 +02:00
RegisterNetEvent('disposal:client:itemDisposed', function(message, type)
2025-07-27 05:45:43 +02:00
lib.notify({
2025-07-28 01:05:18 +02:00
title = type == "shredder" and 'Müllschredder' or 'Mülltonne',
2025-07-27 05:45:43 +02:00
description = message,
type = 'success',
duration = 4000
})
2025-07-28 01:20:56 +02:00
-- Partikel-Effekt
2025-07-27 05:45:43 +02:00
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
RequestNamedPtfxAsset("core")
while not HasNamedPtfxAssetLoaded("core") do
Wait(1)
end
UseParticleFxAssetNextCall("core")
2025-07-28 01:20:56 +02:00
-- Unterschiedliche Effekte je nach Typ
2025-07-28 01:05:18 +02:00
if type == "shredder" then
2025-07-28 01:20:56 +02:00
-- Intensiverer Effekt für Schredder
2025-07-28 01:05:18 +02:00
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
2025-07-28 01:20:56 +02:00
-- Subtiler Effekt für Mülltonnen
2025-07-28 01:05:18 +02:00
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
2025-07-27 05:45:43 +02:00
end)
2025-07-28 01:20:56 +02:00
-- 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)