forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
c4f49f95a1
commit
9126918d5d
1 changed files with 105 additions and 83 deletions
|
@ -17,10 +17,10 @@ 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
|
-- Gebe Pfanditem mit tgiann-inventory
|
||||||
local success = exports['tgiann-inventory']:AddItem(src, pfandItem, 1)
|
TriggerEvent('tgiann-inventory:server:addItem', src, pfandItem, 1)
|
||||||
|
|
||||||
if success and 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
|
||||||
|
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
|
@ -68,8 +68,8 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
-- Überprüfe ob Spieler die Items hat und berechne Gesamtpfand
|
-- Überprüfe ob Spieler die Items hat und berechne Gesamtpfand
|
||||||
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 playerItem = exports['tgiann-inventory']:GetItem(src, itemName)
|
-- Verwende tgiann-inventory callback um Item zu prüfen
|
||||||
|
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItem', function(playerItem)
|
||||||
if playerItem and playerItem.count >= quantity then
|
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
|
||||||
|
@ -83,9 +83,12 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
end, src, itemName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Warte kurz damit alle Callbacks verarbeitet werden
|
||||||
|
SetTimeout(100, function()
|
||||||
if totalPfand <= 0 then
|
if totalPfand <= 0 then
|
||||||
TriggerClientEvent('ox_lib:notify', src, {
|
TriggerClientEvent('ox_lib:notify', src, {
|
||||||
title = 'Pfandsystem',
|
title = 'Pfandsystem',
|
||||||
|
@ -98,11 +101,7 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
-- Entferne Items aus dem Inventar
|
-- Entferne Items aus dem Inventar
|
||||||
local success = true
|
local success = true
|
||||||
for itemName, quantity in pairs(itemsToRemove) do
|
for itemName, quantity in pairs(itemsToRemove) do
|
||||||
local removed = exports['tgiann-inventory']:RemoveItem(src, itemName, quantity)
|
TriggerEvent('tgiann-inventory:server:removeItem', src, itemName, quantity)
|
||||||
if not removed then
|
|
||||||
success = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
|
@ -134,14 +133,28 @@ RegisterNetEvent('qb-pfandsystem:server:redeemPfand', function(selectedItems)
|
||||||
})
|
})
|
||||||
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 totalItems = 0
|
||||||
|
|
||||||
|
-- Zähle wie viele Items wir prüfen müssen
|
||||||
|
for _ in pairs(Config.PfandItems) do
|
||||||
|
totalItems = totalItems + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if totalItems == 0 then
|
||||||
|
cb(pfandItems)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
for itemName, itemConfig in pairs(Config.PfandItems) do
|
for itemName, itemConfig in pairs(Config.PfandItems) do
|
||||||
local playerItem = exports['tgiann-inventory']:GetItem(src, itemName)
|
QBCore.Functions.TriggerCallback('tgiann-inventory:server:getItem', function(playerItem)
|
||||||
|
itemsChecked = itemsChecked + 1
|
||||||
|
|
||||||
if playerItem and playerItem.count > 0 then
|
if playerItem and playerItem.count > 0 then
|
||||||
pfandItems[itemName] = {
|
pfandItems[itemName] = {
|
||||||
|
@ -151,16 +164,17 @@ QBCore.Functions.CreateCallback('qb-pfandsystem:server:getPfandItems', function(
|
||||||
totalWert = itemConfig.pfandwert * playerItem.count
|
totalWert = itemConfig.pfandwert * playerItem.count
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
|
||||||
-- Hook für tgiann-inventory item usage
|
-- Korrekte Event-Handler für tgiann-inventory
|
||||||
-- Dieser Hook wird ausgelöst wenn ein Item verwendet wird
|
RegisterNetEvent('tgiann-inventory:server:itemUsed', function(source, itemName, itemData)
|
||||||
RegisterNetEvent('tgiann-inventory:server:UseItem', function(itemName, itemData)
|
|
||||||
local src = source
|
|
||||||
|
|
||||||
-- Prüfe ob das verwendete Item in unserer Konsumierbare Items Liste ist
|
-- Prüfe ob das verwendete Item in unserer Konsumierbare Items Liste ist
|
||||||
if Config.ConsumableItems[itemName] then
|
if Config.ConsumableItems[itemName] then
|
||||||
-- Warte kurz damit das originale Item erst konsumiert wird
|
-- Warte kurz damit das originale Item erst konsumiert wird
|
||||||
|
@ -170,8 +184,16 @@ RegisterNetEvent('tgiann-inventory:server:UseItem', function(itemName, itemData)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Alternative: Falls der obige Hook nicht funktioniert, kann man auch einen Export verwenden
|
-- Alternative: Nutze den korrekten Event Namen basierend auf der Dokumentation
|
||||||
-- Dieser Export kann von anderen Scripten aufgerufen werden
|
RegisterNetEvent('tgiann-inventory:itemUsed', function(source, itemName, itemData)
|
||||||
|
if Config.ConsumableItems[itemName] then
|
||||||
|
SetTimeout(100, function()
|
||||||
|
TriggerEvent('qb-pfandsystem:server:itemConsumed', itemName)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- 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)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue