2025-06-25 02:26:26 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
|
|
|
-- Debug Print Funktion
|
|
|
|
local function Debug(msg)
|
|
|
|
print("^2[Shisha Debug] ^7" .. msg)
|
|
|
|
end
|
|
|
|
|
2025-07-11 13:10:18 +02:00
|
|
|
-- Function to check if player has an item
|
|
|
|
local function HasItem(source, itemName, amount)
|
|
|
|
local items = exports["tgiann-inventory"]:GetPlayerItems(source)
|
|
|
|
if not items then return false end
|
|
|
|
|
|
|
|
local count = 0
|
|
|
|
for _, item in pairs(items) do
|
|
|
|
if item.name == itemName then
|
|
|
|
count = count + item.count
|
|
|
|
if count >= amount then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Event for client to check if player has an item
|
|
|
|
RegisterNetEvent('shisha-script:checkItem', function(itemName, amount, callbackEvent)
|
|
|
|
local src = source
|
|
|
|
local hasItem = HasItem(src, itemName, amount)
|
|
|
|
TriggerClientEvent(callbackEvent, src, hasItem)
|
|
|
|
end)
|
|
|
|
|
2025-06-25 02:26:26 +02:00
|
|
|
RegisterNetEvent('shisha-script:consumeTobacco')
|
|
|
|
AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
2025-06-25 03:04:57 +02:00
|
|
|
Debug("Tabak-Verbrauch-Event ausgelöst")
|
2025-06-25 02:26:26 +02:00
|
|
|
local src = source
|
|
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
|
|
|
|
if Player then
|
|
|
|
-- Überprüfe nochmal die Zutaten
|
|
|
|
local hasAllItems = true
|
|
|
|
for _, requirement in ipairs(requirements) do
|
2025-07-11 13:10:18 +02:00
|
|
|
if not HasItem(src, requirement.item, requirement.amount) then
|
2025-06-25 02:26:26 +02:00
|
|
|
hasAllItems = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if hasAllItems then
|
2025-06-25 03:04:57 +02:00
|
|
|
Debug("Spieler hat alle benötigten Items")
|
2025-06-25 02:26:26 +02:00
|
|
|
-- Entferne die benötigten Items
|
|
|
|
for _, requirement in ipairs(requirements) do
|
2025-07-11 13:10:18 +02:00
|
|
|
exports["tgiann-inventory"]:RemoveItem(src, requirement.item, requirement.amount)
|
2025-06-25 02:26:26 +02:00
|
|
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove")
|
|
|
|
end
|
|
|
|
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, "Du hast die Shisha vorbereitet!", "success")
|
|
|
|
else
|
2025-06-25 03:04:57 +02:00
|
|
|
Debug("Spieler hat nicht alle benötigten Items")
|
2025-06-25 02:26:26 +02:00
|
|
|
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|