249 lines
		
	
	
	
		
			7.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			249 lines
		
	
	
	
		
			7.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
local QBCore = exports['qb-core']:GetCoreObject()
 | 
						|
 | 
						|
-- List of prop models that should be targetable as shredders
 | 
						|
local shredderPropModels = {
 | 
						|
    'm23_1_prop_m31_generator_01a',
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
-- Variable to store the current entity being interacted with
 | 
						|
local currentEntity = nil
 | 
						|
 | 
						|
-- Add QB-Target to all matching props in the world
 | 
						|
Citizen.CreateThread(function()
 | 
						|
    -- Add target to shredder props
 | 
						|
    exports['qb-target']:AddTargetModel(shredderPropModels, {
 | 
						|
        options = {
 | 
						|
            {
 | 
						|
                type = "client",
 | 
						|
                event = "disposal:openInventory",
 | 
						|
                icon = "fas fa-dumpster",
 | 
						|
                label = "Müllschredder öffnen",
 | 
						|
                action = function(entity)
 | 
						|
                    currentEntity = entity
 | 
						|
                    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
 | 
						|
                    TriggerEvent('disposal:openMenu')
 | 
						|
                end,
 | 
						|
                canInteract = function()
 | 
						|
                    return true
 | 
						|
                end,
 | 
						|
            }
 | 
						|
        },
 | 
						|
        distance = 2.0
 | 
						|
    })
 | 
						|
    
 | 
						|
    print("^2[DISPOSAL]^7 Added QB-Target to " .. #shredderPropModels .. " shredder models")
 | 
						|
end)
 | 
						|
 | 
						|
-- Function to get container ID from entity
 | 
						|
function GetContainerIDFromEntity(entity)
 | 
						|
    if not entity or not DoesEntityExist(entity) then return nil end
 | 
						|
    
 | 
						|
    local model = GetEntityModel(entity)
 | 
						|
    local entityCoords = GetEntityCoords(entity)
 | 
						|
    return "shredder" .. "_" .. model .. "_" .. math.floor(entityCoords.x) .. "_" .. math.floor(entityCoords.y) .. "_" .. math.floor(entityCoords.z)
 | 
						|
end
 | 
						|
 | 
						|
-- Open container inventory
 | 
						|
RegisterNetEvent('disposal:openInventory', function()
 | 
						|
    local playerPed = PlayerPedId()
 | 
						|
    local coords = GetEntityCoords(playerPed)
 | 
						|
    
 | 
						|
    if not currentEntity or not DoesEntityExist(currentEntity) then
 | 
						|
        lib.notify({
 | 
						|
            title = 'Müllschredder',
 | 
						|
            description = 'Kein Schredder gefunden!',
 | 
						|
            type = 'error'
 | 
						|
        })
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    -- Get container ID
 | 
						|
    local containerID = GetContainerIDFromEntity(currentEntity)
 | 
						|
    if not containerID then return end
 | 
						|
    
 | 
						|
    -- Open inventory with this unique ID
 | 
						|
    TriggerServerEvent('disposal:server:openInventory', containerID)
 | 
						|
end)
 | 
						|
 | 
						|
-- Open disposal menu
 | 
						|
RegisterNetEvent('disposal:openMenu', function()
 | 
						|
    local playerPed = PlayerPedId()
 | 
						|
    local coords = GetEntityCoords(playerPed)
 | 
						|
    
 | 
						|
    if not currentEntity or not DoesEntityExist(currentEntity) then
 | 
						|
        lib.notify({
 | 
						|
            title = 'Müllschredder',
 | 
						|
            description = 'Kein Schredder gefunden!',
 | 
						|
            type = 'error'
 | 
						|
        })
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    -- Get container ID
 | 
						|
    local containerID = GetContainerIDFromEntity(currentEntity)
 | 
						|
    if not containerID then return end
 | 
						|
    
 | 
						|
    -- Get items in this container
 | 
						|
    TriggerServerEvent('disposal:server:getItems', containerID)
 | 
						|
end)
 | 
						|
 | 
						|
-- Show menu with items
 | 
						|
RegisterNetEvent('disposal:client:showMenu', function(items, containerID)
 | 
						|
    -- Make sure items is a table
 | 
						|
    items = items or {}
 | 
						|
    
 | 
						|
    -- Check if items is empty
 | 
						|
    if next(items) == nil then
 | 
						|
        lib.notify({
 | 
						|
            title = 'Müllschredder',
 | 
						|
            description = 'Der Schredder ist leer!',
 | 
						|
            type = 'error'
 | 
						|
        })
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    local menuOptions = {}
 | 
						|
    
 | 
						|
    -- All items action option
 | 
						|
    table.insert(menuOptions, {
 | 
						|
        title = '🔥 ALLE ITEMS VERNICHTEN',
 | 
						|
        description = 'Vernichtet alle Items im Schredder permanent!',
 | 
						|
        icon = 'fire',
 | 
						|
        onSelect = function()
 | 
						|
            confirmDestroyAll(containerID)
 | 
						|
        end
 | 
						|
    })
 | 
						|
    
 | 
						|
    table.insert(menuOptions, {
 | 
						|
        title = '─────────────────',
 | 
						|
        description = 'Einzelne Items:',
 | 
						|
        disabled = true
 | 
						|
    })
 | 
						|
    
 | 
						|
    -- Add individual items to menu
 | 
						|
    local hasItems = false
 | 
						|
    for slot, item in pairs(items) do
 | 
						|
        if item and item.amount and item.amount > 0 then
 | 
						|
            hasItems = true
 | 
						|
            table.insert(menuOptions, {
 | 
						|
                title = (item.label or item.name),
 | 
						|
                description = 'Anzahl: ' .. item.amount .. ' | Slot: ' .. slot,
 | 
						|
                icon = 'trash',
 | 
						|
                onSelect = function()
 | 
						|
                    confirmDestroySingle(item.name, item.amount, slot, containerID)
 | 
						|
                end
 | 
						|
            })
 | 
						|
        end
 | 
						|
    end
 | 
						|
    
 | 
						|
    if not hasItems then
 | 
						|
        lib.notify({
 | 
						|
            title = 'Müllschredder',
 | 
						|
            description = 'Der Schredder ist leer!',
 | 
						|
            type = 'error'
 | 
						|
        })
 | 
						|
        return
 | 
						|
    end
 | 
						|
    
 | 
						|
    lib.registerContext({
 | 
						|
        id = 'disposal_menu',
 | 
						|
        title = '🗑️ Müllschredder Verwaltung',
 | 
						|
        options = menuOptions
 | 
						|
    })
 | 
						|
    
 | 
						|
    lib.showContext('disposal_menu')
 | 
						|
end)
 | 
						|
 | 
						|
-- Confirm single item disposal
 | 
						|
function confirmDestroySingle(itemName, amount, slot, containerID)
 | 
						|
    lib.registerContext({
 | 
						|
        id = 'dispose_single_confirm',
 | 
						|
        title = '⚠️ Item vernichten?',
 | 
						|
        options = {
 | 
						|
            {
 | 
						|
                title = '🔥 Ja, vernichten',
 | 
						|
                description = itemName .. ' (' .. amount .. 'x) wird permanent gelöscht!',
 | 
						|
                icon = 'check',
 | 
						|
                onSelect = function()
 | 
						|
                    TriggerServerEvent('disposal:server:disposeSingle', itemName, amount, slot, containerID)
 | 
						|
                end
 | 
						|
            },
 | 
						|
            {
 | 
						|
                title = '❌ Abbrechen',
 | 
						|
                description = 'Zurück zum Hauptmenü',
 | 
						|
                icon = 'times',
 | 
						|
                onSelect = function()
 | 
						|
                    TriggerServerEvent('disposal:server:getItems', containerID)
 | 
						|
                end
 | 
						|
            }
 | 
						|
        }
 | 
						|
    })
 | 
						|
    
 | 
						|
    lib.showContext('dispose_single_confirm')
 | 
						|
end
 | 
						|
 | 
						|
-- Confirm all items disposal
 | 
						|
function confirmDestroyAll(containerID)
 | 
						|
    lib.registerContext({
 | 
						|
        id = 'dispose_all_confirm',
 | 
						|
        title = '⚠️ WARNUNG ⚠️',
 | 
						|
        options = {
 | 
						|
            {
 | 
						|
                title = '🔥 JA, ALLES VERNICHTEN',
 | 
						|
                description = 'ALLE Items im Schredder werden permanent gelöscht!',
 | 
						|
                icon = 'fire',
 | 
						|
                onSelect = function()
 | 
						|
                    TriggerServerEvent('disposal:server:disposeAll', containerID)
 | 
						|
                end
 | 
						|
            },
 | 
						|
            {
 | 
						|
                title = '❌ Abbrechen',
 | 
						|
                description = 'Zurück zum Hauptmenü',
 | 
						|
                icon = 'times',
 | 
						|
                onSelect = function()
 | 
						|
                    TriggerServerEvent('disposal:server:getItems', containerID)
 | 
						|
                end
 | 
						|
            }
 | 
						|
        }
 | 
						|
    })
 | 
						|
    
 | 
						|
    lib.showContext('dispose_all_confirm')
 | 
						|
end
 | 
						|
 | 
						|
-- Success notification with effect
 | 
						|
RegisterNetEvent('disposal:client:itemDisposed', function(message)
 | 
						|
    lib.notify({
 | 
						|
        title = 'Müllschredder',
 | 
						|
        description = message,
 | 
						|
        type = 'success',
 | 
						|
        duration = 4000
 | 
						|
    })
 | 
						|
    
 | 
						|
    -- Particle effect
 | 
						|
    local playerPed = PlayerPedId()
 | 
						|
    local coords = GetEntityCoords(playerPed)
 | 
						|
    
 | 
						|
    RequestNamedPtfxAsset("core")
 | 
						|
    while not HasNamedPtfxAssetLoaded("core") do
 | 
						|
        Wait(1)
 | 
						|
    end
 | 
						|
    
 | 
						|
    UseParticleFxAssetNextCall("core")
 | 
						|
    
 | 
						|
    -- 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)
 | 
						|
    PlaySoundFrontend(-1, "CHECKPOINT_PERFECT", "HUD_MINI_GAME_SOUNDSET", 1)
 | 
						|
end)
 |