forked from Simnation/Main
51 lines
1.9 KiB
Lua
51 lines
1.9 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
-- Debug Print Funktion
|
|
local function Debug(msg)
|
|
print("^2[Shisha Debug] ^7" .. msg)
|
|
end
|
|
|
|
-- Function to check if player has an item
|
|
local function HasItem(source, itemName, amount)
|
|
local itemCount = exports["tgiann-inventory"]:GetItemCount(source, itemName)
|
|
return itemCount >= amount
|
|
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)
|
|
|
|
RegisterNetEvent('shisha-script:consumeTobacco')
|
|
AddEventHandler('shisha-script:consumeTobacco', function(requirements)
|
|
Debug("Tabak-Verbrauch-Event ausgelöst")
|
|
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
|
|
if not HasItem(src, requirement.item, requirement.amount) then
|
|
hasAllItems = false
|
|
break
|
|
end
|
|
end
|
|
|
|
if hasAllItems then
|
|
Debug("Spieler hat alle benötigten Items")
|
|
-- Entferne die benötigten Items
|
|
for _, requirement in ipairs(requirements) do
|
|
exports["tgiann-inventory"]:RemoveItem(src, requirement.item, requirement.amount)
|
|
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove")
|
|
end
|
|
|
|
TriggerClientEvent('QBCore:Notify', src, "Du hast die Shisha vorbereitet!", "success")
|
|
else
|
|
Debug("Spieler hat nicht alle benötigten Items")
|
|
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
|
|
end
|
|
end
|
|
end)
|