1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/pickle_consumables/modules/pfandsystem/server.lua

95 lines
3.5 KiB
Lua
Raw Normal View History

2025-07-28 23:34:19 +02:00
-- modules/pfandsystem/server.lua (mit direkten tgiann-inventory Funktionen)
2025-07-28 23:26:56 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
2025-07-28 23:17:52 +02:00
-- Pfand einlösen
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
local src = source
2025-07-28 23:26:56 +02:00
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
2025-07-28 23:17:52 +02:00
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
2025-07-28 23:34:19 +02:00
-- Verwende tgiann-inventory Export
local item = exports['tgiann-inventory']:GetItem(src, itemName)
if not item or item.count < quantity then
2025-07-28 23:17:52 +02:00
canRedeem = false
2025-07-28 23:26:56 +02:00
TriggerClientEvent('QBCore:Notify', src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error")
2025-07-28 23:17:52 +02:00
return
end
end
end
if canRedeem then
-- Entferne Items und berechne Pfand
for itemName, quantity in pairs(selectedItems) do
if Config.PfandItems[itemName] then
2025-07-28 23:34:19 +02:00
-- Verwende tgiann-inventory Export
local removed = exports['tgiann-inventory']:RemoveItem(src, itemName, quantity)
2025-07-28 23:17:52 +02:00
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
2025-07-28 23:26:56 +02:00
Player.Functions.AddMoney('cash', totalPfand)
2025-07-28 23:17:52 +02:00
else
2025-07-28 23:26:56 +02:00
Player.Functions.AddMoney('bank', totalPfand)
2025-07-28 23:17:52 +02:00
end
-- Formatiere Geld für Anzeige
local moneyString = string.format("€%.2f", totalPfand / 100)
2025-07-28 23:26:56 +02:00
TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
2025-07-28 23:17:52 +02:00
end
end
end)
-- Hole verfügbare Pfand Items des Spielers
2025-07-28 23:22:32 +02:00
lib.callback.register('pickle_consumables:server:getPfandItems', function(source)
2025-07-28 23:17:52 +02:00
local src = source
local pfandItems = {}
for itemName, itemConfig in pairs(Config.PfandItems) do
2025-07-28 23:34:19 +02:00
-- Verwende tgiann-inventory Export
local item = exports['tgiann-inventory']:GetItem(src, itemName)
2025-07-28 23:17:52 +02:00
2025-07-28 23:34:19 +02:00
if item and item.count > 0 then
2025-07-28 23:17:52 +02:00
pfandItems[itemName] = {
2025-07-28 23:34:19 +02:00
count = item.count,
2025-07-28 23:17:52 +02:00
label = itemConfig.label,
pfandwert = itemConfig.pfandwert,
2025-07-28 23:34:19 +02:00
totalWert = itemConfig.pfandwert * item.count
2025-07-28 23:17:52 +02:00
}
end
end
2025-07-28 23:22:32 +02:00
return pfandItems
2025-07-28 23:17:52 +02:00
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
2025-07-28 23:34:19 +02:00
-- Gebe Pfand-Item mit tgiann-inventory
exports['tgiann-inventory']:AddItem(source, itemConfig.pfandItem, 1)
2025-07-28 23:17:52 +02:00
if Config.PfandSystem.showNotification then
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
2025-07-28 23:26:56 +02:00
TriggerClientEvent('QBCore:Notify', source, string.format(_L('pfand_received'), pfandLabel), "success")
2025-07-28 23:17:52 +02:00
end
end
end)