forked from Simnation/Main
ed
This commit is contained in:
parent
8fbef96ae9
commit
85eb54bcbc
7 changed files with 322 additions and 221 deletions
|
@ -1,17 +1,15 @@
|
||||||
-- modules/pfandsystem/client.lua (korrigiert)
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Erstelle Targets für alle Pfandautomaten
|
-- Erstelle Targets für alle Pfandautomaten
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
if not Config.PfandSystem or not Config.PfandSystem.enabled then return end
|
|
||||||
|
|
||||||
for _, prop in pairs(Config.PfandautomatProps) do
|
for _, prop in pairs(Config.PfandautomatProps) do
|
||||||
exports['qb-target']:AddTargetModel(prop, {
|
exports['qb-target']:AddTargetModel(prop, {
|
||||||
options = {
|
options = {
|
||||||
{
|
{
|
||||||
type = "client",
|
type = "client",
|
||||||
event = "pickle_consumables:client:openPfandMenu",
|
event = "qb-pfandsystem:client:openPfandMenu",
|
||||||
icon = "fas fa-recycle",
|
icon = "fas fa-recycle",
|
||||||
label = _L('pfand_menu_title'),
|
label = "Pfand einlösen",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
distance = 2.0
|
distance = 2.0
|
||||||
|
@ -19,18 +17,37 @@ CreateThread(function()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Öffne Pfand Menu
|
-- Registriere Event für Item-Nutzung (wichtig: das ist der korrekte Event für tgiann-inventory)
|
||||||
RegisterNetEvent('pickle_consumables:client:openPfandMenu', function()
|
RegisterNetEvent('inventory:client:UseItem')
|
||||||
-- Verwende lib.callback.await statt TriggerCallback
|
AddEventHandler('inventory:client:UseItem', function(item)
|
||||||
local pfandItems = lib.callback.await('pickle_consumables:server:getPfandItems', false)
|
local itemName = item.name
|
||||||
|
|
||||||
if not pfandItems or next(pfandItems) == nil then
|
-- Prüfe ob das verwendete Item Pfand generiert
|
||||||
ShowNotification(_L('no_pfand_items'))
|
if Config.ConsumableItems[itemName] then
|
||||||
|
-- Informiere den Server über die Item-Nutzung
|
||||||
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
|
||||||
|
if Config.Debug then
|
||||||
|
print('[Pfandsystem] Item verwendet: ' .. itemName)
|
||||||
|
end
|
||||||
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
showPfandMenu(pfandItems)
|
showPfandMenu(pfandItems)
|
||||||
end)
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
-- Zeige Pfand Menu
|
-- Zeige Pfand Menu
|
||||||
function showPfandMenu(pfandItems)
|
function showPfandMenu(pfandItems)
|
||||||
|
@ -61,7 +78,7 @@ function showPfandMenu(pfandItems)
|
||||||
|
|
||||||
lib.registerContext({
|
lib.registerContext({
|
||||||
id = 'pfand_menu',
|
id = 'pfand_menu',
|
||||||
title = _L('pfand_menu_title'),
|
title = Config.Locale['pfand_menu_title'],
|
||||||
options = options
|
options = options
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -70,7 +87,7 @@ end
|
||||||
|
|
||||||
-- Zeige Mengenauswahl
|
-- Zeige Mengenauswahl
|
||||||
function showQuantityInput(itemName, itemData)
|
function showQuantityInput(itemName, itemData)
|
||||||
local input = lib.inputDialog(_L('pfand_menu_title'), {
|
local input = lib.inputDialog('Pfand einlösen', {
|
||||||
{
|
{
|
||||||
type = 'slider',
|
type = 'slider',
|
||||||
label = 'Anzahl (' .. itemData.label .. ')',
|
label = 'Anzahl (' .. itemData.label .. ')',
|
||||||
|
@ -94,7 +111,7 @@ function showQuantityInput(itemName, itemData)
|
||||||
local moneyString = string.format("€%.2f", totalValue / 100)
|
local moneyString = string.format("€%.2f", totalValue / 100)
|
||||||
|
|
||||||
local confirm = lib.alertDialog({
|
local confirm = lib.alertDialog({
|
||||||
header = _L('pfand_menu_title'),
|
header = 'Pfand einlösen',
|
||||||
content = string.format('Möchtest du %d x %s für %s einlösen?',
|
content = string.format('Möchtest du %d x %s für %s einlösen?',
|
||||||
quantity, itemData.label, moneyString),
|
quantity, itemData.label, moneyString),
|
||||||
centered = true,
|
centered = true,
|
||||||
|
@ -123,7 +140,7 @@ function redeemAllItems(pfandItems)
|
||||||
local moneyString = string.format("€%.2f", totalValue / 100)
|
local moneyString = string.format("€%.2f", totalValue / 100)
|
||||||
|
|
||||||
local confirm = lib.alertDialog({
|
local confirm = lib.alertDialog({
|
||||||
header = _L('pfand_menu_title'),
|
header = 'Alle Pfandartikel einlösen',
|
||||||
content = string.format('Möchtest du alle %d Pfandartikel für %s einlösen?',
|
content = string.format('Möchtest du alle %d Pfandartikel für %s einlösen?',
|
||||||
totalCount, moneyString),
|
totalCount, moneyString),
|
||||||
centered = true,
|
centered = true,
|
||||||
|
@ -137,20 +154,29 @@ end
|
||||||
|
|
||||||
-- Sende Pfand zum Server
|
-- Sende Pfand zum Server
|
||||||
function redeemPfand(selectedItems)
|
function redeemPfand(selectedItems)
|
||||||
ShowNotification(_L('processing'))
|
lib.notify({
|
||||||
TriggerServerEvent('pickle_consumables:server:redeemPfand', selectedItems)
|
title = 'Pfandsystem',
|
||||||
|
description = Config.Locale['processing'],
|
||||||
|
type = 'inform'
|
||||||
|
})
|
||||||
|
|
||||||
|
TriggerServerEvent('qb-pfandsystem:server:redeemPfand', selectedItems)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- modules/pfandsystem/client.lua (zusätzlicher Code)
|
-- Debug Befehle (nur wenn Debug aktiviert)
|
||||||
|
if Config.Debug then
|
||||||
|
RegisterCommand('pfandtest', function()
|
||||||
|
TriggerEvent('qb-pfandsystem:client:openPfandMenu')
|
||||||
|
end, false)
|
||||||
|
|
||||||
-- Überwache Item-Nutzung
|
RegisterCommand('pfandconsume', function(source, args)
|
||||||
RegisterNetEvent('inventory:client:UseItem')
|
if args[1] then
|
||||||
AddEventHandler('inventory:client:UseItem', function(item)
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', args[1])
|
||||||
local itemName = type(item) == "table" and item.name or item
|
end
|
||||||
TriggerServerEvent('pickle_consumables:server:useItem', itemName)
|
end, false)
|
||||||
end)
|
end
|
||||||
|
|
||||||
-- Überwache Pickle Consumables Item-Nutzung
|
-- Export für andere Scripts
|
||||||
AddEventHandler('pickle_consumables:useItem', function(itemName, slot)
|
exports('TriggerPfandConsumption', function(itemName)
|
||||||
TriggerServerEvent('pickle_consumables:server:useItem', itemName)
|
TriggerServerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
end)
|
end)
|
62
resources/[inventory]/nordi_pfand/config.lua
Normal file
62
resources/[inventory]/nordi_pfand/config.lua
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
Config = {}
|
||||||
|
|
||||||
|
-- Pfandautomat Props
|
||||||
|
Config.PfandautomatProps = {
|
||||||
|
'as_rv_machine_prop',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Konsumierbare Items die Pfand generieren
|
||||||
|
Config.ConsumableItems = {
|
||||||
|
['beer'] = {
|
||||||
|
pfandItem = 'empty_glasbootle',
|
||||||
|
label = 'Bier'
|
||||||
|
},
|
||||||
|
['water_bottle'] = {
|
||||||
|
pfandItem = 'empty_bottle',
|
||||||
|
label = 'Wasserflasche'
|
||||||
|
},
|
||||||
|
['ecola_dose'] = {
|
||||||
|
pfandItem = 'soda_can',
|
||||||
|
label = 'Cola'
|
||||||
|
},
|
||||||
|
['sprunk_dose'] = {
|
||||||
|
pfandItem = 'soda_can',
|
||||||
|
label = 'Sprite'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Pfand Items und ihre Werte (die leeren Behälter)
|
||||||
|
Config.PfandItems = {
|
||||||
|
['empty_bottle'] = {
|
||||||
|
pfandwert = 25, -- Pfandwert in Cent/Credits
|
||||||
|
label = 'leere Flasche'
|
||||||
|
},
|
||||||
|
['empty_can'] = {
|
||||||
|
pfandwert = 25,
|
||||||
|
label = 'leere Dose'
|
||||||
|
},
|
||||||
|
['empty_glasbootle'] = {
|
||||||
|
pfandwert = 25,
|
||||||
|
label = 'leere Glasflasche'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Allgemeine Einstellungen
|
||||||
|
Config.Currency = 'cash' -- 'cash' oder 'bank'
|
||||||
|
Config.Debug = true
|
||||||
|
Config.ShowPfandNotification = true -- Zeige Benachrichtigung wenn Pfand erhalten wird
|
||||||
|
|
||||||
|
-- Sprache
|
||||||
|
Config.Locale = {
|
||||||
|
['pfand_menu_title'] = 'Pfandautomat',
|
||||||
|
['pfand_menu_description'] = 'Pfandgut einlösen',
|
||||||
|
['no_pfand_items'] = 'Du hast keine Pfandartikel bei dir!',
|
||||||
|
['pfand_success'] = 'Du hast %s für %d Pfandartikel erhalten!',
|
||||||
|
['pfand_error'] = 'Fehler beim Einlösen des Pfands!',
|
||||||
|
['processing'] = 'Verarbeite Pfand...',
|
||||||
|
['select_items'] = 'Wähle die Artikel aus, die du einlösen möchtest:',
|
||||||
|
['pfand_received'] = 'Du hast %s erhalten!',
|
||||||
|
|
||||||
|
}
|
27
resources/[inventory]/nordi_pfand/fxmanifest.lua
Normal file
27
resources/[inventory]/nordi_pfand/fxmanifest.lua
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
fx_version 'cerulean'
|
||||||
|
game 'gta5'
|
||||||
|
lua54 'yes'
|
||||||
|
|
||||||
|
author 'YourName'
|
||||||
|
description 'Pfandsystem für QBCore'
|
||||||
|
version '1.0.0'
|
||||||
|
|
||||||
|
shared_scripts {
|
||||||
|
'@ox_lib/init.lua',
|
||||||
|
'config.lua'
|
||||||
|
}
|
||||||
|
|
||||||
|
client_scripts {
|
||||||
|
'client/main.lua'
|
||||||
|
}
|
||||||
|
|
||||||
|
server_scripts {
|
||||||
|
'server/main.lua'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
'qb-core',
|
||||||
|
'qb-target',
|
||||||
|
'tgiann-inventory',
|
||||||
|
'ox_lib'
|
||||||
|
}
|
176
resources/[inventory]/nordi_pfand/server/main.lua
Normal file
176
resources/[inventory]/nordi_pfand/server/main.lua
Normal file
|
@ -0,0 +1,176 @@
|
||||||
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
|
-- Event wenn ein Item konsumiert wird
|
||||||
|
RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
|
local src = source
|
||||||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
if not Player then return end
|
||||||
|
|
||||||
|
-- Prüfe ob das konsumierte Item Pfand generiert
|
||||||
|
if Config.ConsumableItems[itemName] then
|
||||||
|
local consumableConfig = Config.ConsumableItems[itemName]
|
||||||
|
local pfandItem = consumableConfig.pfandItem
|
||||||
|
|
||||||
|
-- Warte kurz damit das originale Item erst konsumiert wird
|
||||||
|
Wait(500)
|
||||||
|
|
||||||
|
-- Verwende Player.Functions.AddItem
|
||||||
|
local success = Player.Functions.AddItem(pfandItem, 1)
|
||||||
|
|
||||||
|
if success then
|
||||||
|
-- Trigger inventory update
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[pfandItem], "add", 1)
|
||||||
|
|
||||||
|
if Config.ShowPfandNotification then
|
||||||
|
local pfandLabel = Config.PfandItems[pfandItem] and Config.PfandItems[pfandItem].label or pfandItem
|
||||||
|
|
||||||
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
|
title = 'Pfandsystem',
|
||||||
|
description = string.format(Config.Locale['pfand_received'], pfandLabel),
|
||||||
|
type = 'success',
|
||||||
|
duration = 3000
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if Config.Debug then
|
||||||
|
print(string.format('[Pfandsystem] Spieler %s hat %s konsumiert und %s erhalten',
|
||||||
|
Player.PlayerData.name, itemName, pfandItem))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if Config.Debug then
|
||||||
|
print(string.format('[Pfandsystem] Fehler beim Hinzufügen von %s für Spieler %s', pfandItem, Player.PlayerData.name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Pfand einlösen
|
||||||
|
RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
|
local src = source
|
||||||
|
local Player = QBCore.Functions.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 item = Player.Functions.GetItemByName(itemName)
|
||||||
|
if not item or item.amount < quantity then
|
||||||
|
canRedeem = false
|
||||||
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
|
title = 'Pfandsystem',
|
||||||
|
description = 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName),
|
||||||
|
type = '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 = Player.Functions.RemoveItem(itemName, quantity)
|
||||||
|
if removed then
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove", quantity)
|
||||||
|
|
||||||
|
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
||||||
|
totalPfand = totalPfand + pfandWert
|
||||||
|
totalItems = totalItems + quantity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if totalPfand > 0 then
|
||||||
|
-- Gebe Geld
|
||||||
|
if Config.Currency == 'cash' then
|
||||||
|
Player.Functions.AddMoney('cash', totalPfand)
|
||||||
|
else
|
||||||
|
Player.Functions.AddMoney('bank', totalPfand)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Formatiere Geld für Anzeige
|
||||||
|
local moneyString = string.format("€%.2f", totalPfand / 100)
|
||||||
|
|
||||||
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
|
title = 'Pfandsystem',
|
||||||
|
description = string.format(Config.Locale['pfand_success'], moneyString, totalItems),
|
||||||
|
type = 'success'
|
||||||
|
})
|
||||||
|
|
||||||
|
if Config.Debug then
|
||||||
|
print(string.format('[Pfandsystem] Spieler %s hat %d Items für €%.2f eingelöst',
|
||||||
|
Player.PlayerData.name, totalItems, totalPfand / 100))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Hole verfügbare Pfand Items des Spielers
|
||||||
|
QBCore.Functions.CreateCallback('qb-pfandsystem:server:getPfandItems', function(source, cb)
|
||||||
|
local src = source
|
||||||
|
local pfandItems = {}
|
||||||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
|
if not Player then
|
||||||
|
cb(pfandItems)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||||
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
|
|
||||||
|
if item and item.amount > 0 then
|
||||||
|
pfandItems[itemName] = {
|
||||||
|
count = item.amount,
|
||||||
|
label = itemConfig.label,
|
||||||
|
pfandwert = itemConfig.pfandwert,
|
||||||
|
totalWert = itemConfig.pfandwert * item.amount
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
cb(pfandItems)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Zusätzliche Event-Handler für verschiedene Inventarsysteme
|
||||||
|
RegisterNetEvent('inventory:server:UseItem')
|
||||||
|
AddEventHandler('inventory:server:UseItem', function(source, item)
|
||||||
|
local itemName = type(item) == "table" and item.name or item
|
||||||
|
|
||||||
|
if Config.ConsumableItems[itemName] then
|
||||||
|
SetTimeout(100, function()
|
||||||
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Für tgiann-inventory
|
||||||
|
RegisterNetEvent('tgiann-inventory:itemUsed')
|
||||||
|
AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName)
|
||||||
|
if Config.ConsumableItems[itemName] then
|
||||||
|
SetTimeout(100, function()
|
||||||
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Debug-Befehl zum manuellen Auslösen
|
||||||
|
RegisterCommand('pfanditem', function(source, args)
|
||||||
|
if Config.Debug then
|
||||||
|
if args[1] and source > 0 then
|
||||||
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', args[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Export für andere Scripts
|
||||||
|
exports('ConsumePfandItem', function(source, itemName)
|
||||||
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
end)
|
|
@ -1,23 +0,0 @@
|
||||||
-- modules/pfandsystem/init.lua
|
|
||||||
|
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
|
|
||||||
-- Überwache den Moment, wenn ein Item verbraucht wird
|
|
||||||
AddEventHandler('pickle_consumables:itemConsumed', function(source, itemName, itemData)
|
|
||||||
local src = source
|
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
|
||||||
|
|
||||||
if not Player then return end
|
|
||||||
|
|
||||||
-- Prüfe ob das Item ein Pfand-Item generiert
|
|
||||||
if itemData and itemData.pfandItem and Config.PfandItems[itemData.pfandItem] then
|
|
||||||
-- Gebe Pfand-Item
|
|
||||||
Player.Functions.AddItem(itemData.pfandItem, 1)
|
|
||||||
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemData.pfandItem], "add", 1)
|
|
||||||
|
|
||||||
if Config.PfandSystem and Config.PfandSystem.showNotification then
|
|
||||||
local pfandLabel = Config.PfandItems[itemData.pfandItem].label
|
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Du hast ' .. pfandLabel .. ' erhalten!', "success")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
|
@ -1,126 +0,0 @@
|
||||||
-- modules/pfandsystem/server.lua (vereinfacht mit QBCore)
|
|
||||||
|
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
|
||||||
|
|
||||||
-- Pfand einlösen
|
|
||||||
RegisterNetEvent('pickle_consumables:server:redeemPfand', function(selectedItems)
|
|
||||||
local src = source
|
|
||||||
local Player = QBCore.Functions.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 item = Player.Functions.GetItemByName(itemName)
|
|
||||||
if not item or item.amount < quantity then
|
|
||||||
canRedeem = false
|
|
||||||
TriggerClientEvent('QBCore:Notify', 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 = Player.Functions.RemoveItem(itemName, quantity)
|
|
||||||
if removed then
|
|
||||||
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove", quantity)
|
|
||||||
|
|
||||||
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
|
|
||||||
Player.Functions.AddMoney('cash', totalPfand)
|
|
||||||
else
|
|
||||||
Player.Functions.AddMoney('bank', totalPfand)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Formatiere Geld für Anzeige
|
|
||||||
local moneyString = string.format("€%.2f", totalPfand / 100)
|
|
||||||
|
|
||||||
TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_success'), moneyString, totalItems), "success")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
|
||||||
lib.callback.register('pickle_consumables:server:getPfandItems', function(source)
|
|
||||||
local src = source
|
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
|
||||||
local pfandItems = {}
|
|
||||||
|
|
||||||
if not Player then return pfandItems end
|
|
||||||
|
|
||||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
|
||||||
local item = Player.Functions.GetItemByName(itemName)
|
|
||||||
|
|
||||||
if item and item.amount > 0 then
|
|
||||||
pfandItems[itemName] = {
|
|
||||||
count = item.amount,
|
|
||||||
label = itemConfig.label,
|
|
||||||
pfandwert = itemConfig.pfandwert,
|
|
||||||
totalWert = itemConfig.pfandwert * item.amount
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return pfandItems
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Füge einen direkten Event-Handler für die Item-Nutzung hinzu
|
|
||||||
RegisterNetEvent('pickle_consumables:server:useItem')
|
|
||||||
AddEventHandler('pickle_consumables:server:useItem', function(itemName)
|
|
||||||
local src = source
|
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
|
||||||
|
|
||||||
if not Player then return end
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
-- Warte kurz, damit das Item erst konsumiert wird
|
|
||||||
Wait(500)
|
|
||||||
|
|
||||||
-- Gebe Pfand-Item
|
|
||||||
Player.Functions.AddItem(itemConfig.pfandItem, 1)
|
|
||||||
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemConfig.pfandItem], "add", 1)
|
|
||||||
|
|
||||||
if Config.PfandSystem.showNotification then
|
|
||||||
local pfandLabel = Config.PfandItems[itemConfig.pfandItem].label
|
|
||||||
TriggerClientEvent('QBCore:Notify', src, string.format(_L('pfand_received'), pfandLabel), "success")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Überwache alle möglichen Events für Item-Nutzung
|
|
||||||
RegisterNetEvent('QBCore:Server:UseItem')
|
|
||||||
AddEventHandler('QBCore:Server:UseItem', function(item)
|
|
||||||
local src = source
|
|
||||||
local itemName = type(item) == "table" and item.name or item
|
|
||||||
TriggerEvent('pickle_consumables:server:useItem', itemName)
|
|
||||||
end)
|
|
||||||
|
|
||||||
RegisterNetEvent('inventory:server:UseItem')
|
|
||||||
AddEventHandler('inventory:server:UseItem', function(source, item)
|
|
||||||
local itemName = type(item) == "table" and item.name or item
|
|
||||||
TriggerEvent('pickle_consumables:server:useItem', itemName)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Hook für Pickle Consumables Item-Nutzung
|
|
||||||
AddEventHandler('pickle_consumables:itemUsed', function(source, itemName, itemData, slot)
|
|
||||||
TriggerEvent('pickle_consumables:server:useItem', itemName)
|
|
||||||
end)
|
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
-- modules/pfandsystem/shared.lua
|
|
||||||
|
|
||||||
-- Pfandautomat Props
|
|
||||||
Config.PfandautomatProps = {
|
|
||||||
'as_rv_machine_prop',
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Pfand Items und ihre Werte (die leeren Behälter)
|
|
||||||
Config.PfandItems = {
|
|
||||||
['empty_bottle'] = {
|
|
||||||
pfandwert = 25, -- Pfandwert in Cent/Credits
|
|
||||||
label = 'leere Flasche'
|
|
||||||
},
|
|
||||||
['empty_can'] = {
|
|
||||||
pfandwert = 25,
|
|
||||||
label = 'leere Dose'
|
|
||||||
},
|
|
||||||
['empty_glasbootle'] = {
|
|
||||||
pfandwert = 25,
|
|
||||||
label = 'leere Glasflasche'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Pfand Einstellungen
|
|
||||||
Config.PfandSystem = {
|
|
||||||
enabled = true,
|
|
||||||
currency = 'cash', -- 'cash' oder 'bank'
|
|
||||||
showNotification = true
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Pfand Sprache
|
|
||||||
if not Language[Config.Language] then Language[Config.Language] = {} end
|
|
||||||
|
|
||||||
Language[Config.Language]['pfand_menu_title'] = 'Pfandautomat'
|
|
||||||
Language[Config.Language]['pfand_menu_description'] = 'Pfandgut einlösen'
|
|
||||||
Language[Config.Language]['no_pfand_items'] = 'Du hast keine Pfandartikel bei dir!'
|
|
||||||
Language[Config.Language]['pfand_success'] = 'Du hast %s für %d Pfandartikel erhalten!'
|
|
||||||
Language[Config.Language]['pfand_error'] = 'Fehler beim Einlösen des Pfands!'
|
|
||||||
Language[Config.Language]['processing'] = 'Verarbeite Pfand...'
|
|
||||||
Language[Config.Language]['select_items'] = 'Wähle die Artikel aus, die du einlösen möchtest:'
|
|
||||||
Language[Config.Language]['pfand_received'] = 'Du hast %s erhalten!'
|
|
Loading…
Add table
Add a link
Reference in a new issue