-- modules/pfandsystem/server.lua (mit direkten tgiann-inventory Funktionen) 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 -- Verwende tgiann-inventory Export local item = exports['tgiann-inventory']:GetItem(src, itemName) if not item or item.count < 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 -- Verwende tgiann-inventory Export local removed = exports['tgiann-inventory']:RemoveItem(src, itemName, quantity) if removed then 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 pfandItems = {} for itemName, itemConfig in pairs(Config.PfandItems) do -- Verwende tgiann-inventory Export local item = exports['tgiann-inventory']:GetItem(src, itemName) if item and item.count > 0 then pfandItems[itemName] = { count = item.count, label = itemConfig.label, pfandwert = itemConfig.pfandwert, totalWert = itemConfig.pfandwert * item.count } end end return pfandItems end) -- Hook für Item-Nutzung AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemData, slot) -- 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 -- Gebe Pfand-Item mit tgiann-inventory exports['tgiann-inventory']:AddItem(source, itemConfig.pfandItem, 1) if Config.PfandSystem.showNotification then local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label TriggerClientEvent('QBCore:Notify', source, string.format(_L('pfand_received'), pfandLabel), "success") end end end)