forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
9126918d5d
commit
8ffed48f91
1 changed files with 53 additions and 117 deletions
|
@ -17,7 +17,7 @@ RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
local randomChance = math.random(1, 100)
|
local randomChance = math.random(1, 100)
|
||||||
|
|
||||||
if randomChance <= chance then
|
if randomChance <= chance then
|
||||||
-- Gebe Pfanditem mit tgiann-inventory
|
-- Gebe Pfanditem mit tgiann-inventory Event
|
||||||
TriggerEvent('tgiann-inventory:server:addItem', src, pfandItem, 1)
|
TriggerEvent('tgiann-inventory:server:addItem', src, pfandItem, 1)
|
||||||
|
|
||||||
if Config.ShowPfandNotification then
|
if Config.ShowPfandNotification then
|
||||||
|
@ -35,26 +35,11 @@ RegisterNetEvent('qb-pfandsystem:server:itemConsumed', function(itemName)
|
||||||
print(string.format('[Pfandsystem] Spieler %s hat %s konsumiert und %s erhalten',
|
print(string.format('[Pfandsystem] Spieler %s hat %s konsumiert und %s erhalten',
|
||||||
Player.PlayerData.name, itemName, pfandItem))
|
Player.PlayerData.name, itemName, pfandItem))
|
||||||
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)
|
end)
|
||||||
|
|
||||||
-- Pfand einlösen
|
-- Vereinfachte Pfand-Einlösung
|
||||||
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)
|
||||||
|
@ -63,48 +48,20 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
|
|
||||||
local totalPfand = 0
|
local totalPfand = 0
|
||||||
local totalItems = 0
|
local totalItems = 0
|
||||||
local itemsToRemove = {}
|
|
||||||
|
|
||||||
-- Überprüfe ob Spieler die Items hat und berechne Gesamtpfand
|
-- Berechne Gesamtpfand und entferne Items
|
||||||
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 callback um Item zu prüfen
|
-- Entferne Item direkt
|
||||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItem', function(playerItem)
|
TriggerEvent('tgiann-inventory:server:removeItem', src, itemName, quantity)
|
||||||
if playerItem and playerItem.count >= quantity then
|
|
||||||
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
local pfandWert = Config.PfandItems[itemName].pfandwert * quantity
|
||||||
totalPfand = totalPfand + pfandWert
|
totalPfand = totalPfand + pfandWert
|
||||||
totalItems = totalItems + quantity
|
totalItems = totalItems + quantity
|
||||||
itemsToRemove[itemName] = quantity
|
|
||||||
else
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
|
||||||
title = 'Pfandsystem',
|
|
||||||
description = 'Du hast nicht genug ' .. (Config.PfandItems[itemName].label or itemName),
|
|
||||||
type = 'error'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end, src, itemName)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Warte kurz damit alle Callbacks verarbeitet werden
|
if totalPfand > 0 then
|
||||||
SetTimeout(100, function()
|
|
||||||
if totalPfand <= 0 then
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
|
||||||
title = 'Pfandsystem',
|
|
||||||
description = Config.Locale['no_pfand_items'],
|
|
||||||
type = 'error'
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Entferne Items aus dem Inventar
|
|
||||||
local success = true
|
|
||||||
for itemName, quantity in pairs(itemsToRemove) do
|
|
||||||
TriggerEvent('tgiann-inventory:server:removeItem', src, itemName, quantity)
|
|
||||||
end
|
|
||||||
|
|
||||||
if success 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)
|
||||||
|
@ -125,67 +82,46 @@ 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)
|
||||||
|
|
||||||
-- Hole verfügbare Pfand Items des Spielers
|
-- Vereinfachte Item-Abfrage
|
||||||
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 totalItems = 0
|
|
||||||
|
|
||||||
-- Zähle wie viele Items wir prüfen müssen
|
-- Nutze Player.PlayerData.items direkt
|
||||||
for _ in pairs(Config.PfandItems) do
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
totalItems = totalItems + 1
|
if not Player then
|
||||||
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
|
||||||
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItem', function(playerItem)
|
local itemCount = 0
|
||||||
itemsChecked = itemsChecked + 1
|
|
||||||
|
|
||||||
if playerItem and playerItem.count > 0 then
|
-- Durchsuche Spieler-Inventar
|
||||||
|
for slot, item in pairs(Player.PlayerData.items) do
|
||||||
|
if item and item.name == itemName then
|
||||||
|
itemCount = itemCount + item.amount
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if itemCount > 0 then
|
||||||
pfandItems[itemName] = {
|
pfandItems[itemName] = {
|
||||||
count = playerItem.count,
|
count = itemCount,
|
||||||
label = itemConfig.label,
|
label = itemConfig.label,
|
||||||
pfandwert = itemConfig.pfandwert,
|
pfandwert = itemConfig.pfandwert,
|
||||||
totalWert = itemConfig.pfandwert * playerItem.count
|
totalWert = itemConfig.pfandwert * itemCount
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Wenn alle Items geprüft wurden, sende Ergebnis zurück
|
|
||||||
if itemsChecked >= totalItems then
|
|
||||||
cb(pfandItems)
|
cb(pfandItems)
|
||||||
end
|
|
||||||
end, src, itemName)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Korrekte Event-Handler für tgiann-inventory
|
-- Event-Handler für Item-Nutzung
|
||||||
RegisterNetEvent('tgiann-inventory:server:itemUsed', function(source, itemName, itemData)
|
RegisterNetEvent('tgiann-inventory:server:itemUsed', function(source, itemName, itemData)
|
||||||
-- Prüfe ob das verwendete Item in unserer Konsumierbare Items Liste ist
|
|
||||||
if Config.ConsumableItems[itemName] then
|
|
||||||
-- Warte kurz damit das originale Item erst konsumiert wird
|
|
||||||
SetTimeout(100, function()
|
|
||||||
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Alternative: Nutze den korrekten Event Namen basierend auf der Dokumentation
|
|
||||||
RegisterNetEvent('tgiann-inventory:itemUsed', function(source, itemName, itemData)
|
|
||||||
if Config.ConsumableItems[itemName] then
|
if Config.ConsumableItems[itemName] then
|
||||||
SetTimeout(100, function()
|
SetTimeout(100, function()
|
||||||
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue