From 7990b4e328cdd0b623c9390325698eeb3f6b5309 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Mon, 28 Jul 2025 23:26:56 +0200 Subject: [PATCH] Update server.lua --- .../modules/pfandsystem/server.lua | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/resources/[inventory]/pickle_consumables/modules/pfandsystem/server.lua b/resources/[inventory]/pickle_consumables/modules/pfandsystem/server.lua index cb4dc999b..47d7c7c8c 100644 --- a/resources/[inventory]/pickle_consumables/modules/pfandsystem/server.lua +++ b/resources/[inventory]/pickle_consumables/modules/pfandsystem/server.lua @@ -1,8 +1,13 @@ --- modules/pfandsystem/server.lua (korrigiert) +-- modules/pfandsystem/server.lua (mit direkten QBCore-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 @@ -11,10 +16,10 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems -- Prüfe ob alle Items verfügbar sind for itemName, quantity in pairs(selectedItems) do if Config.PfandItems[itemName] then - -- Verwende Framework.HasItem statt HasItem - if not Framework.HasItem(src, itemName, quantity) then + local item = Player.Functions.GetItemByName(itemName) + if not item or item.amount < quantity then canRedeem = false - Framework.Notify(src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error") + TriggerClientEvent('QBCore:Notify', src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error") return end end @@ -24,9 +29,10 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems -- Entferne Items und berechne Pfand for itemName, quantity in pairs(selectedItems) do if Config.PfandItems[itemName] then - -- Verwende Framework.RemoveItem statt RemoveItem - local removed = Framework.RemoveItem(src, itemName, quantity) + 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 @@ -37,15 +43,15 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems if totalPfand > 0 then -- Gebe Geld if Config.PfandSystem.currency == 'cash' then - Framework.AddMoney(src, 'cash', totalPfand) + Player.Functions.AddMoney('cash', totalPfand) else - Framework.AddMoney(src, 'bank', totalPfand) + Player.Functions.AddMoney('bank', totalPfand) end -- Formatiere Geld für Anzeige local moneyString = string.format("€%.2f", totalPfand / 100) - Framework.Notify(src, string.format(_L('pfand_success'), moneyString, totalItems), "success") + TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_success'), moneyString, totalItems), "success") end end end) @@ -53,18 +59,20 @@ 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 - -- Verwende Framework.GetItemCount statt GetItemCount - local itemCount = Framework.GetItemCount(src, itemName) + local item = Player.Functions.GetItemByName(itemName) - if itemCount > 0 then + if item and item.amount > 0 then pfandItems[itemName] = { - count = itemCount, + count = item.amount, label = itemConfig.label, pfandwert = itemConfig.pfandwert, - totalWert = itemConfig.pfandwert * itemCount + totalWert = itemConfig.pfandwert * item.amount } end end @@ -77,12 +85,16 @@ AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemDa -- 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 + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return end + -- Gebe Pfand-Item - Framework.AddItem(source, itemConfig.pfandItem, 1) + Player.Functions.AddItem(itemConfig.pfandItem, 1) + TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[itemConfig.pfandItem], "add", 1) if Config.PfandSystem.showNotification then local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label - Framework.Notify(source, string.format(_L('pfand_received'), pfandLabel), "success") + TriggerClientEvent('QBCore:Notify', source, string.format(_L('pfand_received'), pfandLabel), "success") end end end)