forked from Simnation/Main
ed
This commit is contained in:
parent
85eb54bcbc
commit
f333947ed9
2 changed files with 101 additions and 24 deletions
|
@ -3,10 +3,12 @@ Config = {}
|
||||||
-- Pfandautomat Props
|
-- Pfandautomat Props
|
||||||
Config.PfandautomatProps = {
|
Config.PfandautomatProps = {
|
||||||
'as_rv_machine_prop',
|
'as_rv_machine_prop',
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Konsumierbare Items die Pfand generieren
|
-- Delay in ms before adding the deposit item after consumption detection
|
||||||
|
Config.PfandDelay = 1500
|
||||||
|
|
||||||
|
-- Consumable items that generate deposits
|
||||||
Config.ConsumableItems = {
|
Config.ConsumableItems = {
|
||||||
['beer'] = {
|
['beer'] = {
|
||||||
pfandItem = 'empty_glasbootle',
|
pfandItem = 'empty_glasbootle',
|
||||||
|
@ -26,10 +28,10 @@ Config.ConsumableItems = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Pfand Items und ihre Werte (die leeren Behälter)
|
-- Deposit items and their values (the empty containers)
|
||||||
Config.PfandItems = {
|
Config.PfandItems = {
|
||||||
['empty_bottle'] = {
|
['empty_bottle'] = {
|
||||||
pfandwert = 25, -- Pfandwert in Cent/Credits
|
pfandwert = 25, -- Deposit value in cents/credits
|
||||||
label = 'leere Flasche'
|
label = 'leere Flasche'
|
||||||
},
|
},
|
||||||
['empty_can'] = {
|
['empty_can'] = {
|
||||||
|
@ -40,15 +42,14 @@ Config.PfandItems = {
|
||||||
pfandwert = 25,
|
pfandwert = 25,
|
||||||
label = 'leere Glasflasche'
|
label = 'leere Glasflasche'
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Allgemeine Einstellungen
|
-- General settings
|
||||||
Config.Currency = 'cash' -- 'cash' oder 'bank'
|
Config.Currency = 'cash' -- 'cash' or 'bank'
|
||||||
Config.Debug = true
|
Config.Debug = true
|
||||||
Config.ShowPfandNotification = true -- Zeige Benachrichtigung wenn Pfand erhalten wird
|
Config.ShowPfandNotification = true -- Show notification when deposit is received
|
||||||
|
|
||||||
-- Sprache
|
-- Language
|
||||||
Config.Locale = {
|
Config.Locale = {
|
||||||
['pfand_menu_title'] = 'Pfandautomat',
|
['pfand_menu_title'] = 'Pfandautomat',
|
||||||
['pfand_menu_description'] = 'Pfandgut einlösen',
|
['pfand_menu_description'] = 'Pfandgut einlösen',
|
||||||
|
@ -58,5 +59,4 @@ Config.Locale = {
|
||||||
['processing'] = 'Verarbeite Pfand...',
|
['processing'] = 'Verarbeite Pfand...',
|
||||||
['select_items'] = 'Wähle die Artikel aus, die du einlösen möchtest:',
|
['select_items'] = 'Wähle die Artikel aus, die du einlösen möchtest:',
|
||||||
['pfand_received'] = 'Du hast %s erhalten!',
|
['pfand_received'] = 'Du hast %s erhalten!',
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,24 @@
|
||||||
local QBCore = exports['qb-core']:GetCoreObject()
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
|
||||||
-- Event wenn ein Item konsumiert wird
|
-- Store previous inventory states for all players
|
||||||
|
local playerInventories = {}
|
||||||
|
|
||||||
|
-- Event when an item is consumed
|
||||||
RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then return end
|
if not Player then return end
|
||||||
|
|
||||||
-- Prüfe ob das konsumierte Item Pfand generiert
|
-- Check if the consumed item generates a deposit
|
||||||
if Config.ConsumableItems[itemName] then
|
if Config.ConsumableItems[itemName] then
|
||||||
local consumableConfig = Config.ConsumableItems[itemName]
|
local consumableConfig = Config.ConsumableItems[itemName]
|
||||||
local pfandItem = consumableConfig.pfandItem
|
local pfandItem = consumableConfig.pfandItem
|
||||||
|
|
||||||
-- Warte kurz damit das originale Item erst konsumiert wird
|
-- Wait briefly so the original item is consumed first
|
||||||
Wait(500)
|
Wait(500)
|
||||||
|
|
||||||
-- Verwende Player.Functions.AddItem
|
-- Use Player.Functions.AddItem
|
||||||
local success = Player.Functions.AddItem(pfandItem, 1)
|
local success = Player.Functions.AddItem(pfandItem, 1)
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
|
@ -45,7 +48,81 @@ RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Pfand einlösen
|
-- Function to monitor inventory changes and handle deposit items
|
||||||
|
RegisterNetEvent('inventory:server:SetInventory', function(playerId, inventory)
|
||||||
|
local Player = QBCore.Functions.GetPlayer(playerId)
|
||||||
|
if not Player then return end
|
||||||
|
|
||||||
|
-- Initialize player's inventory tracking if it doesn't exist
|
||||||
|
if not playerInventories[playerId] then
|
||||||
|
playerInventories[playerId] = {}
|
||||||
|
for _, item in pairs(Player.PlayerData.items) do
|
||||||
|
if item then
|
||||||
|
playerInventories[playerId][item.name] = (playerInventories[playerId][item.name] or 0) + item.amount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check for removed consumable items
|
||||||
|
for itemName, prevAmount in pairs(playerInventories[playerId]) do
|
||||||
|
if Config.ConsumableItems[itemName] then
|
||||||
|
local currentItem = Player.Functions.GetItemByName(itemName)
|
||||||
|
local currentAmount = currentItem and currentItem.amount or 0
|
||||||
|
|
||||||
|
-- If the amount decreased, it might have been consumed
|
||||||
|
if currentAmount < prevAmount then
|
||||||
|
local removedAmount = prevAmount - currentAmount
|
||||||
|
|
||||||
|
-- Schedule adding the deposit item with delay
|
||||||
|
SetTimeout(Config.PfandDelay or 1000, function()
|
||||||
|
local pfandItem = Config.ConsumableItems[itemName].pfandItem
|
||||||
|
|
||||||
|
if Config.Debug then
|
||||||
|
print(string.format('[Pfandsystem] Detected %d %s removed, adding %s after delay',
|
||||||
|
removedAmount, itemName, pfandItem))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add the deposit item
|
||||||
|
local success = Player.Functions.AddItem(pfandItem, removedAmount)
|
||||||
|
|
||||||
|
if success then
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', playerId, QBCore.Shared.Items[pfandItem], "add", removedAmount)
|
||||||
|
|
||||||
|
if Config.ShowPfandNotification then
|
||||||
|
local pfandLabel = Config.PfandItems[pfandItem] and Config.PfandItems[pfandItem].label or pfandItem
|
||||||
|
|
||||||
|
TriggerClientEvent('ox_lib:notify', playerId, {
|
||||||
|
title = 'Pfandsystem',
|
||||||
|
description = string.format(Config.Locale['pfand_received'], pfandLabel),
|
||||||
|
type = 'success',
|
||||||
|
duration = 3000
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Update the previous inventory state
|
||||||
|
playerInventories[playerId] = {}
|
||||||
|
for _, item in pairs(Player.PlayerData.items) do
|
||||||
|
if item then
|
||||||
|
playerInventories[playerId][item.name] = (playerInventories[playerId][item.name] or 0) + item.amount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Clean up player inventory tracking when they disconnect
|
||||||
|
AddEventHandler('playerDropped', function()
|
||||||
|
local src = source
|
||||||
|
if playerInventories[src] then
|
||||||
|
playerInventories[src] = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Redeem deposit
|
||||||
RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
local src = source
|
local src = source
|
||||||
local Player = QBCore.Functions.GetPlayer(src)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
@ -56,7 +133,7 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
local canRedeem = true
|
local canRedeem = true
|
||||||
|
|
||||||
-- Prüfe ob alle Items verfügbar sind
|
-- Check if all items are available
|
||||||
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 item = Player.Functions.GetItemByName(itemName)
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
|
@ -73,7 +150,7 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
end
|
end
|
||||||
|
|
||||||
if canRedeem then
|
if canRedeem then
|
||||||
-- Entferne Items und berechne Pfand
|
-- Remove items and calculate deposit
|
||||||
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 = Player.Functions.RemoveItem(itemName, quantity)
|
local removed = Player.Functions.RemoveItem(itemName, quantity)
|
||||||
|
@ -88,14 +165,14 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
end
|
end
|
||||||
|
|
||||||
if totalPfand > 0 then
|
if totalPfand > 0 then
|
||||||
-- Gebe Geld
|
-- Give money
|
||||||
if Config.Currency == 'cash' then
|
if Config.Currency == 'cash' then
|
||||||
Player.Functions.AddMoney('cash', totalPfand)
|
Player.Functions.AddMoney('cash', totalPfand)
|
||||||
else
|
else
|
||||||
Player.Functions.AddMoney('bank', totalPfand)
|
Player.Functions.AddMoney('bank', totalPfand)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Formatiere Geld für Anzeige
|
-- Format money for display
|
||||||
local moneyString = string.format("€%.2f", totalPfand / 100)
|
local moneyString = string.format("€%.2f", totalPfand / 100)
|
||||||
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
|
@ -112,7 +189,7 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
-- Get available deposit items for the player
|
||||||
QBCore.Functions.CreateCallback('qb-pfandsystem:server:getPfandItems', function(source, cb)
|
QBCore.Functions.CreateCallback('qb-pfandsystem:server:getPfandItems', function(source, cb)
|
||||||
local src = source
|
local src = source
|
||||||
local pfandItems = {}
|
local pfandItems = {}
|
||||||
|
@ -139,7 +216,7 @@ QBCore.Functions.CreateCallback('qb-pfandsystem:server:getPfandItems', function(
|
||||||
cb(pfandItems)
|
cb(pfandItems)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Zusätzliche Event-Handler für verschiedene Inventarsysteme
|
-- Additional event handlers for various inventory systems
|
||||||
RegisterNetEvent('inventory:server:UseItem')
|
RegisterNetEvent('inventory:server:UseItem')
|
||||||
AddEventHandler('inventory:server:UseItem', function(source, item)
|
AddEventHandler('inventory:server:UseItem', function(source, item)
|
||||||
local itemName = type(item) == "table" and item.name or item
|
local itemName = type(item) == "table" and item.name or item
|
||||||
|
@ -151,7 +228,7 @@ AddEventHandler('inventory:server:UseItem', function(source, item)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Für tgiann-inventory
|
-- For tgiann-inventory
|
||||||
RegisterNetEvent('tgiann-inventory:itemUsed')
|
RegisterNetEvent('tgiann-inventory:itemUsed')
|
||||||
AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName)
|
AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName)
|
||||||
if Config.ConsumableItems[itemName] then
|
if Config.ConsumableItems[itemName] then
|
||||||
|
@ -161,7 +238,7 @@ AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Debug-Befehl zum manuellen Auslösen
|
-- Debug command for manual triggering
|
||||||
RegisterCommand('pfanditem', function(source, args)
|
RegisterCommand('pfanditem', function(source, args)
|
||||||
if Config.Debug then
|
if Config.Debug then
|
||||||
if args[1] and source > 0 then
|
if args[1] and source > 0 then
|
||||||
|
@ -170,7 +247,7 @@ RegisterCommand('pfanditem', function(source, args)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Export für andere Scripts
|
-- Export for other scripts
|
||||||
exports('ConsumePfandItem', function(source, itemName)
|
exports('ConsumePfandItem', function(source, itemName)
|
||||||
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue