2025-06-18 02:30:02 +02:00
|
|
|
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Debug-Funktion
|
2025-06-18 02:30:02 +02:00
|
|
|
local function Debug(msg)
|
2025-06-18 05:39:08 +02:00
|
|
|
print("^2[Grill Debug] ^7" .. msg)
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Warte auf vollständige Initialisierung von QBCore
|
2025-06-18 02:30:02 +02:00
|
|
|
CreateThread(function()
|
2025-06-18 06:13:19 +02:00
|
|
|
if not QBCore then
|
|
|
|
Debug("QBCore nicht gefunden, warte...")
|
|
|
|
while not QBCore do
|
|
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
Wait(100)
|
|
|
|
end
|
2025-06-18 05:39:08 +02:00
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
Debug("QBCore initialisiert")
|
2025-06-18 05:39:08 +02:00
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Registriere Grill-Props für qb-target
|
2025-06-18 05:39:08 +02:00
|
|
|
for _, prop in pairs(Config.GrillProps) do
|
2025-06-18 06:13:19 +02:00
|
|
|
Debug("Registriere Target für Prop: " .. tostring(prop))
|
2025-06-18 02:30:02 +02:00
|
|
|
exports['qb-target']:AddTargetModel(prop, {
|
|
|
|
options = {
|
|
|
|
{
|
|
|
|
type = "client",
|
2025-06-18 06:13:19 +02:00
|
|
|
event = "nordi_bbq:OpenGrillMenu",
|
|
|
|
icon = "fas fa-fire",
|
|
|
|
label = "Grillen",
|
2025-06-18 02:30:02 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
distance = 2.0
|
|
|
|
})
|
|
|
|
end
|
2025-06-18 06:13:19 +02:00
|
|
|
|
|
|
|
Debug("Target-Optionen registriert")
|
2025-06-18 02:30:02 +02:00
|
|
|
end)
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Event zum Öffnen des Grill-Menüs
|
|
|
|
RegisterNetEvent('nordi_bbq:OpenGrillMenu', function()
|
|
|
|
Debug("Öffne Grill-Menü")
|
2025-06-18 05:39:08 +02:00
|
|
|
OpenGrillMenu()
|
2025-06-18 02:30:02 +02:00
|
|
|
end)
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Funktion zum Überprüfen der Zutaten
|
|
|
|
function CheckIngredients(recipe)
|
2025-06-18 02:30:02 +02:00
|
|
|
local hasItems = true
|
|
|
|
local missingItems = {}
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
if not recipe or not recipe.requires then
|
|
|
|
Debug("Rezept oder Anforderungen fehlen")
|
2025-06-18 05:47:41 +02:00
|
|
|
return false, {}
|
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
for _, item in pairs(recipe.requires) do
|
|
|
|
if not QBCore.Functions.HasItem(item.item, item.amount) then
|
2025-06-18 02:30:02 +02:00
|
|
|
hasItems = false
|
|
|
|
table.insert(missingItems, {
|
2025-06-18 06:13:19 +02:00
|
|
|
item = item.item,
|
|
|
|
amount = item.amount
|
2025-06-18 02:30:02 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return hasItems, missingItems
|
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Funktion zum Anzeigen fehlender Zutaten
|
|
|
|
function ShowMissingIngredients(missingItems)
|
|
|
|
local text = "Fehlende Zutaten:\n"
|
|
|
|
|
|
|
|
for _, item in pairs(missingItems) do
|
|
|
|
local itemLabel = QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label or item.item
|
|
|
|
text = text .. "- " .. itemLabel .. " (" .. item.amount .. "x)\n"
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
QBCore.Functions.Notify(text, "error", 5000)
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Funktion zum Öffnen des Grill-Menüs
|
2025-06-18 05:33:48 +02:00
|
|
|
function OpenGrillMenu()
|
2025-06-18 06:13:19 +02:00
|
|
|
Debug("Erstelle Grill-Menü")
|
2025-06-18 05:39:08 +02:00
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
local menuOptions = {}
|
2025-06-18 05:39:08 +02:00
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
for _, recipe in pairs(Config.GrillRecipes) do
|
|
|
|
local hasIngredients, _ = CheckIngredients(recipe)
|
|
|
|
local status = hasIngredients and "~g~✓" or "~r~✗"
|
2025-06-18 05:39:08 +02:00
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Erstelle Beschreibung mit Zutaten
|
|
|
|
local description = recipe.description .. "\n\nZutaten:"
|
|
|
|
for _, item in pairs(recipe.requires) do
|
|
|
|
local itemLabel = QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label or item.item
|
|
|
|
local hasItem = QBCore.Functions.HasItem(item.item, item.amount)
|
|
|
|
local itemStatus = hasItem and "~g~✓" or "~r~✗"
|
|
|
|
description = description .. "\n- " .. item.amount .. "x " .. itemLabel .. " " .. itemStatus
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
2025-06-18 06:13:19 +02:00
|
|
|
|
|
|
|
table.insert(menuOptions, {
|
|
|
|
title = recipe.label,
|
2025-06-18 02:30:02 +02:00
|
|
|
description = description,
|
2025-06-18 06:13:19 +02:00
|
|
|
icon = recipe.icon or "fas fa-drumstick-bite",
|
2025-06-18 02:30:02 +02:00
|
|
|
onSelect = function()
|
2025-06-18 06:13:19 +02:00
|
|
|
StartGrilling(recipe)
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
2025-06-18 05:39:08 +02:00
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Registriere und zeige das Menü mit ox_lib
|
2025-06-18 05:39:08 +02:00
|
|
|
if lib and lib.registerContext then
|
|
|
|
lib.registerContext({
|
|
|
|
id = 'grill_menu',
|
|
|
|
title = 'Grill',
|
2025-06-18 06:13:19 +02:00
|
|
|
options = menuOptions
|
2025-06-18 05:39:08 +02:00
|
|
|
})
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
lib.showContext('grill_menu')
|
2025-06-18 05:39:08 +02:00
|
|
|
else
|
2025-06-18 06:13:19 +02:00
|
|
|
Debug("FEHLER: ox_lib nicht verfügbar")
|
|
|
|
QBCore.Functions.Notify("Fehler beim Laden des Menüs", "error")
|
2025-06-18 05:39:08 +02:00
|
|
|
end
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
|
|
|
|
2025-06-18 06:13:19 +02:00
|
|
|
-- Funktion zum Starten des Grillvorgangs
|
|
|
|
function StartGrilling(recipe)
|
|
|
|
Debug("Starte Grillvorgang für: " .. recipe.label)
|
|
|
|
|
|
|
|
-- Überprüfe Zutaten erneut
|
|
|
|
local hasIngredients, missingItems = CheckIngredients(recipe)
|
|
|
|
|
|
|
|
if not hasIngredients then
|
|
|
|
ShowMissingIngredients(missingItems)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Animation und Progressbar
|
2025-06-18 05:39:08 +02:00
|
|
|
local animDict = "amb@prop_human_bbq@male@base"
|
|
|
|
local anim = "base"
|
2025-06-18 02:30:02 +02:00
|
|
|
|
|
|
|
RequestAnimDict(animDict)
|
|
|
|
while not HasAnimDictLoaded(animDict) do
|
2025-06-18 06:13:19 +02:00
|
|
|
Wait(10)
|
2025-06-18 02:30:02 +02:00
|
|
|
end
|
2025-06-18 06:13:19 +02:00
|
|
|
|
|
|
|
QBCore.Functions.Progressbar("grill_food", "Grille " .. recipe.label .. "...", Config.GrillTime, false, true, {
|
2025-06-18 02:30:02 +02:00
|
|
|
disableMovement = true,
|
|
|
|
disableCarMovement = true,
|
|
|
|
disableMouse = false,
|
|
|
|
disableCombat = true,
|
|
|
|
}, {
|
|
|
|
animDict = animDict,
|
|
|
|
anim = anim,
|
|
|
|
flags = 49,
|
|
|
|
}, {}, {}, function() -- Success
|
2025-06-18 06:13:19 +02:00
|
|
|
Debug("Grillvorgang abgeschlossen")
|
|
|
|
TriggerServerEvent('nordi_bbq:server:GiveGrilledFood', recipe.item, recipe.requires)
|
|
|
|
end, function() -- Cancel
|
|
|
|
Debug("Grillvorgang abgebrochen")
|
|
|
|
QBCore.Functions.Notify("Grillvorgang abgebrochen", "error")
|
2025-06-18 02:30:02 +02:00
|
|
|
end)
|
|
|
|
end
|