forked from Simnation/Main
175 lines
5.3 KiB
Lua
175 lines
5.3 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
-- Erstelle Targets für alle Pfandautomaten
|
|
CreateThread(function()
|
|
for _, prop in pairs(Config.PfandautomatProps) do
|
|
exports['qb-target']:AddTargetModel(prop, {
|
|
options = {
|
|
{
|
|
type = "client",
|
|
event = "qb-pfandsystem:client:openPfandMenu",
|
|
icon = "fas fa-recycle",
|
|
label = "Pfand einlösen",
|
|
}
|
|
},
|
|
distance = 2.0
|
|
})
|
|
end
|
|
end)
|
|
|
|
-- Hook für Item Usage (Client-seitig)
|
|
RegisterNetEvent('tgiann-inventory:client:UseItem', function(itemName, itemData)
|
|
-- Prüfe ob das verwendete Item Pfand generiert
|
|
if Config.ConsumableItems[itemName] then
|
|
-- Informiere den Server über die Item-Nutzung
|
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
|
end
|
|
end)
|
|
|
|
-- Öffne Pfand Menu
|
|
RegisterNetEvent('qb-pfandsystem:client:openPfandMenu', function()
|
|
QBCore.Functions.TriggerCallback('qb-pfandsystem:server:getPfandItems', function(pfandItems)
|
|
if next(pfandItems) == nil then
|
|
lib.notify({
|
|
title = 'Pfandsystem',
|
|
description = Config.Locale['no_pfand_items'],
|
|
type = 'error'
|
|
})
|
|
return
|
|
end
|
|
|
|
showPfandMenu(pfandItems)
|
|
end)
|
|
end)
|
|
|
|
-- Zeige Pfand Menu
|
|
function showPfandMenu(pfandItems)
|
|
local options = {}
|
|
|
|
for itemName, itemData in pairs(pfandItems) do
|
|
local moneyString = string.format("€%.2f", itemData.totalWert / 100)
|
|
|
|
table.insert(options, {
|
|
title = itemData.label,
|
|
description = string.format("Anzahl: %d | Gesamtwert: %s", itemData.count, moneyString),
|
|
icon = 'recycle',
|
|
onSelect = function()
|
|
showQuantityInput(itemName, itemData)
|
|
end
|
|
})
|
|
end
|
|
|
|
-- Option für alle Items
|
|
table.insert(options, {
|
|
title = "Alle Pfandartikel einlösen",
|
|
description = "Löse alle verfügbaren Pfandartikel auf einmal ein",
|
|
icon = 'coins',
|
|
onSelect = function()
|
|
redeemAllItems(pfandItems)
|
|
end
|
|
})
|
|
|
|
lib.registerContext({
|
|
id = 'pfand_menu',
|
|
title = Config.Locale['pfand_menu_title'],
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('pfand_menu')
|
|
end
|
|
|
|
-- Zeige Mengenauswahl
|
|
function showQuantityInput(itemName, itemData)
|
|
local input = lib.inputDialog('Pfand einlösen', {
|
|
{
|
|
type = 'slider',
|
|
label = 'Anzahl (' .. itemData.label .. ')',
|
|
description = string.format('Verfügbar: %d | Pfandwert: €%.2f pro Stück',
|
|
itemData.count, itemData.pfandwert / 100),
|
|
required = true,
|
|
min = 1,
|
|
max = itemData.count,
|
|
default = itemData.count
|
|
}
|
|
})
|
|
|
|
if input and input[1] then
|
|
local quantity = tonumber(input[1])
|
|
if quantity and quantity > 0 and quantity <= itemData.count then
|
|
local selectedItems = {}
|
|
selectedItems[itemName] = quantity
|
|
|
|
-- Zeige Bestätigung
|
|
local totalValue = quantity * itemData.pfandwert
|
|
local moneyString = string.format("€%.2f", totalValue / 100)
|
|
|
|
local confirm = lib.alertDialog({
|
|
header = 'Pfand einlösen',
|
|
content = string.format('Möchtest du %d x %s für %s einlösen?',
|
|
quantity, itemData.label, moneyString),
|
|
centered = true,
|
|
cancel = true
|
|
})
|
|
|
|
if confirm == 'confirm' then
|
|
redeemPfand(selectedItems)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Löse alle Items ein
|
|
function redeemAllItems(pfandItems)
|
|
local selectedItems = {}
|
|
local totalValue = 0
|
|
local totalCount = 0
|
|
|
|
for itemName, itemData in pairs(pfandItems) do
|
|
selectedItems[itemName] = itemData.count
|
|
totalValue = totalValue + itemData.totalWert
|
|
totalCount = totalCount + itemData.count
|
|
end
|
|
|
|
local moneyString = string.format("€%.2f", totalValue / 100)
|
|
|
|
local confirm = lib.alertDialog({
|
|
header = 'Alle Pfandartikel einlösen',
|
|
content = string.format('Möchtest du alle %d Pfandartikel für %s einlösen?',
|
|
totalCount, moneyString),
|
|
centered = true,
|
|
cancel = true
|
|
})
|
|
|
|
if confirm == 'confirm' then
|
|
redeemPfand(selectedItems)
|
|
end
|
|
end
|
|
|
|
-- Sende Pfand zum Server
|
|
function redeemPfand(selectedItems)
|
|
lib.notify({
|
|
title = 'Pfandsystem',
|
|
description = Config.Locale['processing'],
|
|
type = 'inform'
|
|
})
|
|
|
|
TriggerServerEvent('qb-pfandsystem:server:redeemPfand', selectedItems)
|
|
end
|
|
|
|
-- Debug Befehle (nur wenn Debug aktiviert)
|
|
if Config.Debug then
|
|
RegisterCommand('pfandtest', function()
|
|
TriggerEvent('qb-pfandsystem:client:openPfandMenu')
|
|
end, false)
|
|
|
|
RegisterCommand('pfandconsume', function(source, args)
|
|
if args[1] then
|
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', args[1])
|
|
end
|
|
end, false)
|
|
end
|
|
|
|
-- Export für andere Scripts
|
|
exports('TriggerPfandConsumption', function(itemName)
|
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
|
end)
|