1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-28 23:34:19 +02:00
parent 62cee6ee75
commit ec9ff993e4

View file

@ -1,4 +1,4 @@
-- modules/pfandsystem/server.lua (mit direkten QBCore-Funktionen)
-- modules/pfandsystem/server.lua (mit direkten tgiann-inventory Funktionen)
local QBCore = exports['qb-core']:GetCoreObject()
@ -16,8 +16,9 @@ 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
local item = Player.Functions.GetItemByName(itemName)
if not item or item.amount < quantity 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
@ -29,10 +30,9 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems
-- Entferne Items und berechne Pfand
for itemName, quantity in pairs(selectedItems) do
if Config.PfandItems[itemName] then
local removed = Player.Functions.RemoveItem(itemName, quantity)
-- Verwende tgiann-inventory Export
local removed = exports['tgiann-inventory']:RemoveItem(src, 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
@ -59,20 +59,18 @@ 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)
-- Verwende tgiann-inventory Export
local item = exports['tgiann-inventory']:GetItem(src, itemName)
if item and item.amount > 0 then
if item and item.count > 0 then
pfandItems[itemName] = {
count = item.amount,
count = item.count,
label = itemConfig.label,
pfandwert = itemConfig.pfandwert,
totalWert = itemConfig.pfandwert * item.amount
totalWert = itemConfig.pfandwert * item.count
}
end
end
@ -85,12 +83,8 @@ 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
Player.Functions.AddItem(itemConfig.pfandItem, 1)
TriggerClientEvent('inventory:client:ItemBox', source, QBCore.Shared.Items[itemConfig.pfandItem], "add", 1)
-- 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