-- modules/pfandsystem/client.lua -- 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() TriggerCallback('pickle_consumables:server:getPfandItems', function(pfandItems) if next(pfandItems) == nil then ShowNotification(_L('no_pfand_items')) return end showPfandMenu(pfandItems) end) 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 = _L("Alle Pfandartikel einlösen"), description = _L("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