forked from Simnation/Main
ed
This commit is contained in:
parent
ad74a2d686
commit
0156a8765f
2 changed files with 60 additions and 126 deletions
|
@ -10,22 +10,18 @@ Config.PfandautomatProps = {
|
||||||
Config.ConsumableItems = {
|
Config.ConsumableItems = {
|
||||||
['beer'] = {
|
['beer'] = {
|
||||||
pfandItem = 'empty_glasbootle',
|
pfandItem = 'empty_glasbootle',
|
||||||
chance = 100, -- 100% Chance Pfand zu bekommen
|
|
||||||
label = 'Bier'
|
label = 'Bier'
|
||||||
},
|
},
|
||||||
['water_bottle'] = {
|
['water_bottle'] = {
|
||||||
pfandItem = 'empty_bottle',
|
pfandItem = 'empty_bottle',
|
||||||
chance = 100,
|
|
||||||
label = 'Wasserflasche'
|
label = 'Wasserflasche'
|
||||||
},
|
},
|
||||||
['ecola_dose'] = {
|
['ecola_dose'] = {
|
||||||
pfandItem = 'soda_can',
|
pfandItem = 'soda_can',
|
||||||
chance = 100,
|
|
||||||
label = 'Cola'
|
label = 'Cola'
|
||||||
},
|
},
|
||||||
['sprunk_dose'] = {
|
['sprunk_dose'] = {
|
||||||
pfandItem = 'soda_can',
|
pfandItem = 'soda_can',
|
||||||
chance = 100,
|
|
||||||
label = 'Sprite'
|
label = 'Sprite'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -62,5 +58,5 @@ 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!',
|
||||||
['pfand_bottle_broken'] = 'Die Flasche ist beim Trinken zerbrochen!'
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,14 @@ RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
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
|
||||||
local chance = consumableConfig.chance or 100
|
|
||||||
|
|
||||||
-- Würfle ob Pfand erhalten wird
|
-- Verwende Player.Functions.AddItem statt tgiann-inventory
|
||||||
local randomChance = math.random(1, 100)
|
local success = Player.Functions.AddItem(pfandItem, 1)
|
||||||
|
|
||||||
if randomChance <= chance then
|
|
||||||
-- Gebe Pfanditem mit korrektem tgiann-inventory Export
|
|
||||||
local success = exports['tgiann-inventory']:AddItem(src, pfandItem, 1, nil, nil, function(success, reason)
|
|
||||||
if success then
|
if success then
|
||||||
|
-- Trigger inventory update
|
||||||
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[pfandItem], "add", 1)
|
||||||
|
|
||||||
if Config.ShowPfandNotification then
|
if Config.ShowPfandNotification then
|
||||||
local pfandLabel = Config.PfandItems[pfandItem] and Config.PfandItems[pfandItem].label or pfandItem
|
local pfandLabel = Config.PfandItems[pfandItem] and Config.PfandItems[pfandItem].label or pfandItem
|
||||||
|
|
||||||
|
@ -37,24 +36,7 @@ RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if Config.Debug then
|
if Config.Debug then
|
||||||
print(string.format('[Pfandsystem] Fehler beim Hinzufügen von %s: %s', pfandItem, reason or 'Unbekannt'))
|
print(string.format('[Pfandsystem] Fehler beim Hinzufügen von %s für Spieler %s', pfandItem, Player.PlayerData.name))
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
-- Pfand nicht erhalten (z.B. Flasche zerbrochen)
|
|
||||||
if Config.ShowPfandNotification and chance < 100 then
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
|
||||||
title = 'Pfandsystem',
|
|
||||||
description = Config.Locale['pfand_bottle_broken'],
|
|
||||||
type = 'error',
|
|
||||||
duration = 3000
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
if Config.Debug then
|
|
||||||
print(string.format('[Pfandsystem] Spieler %s hat %s konsumiert aber kein Pfand erhalten (%d%% Chance)',
|
|
||||||
Player.PlayerData.name, itemName, chance))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,19 +51,14 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
|
|
||||||
local totalPfand = 0
|
local totalPfand = 0
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
local itemsToRemove = {}
|
local canRedeem = true
|
||||||
|
|
||||||
-- Überprüfe ob Spieler die Items hat und berechne Gesamtpfand
|
-- 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 tgiann-inventory Export um Item zu prüfen
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
exports['tgiann-inventory']:GetItem(src, itemName, function(item)
|
if not item or item.amount < quantity then
|
||||||
if item and item.count >= quantity then
|
canRedeem = false
|
||||||
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
|
||||||
totalPfand = totalPfand + pfandWert
|
|
||||||
totalItems = totalItems + quantity
|
|
||||||
itemsToRemove[itemName] = quantity
|
|
||||||
else
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
title = 'Pfandsystem',
|
title = 'Pfandsystem',
|
||||||
description = 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName),
|
description = 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName),
|
||||||
|
@ -89,35 +66,25 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Warte kurz damit alle Callbacks verarbeitet werden
|
if canRedeem then
|
||||||
SetTimeout(500, function()
|
-- Entferne Items und berechne Pfand
|
||||||
if totalPfand <= 0 then
|
for itemName, quantity in pairs(selectedItems) do
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
if Config.PfandItems[itemName] then
|
||||||
title = 'Pfandsystem',
|
local removed = Player.Functions.RemoveItem(itemName, quantity)
|
||||||
description = Config.Locale['no_pfand_items'],
|
if removed then
|
||||||
type = 'error'
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "remove", quantity)
|
||||||
})
|
|
||||||
return
|
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
||||||
|
totalPfand = totalPfand + pfandWert
|
||||||
|
totalItems = totalItems + quantity
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Entferne Items aus dem Inventar
|
if totalPfand > 0 then
|
||||||
local removedSuccessfully = true
|
|
||||||
for itemName, quantity in pairs(itemsToRemove) do
|
|
||||||
exports['tgiann-inventory']:RemoveItem(src, itemName, quantity, nil, function(success, reason)
|
|
||||||
if not success then
|
|
||||||
removedSuccessfully = false
|
|
||||||
if Config.Debug then
|
|
||||||
print(string.format('[Pfandsystem] Fehler beim Entfernen von %s: %s', itemName, reason or 'Unbekannt'))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
if removedSuccessfully then
|
|
||||||
-- Gebe Geld
|
-- Gebe Geld
|
||||||
if Config.Currency == 'cash' then
|
if Config.Currency == 'cash' then
|
||||||
Player.Functions.AddMoney('cash', totalPfand)
|
Player.Functions.AddMoney('cash', totalPfand)
|
||||||
|
@ -138,56 +105,38 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
print(string.format('[Pfandsystem] Spieler %s hat %d Items für €%.2f eingelöst',
|
print(string.format('[Pfandsystem] Spieler %s hat %d Items für €%.2f eingelöst',
|
||||||
Player.PlayerData.name, totalItems, totalPfand / 100))
|
Player.PlayerData.name, totalItems, totalPfand / 100))
|
||||||
end
|
end
|
||||||
else
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
|
||||||
title = 'Pfandsystem',
|
|
||||||
description = Config.Locale['pfand_error'],
|
|
||||||
type = 'error'
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
-- Hole verfügbare Pfand Items des Spielers
|
||||||
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 = {}
|
||||||
local itemsChecked = 0
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
local totalItems = 0
|
|
||||||
|
|
||||||
-- Zähle wie viele Items wir prüfen müssen
|
if not Player then
|
||||||
for _ in pairs(Config.PfandItems) do
|
|
||||||
totalItems = totalItems + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if totalItems == 0 then
|
|
||||||
cb(pfandItems)
|
cb(pfandItems)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||||
exports['tgiann-inventory']:GetItem(src, itemName, function(item)
|
local item = Player.Functions.GetItemByName(itemName)
|
||||||
itemsChecked = itemsChecked + 1
|
|
||||||
|
|
||||||
if item and item.count > 0 then
|
if item and item.amount > 0 then
|
||||||
pfandItems[itemName] = {
|
pfandItems[itemName] = {
|
||||||
count = item.count,
|
count = item.amount,
|
||||||
label = itemConfig.label,
|
label = itemConfig.label,
|
||||||
pfandwert = itemConfig.pfandwert,
|
pfandwert = itemConfig.pfandwert,
|
||||||
totalWert = itemConfig.pfandwert * item.count
|
totalWert = itemConfig.pfandwert * item.amount
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Wenn alle Items geprüft wurden, sende Ergebnis zurück
|
|
||||||
if itemsChecked >= totalItems then
|
|
||||||
cb(pfandItems)
|
cb(pfandItems)
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Event-Handler für tgiann-inventory item usage
|
-- Event-Handler für Item-Nutzung
|
||||||
-- Basierend auf der Dokumentation
|
|
||||||
RegisterNetEvent('tgiann-inventory:itemUsed')
|
RegisterNetEvent('tgiann-inventory:itemUsed')
|
||||||
AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName, itemData)
|
AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName, itemData)
|
||||||
if Config.ConsumableItems[itemName] then
|
if Config.ConsumableItems[itemName] then
|
||||||
|
@ -197,17 +146,6 @@ AddEventHandler('tgiann-inventory:itemUsed', function(source, itemName, itemData
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Alternative Event (falls der obere nicht funktioniert)
|
|
||||||
RegisterNetEvent('inventory:server:UseItem')
|
|
||||||
AddEventHandler('inventory:server:UseItem', function(itemName, itemData)
|
|
||||||
local src = source
|
|
||||||
if Config.ConsumableItems[itemName] then
|
|
||||||
SetTimeout(100, function()
|
|
||||||
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Export für andere Scripts
|
-- Export für andere Scripts
|
||||||
exports('ConsumePfandItem', function(source, itemName)
|
exports('ConsumePfandItem', function(source, itemName)
|
||||||
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue