forked from Simnation/Main
ed
This commit is contained in:
parent
c82cfea316
commit
07f27b0557
7 changed files with 150 additions and 322 deletions
|
@ -0,0 +1,89 @@
|
|||
-- modules/pfandsystem/server.lua
|
||||
|
||||
-- Pfand einlösen
|
||||
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
|
||||
local src = source
|
||||
local Player = 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
|
||||
local hasItem = HasItem(src, itemName, quantity)
|
||||
if not hasItem then
|
||||
canRedeem = false
|
||||
ShowNotification(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
|
||||
local removed = 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
|
||||
AddMoney(src, 'cash', totalPfand)
|
||||
else
|
||||
AddMoney(src, 'bank', totalPfand)
|
||||
end
|
||||
|
||||
-- Formatiere Geld für Anzeige
|
||||
local moneyString = string.format("€%.2f", totalPfand / 100)
|
||||
|
||||
ShowNotification(src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Hole verfügbare Pfand Items des Spielers
|
||||
RegisterCallback('pickle_consumables:server:getPfandItems', function(source, cb)
|
||||
local src = source
|
||||
local pfandItems = {}
|
||||
|
||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||
local itemCount = GetItemCount(src, itemName)
|
||||
|
||||
if itemCount > 0 then
|
||||
pfandItems[itemName] = {
|
||||
count = itemCount,
|
||||
label = itemConfig.label,
|
||||
pfandwert = itemConfig.pfandwert,
|
||||
totalWert = itemConfig.pfandwert * itemCount
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
cb(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
|
||||
AddItem(source, itemConfig.pfandItem, 1)
|
||||
|
||||
if Config.PfandSystem.showNotification then
|
||||
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
|
||||
ShowNotification(source, string.format(_L('pfand_received'), pfandLabel), "success")
|
||||
end
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue