ed
This commit is contained in:
		
							parent
							
								
									8fbef96ae9
								
							
						
					
					
						commit
						85eb54bcbc
					
				
					 7 changed files with 322 additions and 221 deletions
				
			
		| 
						 | 
				
			
			@ -1,156 +0,0 @@
 | 
			
		|||
-- modules/pfandsystem/client.lua (korrigiert)
 | 
			
		||||
 | 
			
		||||
-- Erstelle Targets für alle Pfandautomaten
 | 
			
		||||
CreateThread(function()
 | 
			
		||||
    if not Config.PfandSystem or not Config.PfandSystem.enabled then return end
 | 
			
		||||
    
 | 
			
		||||
    for _, prop in pairs(Config.PfandautomatProps) do
 | 
			
		||||
        exports['qb-target']:AddTargetModel(prop, {
 | 
			
		||||
            options = {
 | 
			
		||||
                {
 | 
			
		||||
                    type = "client",
 | 
			
		||||
                    event = "pickle_consumables:client:openPfandMenu",
 | 
			
		||||
                    icon = "fas fa-recycle",
 | 
			
		||||
                    label = _L('pfand_menu_title'),
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            distance = 2.0
 | 
			
		||||
        })
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Öffne Pfand Menu
 | 
			
		||||
RegisterNetEvent('pickle_consumables:client:openPfandMenu', function()
 | 
			
		||||
    -- Verwende lib.callback.await statt TriggerCallback
 | 
			
		||||
    local pfandItems = lib.callback.await('pickle_consumables:server:getPfandItems', false)
 | 
			
		||||
    
 | 
			
		||||
    if not pfandItems or next(pfandItems) == nil then
 | 
			
		||||
        ShowNotification(_L('no_pfand_items'))
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    showPfandMenu(pfandItems)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Zeige Pfand Menu
 | 
			
		||||
function showPfandMenu(pfandItems)
 | 
			
		||||
    local options = {}
 | 
			
		||||
    
 | 
			
		||||
    for itemName, itemData in pairs(pfandItems) do
 | 
			
		||||
        local moneyString = string.format("€%.2f", itemData.totalWert / 100)
 | 
			
		||||
        
 | 
			
		||||
        table.insert(options, {
 | 
			
		||||
            title = itemData.label,
 | 
			
		||||
            description = string.format("Anzahl: %d | Gesamtwert: %s", itemData.count, moneyString),
 | 
			
		||||
            icon = 'recycle',
 | 
			
		||||
            onSelect = function()
 | 
			
		||||
                showQuantityInput(itemName, itemData)
 | 
			
		||||
            end
 | 
			
		||||
        })
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Option für alle Items
 | 
			
		||||
    table.insert(options, {
 | 
			
		||||
        title = "Alle Pfandartikel einlösen",
 | 
			
		||||
        description = "Löse alle verfügbaren Pfandartikel auf einmal ein",
 | 
			
		||||
        icon = 'coins',
 | 
			
		||||
        onSelect = function()
 | 
			
		||||
            redeemAllItems(pfandItems)
 | 
			
		||||
        end
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    lib.registerContext({
 | 
			
		||||
        id = 'pfand_menu',
 | 
			
		||||
        title = _L('pfand_menu_title'),
 | 
			
		||||
        options = options
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    lib.showContext('pfand_menu')
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Zeige Mengenauswahl
 | 
			
		||||
function showQuantityInput(itemName, itemData)
 | 
			
		||||
    local input = lib.inputDialog(_L('pfand_menu_title'), {
 | 
			
		||||
        {
 | 
			
		||||
            type = 'slider',
 | 
			
		||||
            label = 'Anzahl (' .. itemData.label .. ')',
 | 
			
		||||
            description = string.format('Verfügbar: %d | Pfandwert: €%.2f pro Stück', 
 | 
			
		||||
                itemData.count, itemData.pfandwert / 100),
 | 
			
		||||
            required = true,
 | 
			
		||||
            min = 1,
 | 
			
		||||
            max = itemData.count,
 | 
			
		||||
            default = itemData.count
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    if input and input[1] then
 | 
			
		||||
        local quantity = tonumber(input[1])
 | 
			
		||||
        if quantity and quantity > 0 and quantity <= itemData.count then
 | 
			
		||||
            local selectedItems = {}
 | 
			
		||||
            selectedItems[itemName] = quantity
 | 
			
		||||
            
 | 
			
		||||
            -- Zeige Bestätigung
 | 
			
		||||
            local totalValue = quantity * itemData.pfandwert
 | 
			
		||||
            local moneyString = string.format("€%.2f", totalValue / 100)
 | 
			
		||||
            
 | 
			
		||||
            local confirm = lib.alertDialog({
 | 
			
		||||
                header = _L('pfand_menu_title'),
 | 
			
		||||
                content = string.format('Möchtest du %d x %s für %s einlösen?', 
 | 
			
		||||
                    quantity, itemData.label, moneyString),
 | 
			
		||||
                centered = true,
 | 
			
		||||
                cancel = true
 | 
			
		||||
            })
 | 
			
		||||
            
 | 
			
		||||
            if confirm == 'confirm' then
 | 
			
		||||
                redeemPfand(selectedItems)
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Löse alle Items ein
 | 
			
		||||
function redeemAllItems(pfandItems)
 | 
			
		||||
    local selectedItems = {}
 | 
			
		||||
    local totalValue = 0
 | 
			
		||||
    local totalCount = 0
 | 
			
		||||
    
 | 
			
		||||
    for itemName, itemData in pairs(pfandItems) do
 | 
			
		||||
        selectedItems[itemName] = itemData.count
 | 
			
		||||
        totalValue = totalValue + itemData.totalWert
 | 
			
		||||
        totalCount = totalCount + itemData.count
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    local moneyString = string.format("€%.2f", totalValue / 100)
 | 
			
		||||
    
 | 
			
		||||
    local confirm = lib.alertDialog({
 | 
			
		||||
        header = _L('pfand_menu_title'),
 | 
			
		||||
        content = string.format('Möchtest du alle %d Pfandartikel für %s einlösen?', 
 | 
			
		||||
            totalCount, moneyString),
 | 
			
		||||
        centered = true,
 | 
			
		||||
        cancel = true
 | 
			
		||||
    })
 | 
			
		||||
    
 | 
			
		||||
    if confirm == 'confirm' then
 | 
			
		||||
        redeemPfand(selectedItems)
 | 
			
		||||
    end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Sende Pfand zum Server
 | 
			
		||||
function redeemPfand(selectedItems)
 | 
			
		||||
    ShowNotification(_L('processing'))
 | 
			
		||||
    TriggerServerEvent('pickle_consumables:server:redeemPfand', selectedItems)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- modules/pfandsystem/client.lua (zusätzlicher Code)
 | 
			
		||||
 | 
			
		||||
-- Überwache Item-Nutzung
 | 
			
		||||
RegisterNetEvent('inventory:client:UseItem')
 | 
			
		||||
AddEventHandler('inventory:client:UseItem', function(item)
 | 
			
		||||
    local itemName = type(item) == "table" and item.name or item
 | 
			
		||||
    TriggerServerEvent('pickle_consumables:server:useItem', itemName)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Überwache Pickle Consumables Item-Nutzung
 | 
			
		||||
AddEventHandler('pickle_consumables:useItem', function(itemName, slot)
 | 
			
		||||
    TriggerServerEvent('pickle_consumables:server:useItem', itemName)
 | 
			
		||||
end)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,23 +0,0 @@
 | 
			
		|||
-- modules/pfandsystem/init.lua
 | 
			
		||||
 | 
			
		||||
local QBCore = exports['qb-core']:GetCoreObject()
 | 
			
		||||
 | 
			
		||||
-- Überwache den Moment, wenn ein Item verbraucht wird
 | 
			
		||||
AddEventHandler('pickle_consumables:itemConsumed', function(source, itemName, itemData)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player then return end
 | 
			
		||||
    
 | 
			
		||||
    -- Prüfe ob das Item ein Pfand-Item generiert
 | 
			
		||||
    if itemData and itemData.pfandItem and Config.PfandItems[itemData.pfandItem] then
 | 
			
		||||
        -- Gebe Pfand-Item
 | 
			
		||||
        Player.Functions.AddItem(itemData.pfandItem, 1)
 | 
			
		||||
        TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemData.pfandItem], "add", 1)
 | 
			
		||||
        
 | 
			
		||||
        if Config.PfandSystem and Config.PfandSystem.showNotification then
 | 
			
		||||
            local pfandLabel = Config.PfandItems[itemData.pfandItem].label
 | 
			
		||||
            TriggerClientEvent('QBCore:Notify', src, 'Du hast ' .. pfandLabel .. ' erhalten!', "success")
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,126 +0,0 @@
 | 
			
		|||
-- modules/pfandsystem/server.lua (vereinfacht mit QBCore)
 | 
			
		||||
 | 
			
		||||
local QBCore = exports['qb-core']:GetCoreObject()
 | 
			
		||||
 | 
			
		||||
-- Pfand einlösen
 | 
			
		||||
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player then return end
 | 
			
		||||
    
 | 
			
		||||
    local totalPfand = 0
 | 
			
		||||
    local totalItems = 0
 | 
			
		||||
    local canRedeem = true
 | 
			
		||||
    
 | 
			
		||||
    -- Prüfe ob alle Items verfügbar sind
 | 
			
		||||
    for itemName, quantity in pairs(selectedItems) do
 | 
			
		||||
        if Config.PfandItems[itemName] then
 | 
			
		||||
            local item = Player.Functions.GetItemByName(itemName)
 | 
			
		||||
            if not item or item.amount < quantity then
 | 
			
		||||
                canRedeem = false
 | 
			
		||||
                TriggerClientEvent('QBCore:Notify', src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error")
 | 
			
		||||
                return
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    if canRedeem then
 | 
			
		||||
        -- Entferne Items und berechne Pfand
 | 
			
		||||
        for itemName, quantity in pairs(selectedItems) do
 | 
			
		||||
            if Config.PfandItems[itemName] then
 | 
			
		||||
                local removed = Player.Functions.RemoveItem(itemName, quantity)
 | 
			
		||||
                if removed then
 | 
			
		||||
                    TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove", quantity)
 | 
			
		||||
                    
 | 
			
		||||
                    local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
 | 
			
		||||
                    totalPfand = totalPfand + pfandWert
 | 
			
		||||
                    totalItems = totalItems + quantity
 | 
			
		||||
                end
 | 
			
		||||
            end
 | 
			
		||||
        end
 | 
			
		||||
        
 | 
			
		||||
        if totalPfand > 0 then
 | 
			
		||||
            -- Gebe Geld
 | 
			
		||||
            if Config.PfandSystem.currency == 'cash' then
 | 
			
		||||
                Player.Functions.AddMoney('cash', totalPfand)
 | 
			
		||||
            else
 | 
			
		||||
                Player.Functions.AddMoney('bank', totalPfand)
 | 
			
		||||
            end
 | 
			
		||||
            
 | 
			
		||||
            -- Formatiere Geld für Anzeige
 | 
			
		||||
            local moneyString = string.format("€%.2f", totalPfand / 100)
 | 
			
		||||
            
 | 
			
		||||
            TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Hole verfügbare Pfand Items des Spielers
 | 
			
		||||
lib.callback.register('pickle_consumables:server:getPfandItems', function(source)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    local pfandItems = {}
 | 
			
		||||
    
 | 
			
		||||
    if not Player then return pfandItems end
 | 
			
		||||
    
 | 
			
		||||
    for itemName, itemConfig in pairs(Config.PfandItems) do
 | 
			
		||||
        local item = Player.Functions.GetItemByName(itemName)
 | 
			
		||||
        
 | 
			
		||||
        if item and item.amount > 0 then
 | 
			
		||||
            pfandItems[itemName] = {
 | 
			
		||||
                count = item.amount,
 | 
			
		||||
                label = itemConfig.label,
 | 
			
		||||
                pfandwert = itemConfig.pfandwert,
 | 
			
		||||
                totalWert = itemConfig.pfandwert * item.amount
 | 
			
		||||
            }
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    return pfandItems
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Füge einen direkten Event-Handler für die Item-Nutzung hinzu
 | 
			
		||||
RegisterNetEvent('pickle_consumables:server:useItem')
 | 
			
		||||
AddEventHandler('pickle_consumables:server:useItem', function(itemName)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player then return end
 | 
			
		||||
    
 | 
			
		||||
    -- Prüfe ob das Item ein Pfand-Item generiert
 | 
			
		||||
    local itemConfig = Config.Items[itemName]
 | 
			
		||||
    if itemConfig and itemConfig.pfandItem and Config.PfandItems[itemConfig.pfandItem] then
 | 
			
		||||
        -- Warte kurz, damit das Item erst konsumiert wird
 | 
			
		||||
        Wait(500)
 | 
			
		||||
        
 | 
			
		||||
        -- Gebe Pfand-Item
 | 
			
		||||
        Player.Functions.AddItem(itemConfig.pfandItem, 1)
 | 
			
		||||
        TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemConfig.pfandItem], "add", 1)
 | 
			
		||||
        
 | 
			
		||||
        if Config.PfandSystem.showNotification then
 | 
			
		||||
            local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
 | 
			
		||||
            TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_received'), pfandLabel), "success")
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Überwache alle möglichen Events für Item-Nutzung
 | 
			
		||||
RegisterNetEvent('QBCore:Server:UseItem')
 | 
			
		||||
AddEventHandler('QBCore:Server:UseItem', function(item)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local itemName = type(item) == "table" and item.name or item
 | 
			
		||||
    TriggerEvent('pickle_consumables:server:useItem', itemName)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
RegisterNetEvent('inventory:server:UseItem')
 | 
			
		||||
AddEventHandler('inventory:server:UseItem', function(source, item)
 | 
			
		||||
    local itemName = type(item) == "table" and item.name or item
 | 
			
		||||
    TriggerEvent('pickle_consumables:server:useItem', itemName)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Hook für Pickle Consumables Item-Nutzung
 | 
			
		||||
AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemData, slot)
 | 
			
		||||
    TriggerEvent('pickle_consumables:server:useItem', itemName)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,41 +0,0 @@
 | 
			
		|||
-- modules/pfandsystem/shared.lua
 | 
			
		||||
 | 
			
		||||
-- Pfandautomat Props
 | 
			
		||||
Config.PfandautomatProps = {
 | 
			
		||||
    'as_rv_machine_prop',
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Pfand Items und ihre Werte (die leeren Behälter)
 | 
			
		||||
Config.PfandItems = {
 | 
			
		||||
    ['empty_bottle'] = {
 | 
			
		||||
        pfandwert = 25,  -- Pfandwert in Cent/Credits
 | 
			
		||||
        label = 'leere Flasche'
 | 
			
		||||
    },
 | 
			
		||||
    ['empty_can'] = {
 | 
			
		||||
        pfandwert = 25,
 | 
			
		||||
        label = 'leere Dose'
 | 
			
		||||
    },
 | 
			
		||||
    ['empty_glasbootle'] = {
 | 
			
		||||
        pfandwert = 25,
 | 
			
		||||
        label = 'leere Glasflasche'
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Pfand Einstellungen
 | 
			
		||||
Config.PfandSystem = {
 | 
			
		||||
    enabled = true,
 | 
			
		||||
    currency = 'cash', -- 'cash' oder 'bank'
 | 
			
		||||
    showNotification = true
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Pfand Sprache
 | 
			
		||||
if not Language[Config.Language] then Language[Config.Language] = {} end
 | 
			
		||||
 | 
			
		||||
Language[Config.Language]['pfand_menu_title'] = 'Pfandautomat'
 | 
			
		||||
Language[Config.Language]['pfand_menu_description'] = 'Pfandgut einlösen'
 | 
			
		||||
Language[Config.Language]['no_pfand_items'] = 'Du hast keine Pfandartikel bei dir!'
 | 
			
		||||
Language[Config.Language]['pfand_success'] = 'Du hast %s für %d Pfandartikel erhalten!'
 | 
			
		||||
Language[Config.Language]['pfand_error'] = 'Fehler beim Einlösen des Pfands!'
 | 
			
		||||
Language[Config.Language]['processing'] = 'Verarbeite Pfand...'
 | 
			
		||||
Language[Config.Language]['select_items'] = 'Wähle die Artikel aus, die du einlösen möchtest:'
 | 
			
		||||
Language[Config.Language]['pfand_received'] = 'Du hast %s erhalten!'
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue