ed
This commit is contained in:
parent
c82cfea316
commit
07f27b0557
7 changed files with 150 additions and 322 deletions
|
@ -1834,6 +1834,7 @@ Config.Items = {
|
|||
prop = { model = `h4_prop_club_water_bottle`, boneId = 28422, offset = vec3(0.0, 0.00, -0.20), rotation = vec3(0.0, 0.0, 0.0) },
|
||||
idle = { dict = "amb@code_human_wander_drinking_fat@beer@male@base", anim = "static", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
animation = { dict = "mini@sprunk", anim = "plyr_buy_drink_pt2", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
pfandItem = "empty_bottle", -- Hier wird das Pfand-Item definiert
|
||||
status = { -- Per use. Values are based on percentage of the max value of the status. If below zero, it will remove the status percentage.
|
||||
hunger = 0,
|
||||
thirst = 20,
|
||||
|
@ -1848,6 +1849,7 @@ Config.Items = {
|
|||
prop = { model = `sf_prop_sf_can_01a`, boneId = 28422, offset = vec3(0.0, 0.00, -0.07), rotation = vec3(0.0, 0.0, 0.0) },
|
||||
idle = { dict = "amb@code_human_wander_drinking_fat@beer@male@base", anim = "static", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
animation = { dict = "mini@sprunk", anim = "plyr_buy_drink_pt2", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
pfandItem = "empty_can", -- Hier wird das Pfand-Item definiert
|
||||
status = { -- Per use. Values are based on percentage of the max value of the status. If below zero, it will remove the status percentage.
|
||||
hunger = 0,
|
||||
thirst = 15,
|
||||
|
@ -1876,6 +1878,7 @@ Config.Items = {
|
|||
prop = { model = `ng_proc_sodacan_01b`, boneId = 28422, offset = vec3(0.0, 0.00, -0.07), rotation = vec3(0.0, 0.0, 0.0) },
|
||||
idle = { dict = "amb@code_human_wander_drinking_fat@beer@male@base", anim = "static", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
animation = { dict = "mini@sprunk", anim = "plyr_buy_drink_pt2", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
pfandItem = "empty_can", -- Hier wird das Pfand-Item definiert
|
||||
status = { -- Per use. Values are based on percentage of the max value of the status. If below zero, it will remove the status percentage.
|
||||
hunger = 0,
|
||||
thirst = 10,
|
||||
|
@ -1890,6 +1893,7 @@ Config.Items = {
|
|||
prop = { model = `sf_prop_sf_can_01a`, boneId = 28422, offset = vec3(0.0, 0.00, -0.07), rotation = vec3(0.0, 0.0, 0.0) },
|
||||
idle = { dict = "amb@code_human_wander_drinking_fat@beer@male@base", anim = "static", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
animation = { dict = "mini@sprunk", anim = "plyr_buy_drink_pt2", time = 2000, params = { nil, nil, nil, 49 } },
|
||||
pfandItem = "empty_can", -- Hier wird das Pfand-Item definiert
|
||||
status = { -- Per use. Values are based on percentage of the max value of the status. If below zero, it will remove the status percentage.
|
||||
hunger = 0,
|
||||
thirst = 20,
|
||||
|
|
|
@ -0,0 +1,141 @@
|
|||
-- modules/pfandsystem/client.lua
|
||||
|
||||
-- Erstelle Targets für alle Pfandautomaten
|
||||
CreateThread(function()
|
||||
if not Config.PfandSystem or not Config.PfandSystem.enabled then return end
|
||||
|
||||
for _, prop in pairs(Config.PfandautomatProps) do
|
||||
exports['qb-target']:AddTargetModel(prop, {
|
||||
options = {
|
||||
{
|
||||
type = "client",
|
||||
event = "pickle_consumables:client:openPfandMenu",
|
||||
icon = "fas fa-recycle",
|
||||
label = _L('pfand_menu_title'),
|
||||
}
|
||||
},
|
||||
distance = 2.0
|
||||
})
|
||||
end
|
||||
end)
|
||||
|
||||
-- Öffne Pfand Menu
|
||||
RegisterNetEvent('pickle_consumables:client:openPfandMenu', function()
|
||||
TriggerCallback('pickle_consumables:server:getPfandItems', function(pfandItems)
|
||||
if next(pfandItems) == nil then
|
||||
ShowNotification(_L('no_pfand_items'))
|
||||
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 = _L("Alle Pfandartikel einlösen"),
|
||||
description = _L("Löse alle verfügbaren Pfandartikel auf einmal ein"),
|
||||
icon = 'coins',
|
||||
onSelect = function()
|
||||
redeemAllItems(pfandItems)
|
||||
end
|
||||
})
|
||||
|
||||
lib.registerContext({
|
||||
id = 'pfand_menu',
|
||||
title = _L('pfand_menu_title'),
|
||||
options = options
|
||||
})
|
||||
|
||||
lib.showContext('pfand_menu')
|
||||
end
|
||||
|
||||
-- Zeige Mengenauswahl
|
||||
function showQuantityInput(itemName, itemData)
|
||||
local input = lib.inputDialog(_L('pfand_menu_title'), {
|
||||
{
|
||||
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 = _L('pfand_menu_title'),
|
||||
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 = _L('pfand_menu_title'),
|
||||
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)
|
||||
ShowNotification(_L('processing'))
|
||||
TriggerServerEvent('pickle_consumables:server:redeemPfand', selectedItems)
|
||||
end
|
|
@ -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)
|
|
@ -0,0 +1,41 @@
|
|||
-- 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