forked from Simnation/Main
Update server.lua
This commit is contained in:
parent
409113546c
commit
7990b4e328
1 changed files with 28 additions and 16 deletions
|
@ -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
|
-- 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 = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
if not Player then return end
|
||||||
|
|
||||||
local totalPfand = 0
|
local totalPfand = 0
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
|
@ -11,10 +16,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
|
||||||
-- Verwende Framework.HasItem statt HasItem
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
if not Framework.HasItem(src, itemName, quantity) then
|
if not item or item.amount < quantity then
|
||||||
canRedeem = false
|
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
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -24,9 +29,10 @@ 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
|
||||||
-- Verwende Framework.RemoveItem statt RemoveItem
|
local removed = Player.Functions.RemoveItem(itemName, quantity)
|
||||||
local removed = Framework.RemoveItem(src, itemName, quantity)
|
|
||||||
if removed then
|
if removed then
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove", quantity)
|
||||||
|
|
||||||
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
||||||
totalPfand = totalPfand + pfandWert
|
totalPfand = totalPfand + pfandWert
|
||||||
totalItems = totalItems + quantity
|
totalItems = totalItems + quantity
|
||||||
|
@ -37,15 +43,15 @@ 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
|
||||||
Framework.AddMoney(src, 'cash', totalPfand)
|
Player.Functions.AddMoney('cash', totalPfand)
|
||||||
else
|
else
|
||||||
Framework.AddMoney(src, 'bank', totalPfand)
|
Player.Functions.AddMoney('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)
|
||||||
|
|
||||||
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
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -53,18 +59,20 @@ end)
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
-- Hole verfügbare Pfand Items des Spielers
|
||||||
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 Player = QBCore.Functions.GetPlayer(src)
|
||||||
local pfandItems = {}
|
local pfandItems = {}
|
||||||
|
|
||||||
|
if not Player then return pfandItems end
|
||||||
|
|
||||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||||
-- Verwende Framework.GetItemCount statt GetItemCount
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
local itemCount = Framework.GetItemCount(src, itemName)
|
|
||||||
|
|
||||||
if itemCount > 0 then
|
if item and item.amount > 0 then
|
||||||
pfandItems[itemName] = {
|
pfandItems[itemName] = {
|
||||||
count = itemCount,
|
count = item.amount,
|
||||||
label = itemConfig.label,
|
label = itemConfig.label,
|
||||||
pfandwert = itemConfig.pfandwert,
|
pfandwert = itemConfig.pfandwert,
|
||||||
totalWert = itemConfig.pfandwert * itemCount
|
totalWert = itemConfig.pfandwert * item.amount
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -77,12 +85,16 @@ AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemDa
|
||||||
-- Prüfe ob das Item ein Pfand-Item generiert
|
-- Prüfe ob das Item ein Pfand-Item generiert
|
||||||
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
|
||||||
|
local Player = QBCore.Functions.GetPlayer(source)
|
||||||
|
if not Player then return end
|
||||||
|
|
||||||
-- Gebe Pfand-Item
|
-- 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
|
if Config.PfandSystem.showNotification then
|
||||||
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
|
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
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue