forked from Simnation/Main
Update server.lua
This commit is contained in:
parent
60edd2237a
commit
409113546c
1 changed files with 12 additions and 14 deletions
|
@ -3,9 +3,6 @@
|
||||||
-- Pfand einlösen
|
-- Pfand einlösen
|
||||||
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
|
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = GetPlayer(src)
|
|
||||||
|
|
||||||
if not Player then return end
|
|
||||||
|
|
||||||
local totalPfand = 0
|
local totalPfand = 0
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
|
@ -14,10 +11,10 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems
|
||||||
-- Prüfe ob alle Items verfügbar sind
|
-- Prüfe ob alle Items verfügbar sind
|
||||||
for itemName, quantity in pairs(selectedItems) do
|
for itemName, quantity in pairs(selectedItems) do
|
||||||
if Config.PfandItems[itemName] then
|
if Config.PfandItems[itemName] then
|
||||||
local hasItem = HasItem(src, itemName, quantity)
|
-- Verwende Framework.HasItem statt HasItem
|
||||||
if not hasItem then
|
if not Framework.HasItem(src, itemName, quantity) then
|
||||||
canRedeem = false
|
canRedeem = false
|
||||||
ShowNotification(src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error")
|
Framework.Notify(src, 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName), "error")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -27,7 +24,8 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems
|
||||||
-- Entferne Items und berechne Pfand
|
-- Entferne Items und berechne Pfand
|
||||||
for itemName, quantity in pairs(selectedItems) do
|
for itemName, quantity in pairs(selectedItems) do
|
||||||
if Config.PfandItems[itemName] then
|
if Config.PfandItems[itemName] then
|
||||||
local removed = RemoveItem(src, itemName, quantity)
|
-- Verwende Framework.RemoveItem statt RemoveItem
|
||||||
|
local removed = Framework.RemoveItem(src, itemName, quantity)
|
||||||
if removed then
|
if removed then
|
||||||
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
||||||
totalPfand = totalPfand + pfandWert
|
totalPfand = totalPfand + pfandWert
|
||||||
|
@ -39,27 +37,27 @@ RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems
|
||||||
if totalPfand > 0 then
|
if totalPfand > 0 then
|
||||||
-- Gebe Geld
|
-- Gebe Geld
|
||||||
if Config.PfandSystem.currency == 'cash' then
|
if Config.PfandSystem.currency == 'cash' then
|
||||||
AddMoney(src, 'cash', totalPfand)
|
Framework.AddMoney(src, 'cash', totalPfand)
|
||||||
else
|
else
|
||||||
AddMoney(src, 'bank', totalPfand)
|
Framework.AddMoney(src, 'bank', totalPfand)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Formatiere Geld für Anzeige
|
-- Formatiere Geld für Anzeige
|
||||||
local moneyString = string.format("€%.2f", totalPfand / 100)
|
local moneyString = string.format("€%.2f", totalPfand / 100)
|
||||||
|
|
||||||
ShowNotification(src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
|
Framework.Notify(src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
-- Hole verfügbare Pfand Items des Spielers
|
||||||
-- Verwende lib.callback.register statt RegisterCallback
|
|
||||||
lib.callback.register('pickle_consumables:server:getPfandItems', function(source)
|
lib.callback.register('pickle_consumables:server:getPfandItems', function(source)
|
||||||
local src = source
|
local src = source
|
||||||
local pfandItems = {}
|
local pfandItems = {}
|
||||||
|
|
||||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||||
local itemCount = GetItemCount(src, itemName)
|
-- Verwende Framework.GetItemCount statt GetItemCount
|
||||||
|
local itemCount = Framework.GetItemCount(src, itemName)
|
||||||
|
|
||||||
if itemCount > 0 then
|
if itemCount > 0 then
|
||||||
pfandItems[itemName] = {
|
pfandItems[itemName] = {
|
||||||
|
@ -80,11 +78,11 @@ AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemDa
|
||||||
local itemConfig = Config.Items[itemName]
|
local itemConfig = Config.Items[itemName]
|
||||||
if itemConfig and itemConfig.pfandItem and Config.PfandItems[itemConfig.pfandItem] then
|
if itemConfig and itemConfig.pfandItem and Config.PfandItems[itemConfig.pfandItem] then
|
||||||
-- Gebe Pfand-Item
|
-- Gebe Pfand-Item
|
||||||
AddItem(source, itemConfig.pfandItem, 1)
|
Framework.AddItem(source, itemConfig.pfandItem, 1)
|
||||||
|
|
||||||
if Config.PfandSystem.showNotification then
|
if Config.PfandSystem.showNotification then
|
||||||
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
|
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
|
||||||
ShowNotification(source, string.format(_L('pfand_received'), pfandLabel), "success")
|
Framework.Notify(source, string.format(_L('pfand_received'), pfandLabel), "success")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue