local QBCore = exports['qb-core']:GetCoreObject() -- Check if lib exists (ox_lib) if not lib then print("^1ERROR: lib is not defined. Make sure ox_lib is properly installed and loaded.^7") end -- Debug Print Function local function Debug(msg) print("^2[Grill Debug] ^7" .. msg) end -- Wait for QBCore to be fully initialized CreateThread(function() while not QBCore do Wait(100) end while not QBCore.Shared or not QBCore.Shared.Items do Debug("Waiting for QBCore.Shared.Items to be initialized...") Wait(1000) end Debug("Script starting...") for _, prop in pairs(Config.GrillProps) do exports['qb-target']:AddTargetModel(prop, { options = { { num = 1, type = "client", event = "nordi_bbq:client:OpenMenu", icon = 'fas fa-fire', label = 'Grillen', } }, distance = 2.0 }) end Debug("Target options registered") end) -- Event Handler for opening the menu RegisterNetEvent('nordi_grill:client:OpenMenu') AddEventHandler('nordi_grill:client:OpenMenu', function() Debug("Opening menu...") OpenGrillMenu() end) function CheckIngredients(requirements) local hasItems = true local missingItems = {} if not requirements then Debug("FEHLER: requirements ist nil") return false, {} end for _, requirement in ipairs(requirements) do if not requirement or not requirement.item then Debug("FEHLER: requirement oder requirement.item ist nil") hasItems = false goto continue_req end local amount = requirement.amount or 1 local hasItem = QBCore.Functions.HasItem(requirement.item, amount) if not hasItem then hasItems = false table.insert(missingItems, { item = requirement.item, required = amount }) end ::continue_req:: end return hasItems, missingItems end function ShowMissingIngredientsWarning(missingItems) local warningText = "Fehlende Zutaten:\n" for _, item in ipairs(missingItems) do if not item or not item.item then Debug("FEHLER: item oder item.item ist nil") goto continue_missing end local itemLabel = item.item -- Default to item name if label not found -- Safely check if the item exists in QBCore.Shared.Items if QBCore.Shared and QBCore.Shared.Items and QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label then itemLabel = QBCore.Shared.Items[item.item].label end warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n" ::continue_missing:: end QBCore.Functions.Notify(warningText, "error", 5000) end function OpenGrillMenu() Debug("Building menu options...") -- Make sure Config.GrillOptions exists if not Config or not Config.GrillOptions then Debug("ERROR: Config.GrillOptions is nil") QBCore.Functions.Notify("Fehler beim Laden des Grillmenüs", "error") return end local options = {} for _, food in ipairs(Config.GrillOptions) do -- Make sure food.requires exists if not food or not food.requires then Debug("ERROR: food oder food.requires ist nil für " .. (food.label or "unbekanntes Essen")) goto continue end local hasIngredients, missing = CheckIngredients(food.requires) local description = (food.description or "Keine Beschreibung") .. "\n\nBenötigt:" for _, req in ipairs(food.requires) do -- Make sure req.item exists if not req or not req.item then Debug("ERROR: req oder req.item ist nil") goto continue_req end local itemLabel = req.item -- Default to item name if label not found local hasItem = false -- Safely check if the item exists in QBCore.Shared.Items if QBCore.Shared and QBCore.Shared.Items and QBCore.Shared.Items[req.item] then if QBCore.Shared.Items[req.item].label then itemLabel = QBCore.Shared.Items[req.item].label end hasItem = QBCore.Functions.HasItem(req.item, req.amount or 1) else Debug("Warnung: Item " .. req.item .. " nicht in QBCore.Shared.Items gefunden") end local status = hasItem and "~g~✓" or "~r~✗" description = description .. "\n- " .. (req.amount or 1) .. "x " .. itemLabel .. " " .. status ::continue_req:: end table.insert(options, { title = food.label or "Unbekanntes Essen", description = description, icon = food.icon or "fas fa-question", onSelect = function() local canMake, missingItems = CheckIngredients(food.requires) if canMake then PrepareFood(food) else ShowMissingIngredientsWarning(missingItems) end end }) ::continue:: end Debug("Showing menu with " .. #options .. " options") -- Safely register and show context if lib and lib.registerContext then lib.registerContext({ id = 'grill_menu', title = 'Grill', options = options }) if lib.showContext then lib.showContext('grill_menu') else Debug("ERROR: lib.showContext is not available") QBCore.Functions.Notify("Fehler beim Anzeigen des Menüs", "error") end else Debug("ERROR: lib.registerContext is not available") QBCore.Functions.Notify("Fehler beim Erstellen des Menüs", "error") end end function PrepareFood(selectedFood) Debug("Starting food preparation...") local player = PlayerPedId() local animDict = "amb@prop_human_bbq@male@base" local anim = "base" RequestAnimDict(animDict) while not HasAnimDictLoaded(animDict) do Wait(0) end QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, { disableMovement = true, disableCarMovement = true, disableMouse = false, disableCombat = true, }, { animDict = animDict, anim = anim, flags = 49, }, {}, {}, function() -- Success Debug("Food preparation successful, triggering server event...") TriggerServerEvent('grill-script:giveFood', selectedFood.item, selectedFood.requires) end, function() -- Cancelled Debug("Food preparation cancelled") QBCore.Functions.Notify("Zubereitung abgebrochen", "error") end) end -- Debug Event RegisterNetEvent('grill-script:debug') AddEventHandler('grill-script:debug', function(msg) Debug(msg) end)