local QBCore = exports['qb-core']:GetCoreObject() -- Debug Print Function local function Debug(msg) print("^2[Grill Debug] ^7" .. msg) end RegisterNetEvent('grill-script:giveFood') AddEventHandler('grill-script:giveFood', function(itemName, requirements) Debug("Give food event triggered") local src = source local Player = QBCore.Functions.GetPlayer(src) if not Player then Debug("ERROR: Player not found") return end -- Check if the item is in the allowed grill options local isValidItem = false for _, food in ipairs(Config.GrillOptions) do if food.item == itemName then isValidItem = true break end end if isValidItem then Debug("Valid food item requested: " .. itemName) -- Double-check ingredients local hasAllItems = true for _, requirement in ipairs(requirements) do if not Player.Functions.HasItem(requirement.item, requirement.amount) then hasAllItems = false Debug("Player missing item: " .. requirement.item) break end end if hasAllItems then Debug("Player has all required items") -- Remove required items for _, requirement in ipairs(requirements) do Player.Functions.RemoveItem(requirement.item, requirement.amount) TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove") end -- Give the finished food Player.Functions.AddItem(itemName, 1) -- Safely get the item label local itemLabel = itemName if QBCore.Shared.Items[itemName] and QBCore.Shared.Items[itemName].label then itemLabel = QBCore.Shared.Items[itemName].label end TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add") TriggerClientEvent('QBCore:Notify', src, "Du hast " .. itemLabel .. " gegrillt!", "success") else Debug("Player missing required items") TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error") end else Debug("Invalid food item requested: " .. itemName) TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error") end end)