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_grill: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 = {} for _, requirement in ipairs(requirements) do local hasItem = QBCore.Functions.HasItem(requirement.item, requirement.amount) if not hasItem then hasItems = false table.insert(missingItems, { item = requirement.item, required = requirement.amount }) end end return hasItems, missingItems end function ShowMissingIngredientsWarning(missingItems) local warningText = "Fehlende Zutaten:\n" for _, item in ipairs(missingItems) do 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" 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.requires then Debug("ERROR: food.requires is nil for " .. (food.label or "unknown food")) goto continue end local hasIngredients, missing = CheckIngredients(food.requires) local description = (food.description or "No description") .. "\n\nBenötigt:" for _, req in ipairs(food.requires) do -- Make sure req.item exists if not req.item then Debug("ERROR: req.item is 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] and QBCore.Shared.Items[req.item].label then itemLabel = QBCore.Shared.Items[req.item].label hasItem = QBCore.Functions.HasItem(req.item, req.amount) else Debug("Warning: Item " .. req.item .. " not found in QBCore.Shared.Items") end local status = hasItem and "~g~✓" or "~r~✗" description = description .. "\n- " .. req.amount .. "x " .. itemLabel .. " " .. status ::continue_req:: end table.insert(options, { title = food.label or "Unknown Food", 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)