161 lines
		
	
	
	
		
			4.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			161 lines
		
	
	
	
		
			4.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
local QBCore = exports['qb-core']:GetCoreObject()
 | 
						|
 | 
						|
-- Debug-Funktion
 | 
						|
local function Debug(msg)
 | 
						|
    print("^2[Grill Debug] ^7" .. msg)
 | 
						|
end
 | 
						|
 | 
						|
-- Warte auf vollständige Initialisierung von QBCore
 | 
						|
CreateThread(function()
 | 
						|
    if not QBCore then
 | 
						|
        Debug("QBCore nicht gefunden, warte...")
 | 
						|
        while not QBCore do
 | 
						|
            QBCore = exports['qb-core']:GetCoreObject()
 | 
						|
            Wait(100)
 | 
						|
        end
 | 
						|
    end
 | 
						|
    
 | 
						|
    Debug("QBCore initialisiert")
 | 
						|
    
 | 
						|
    -- Registriere Grill-Props für qb-target
 | 
						|
    for _, prop in pairs(Config.GrillProps) do
 | 
						|
        Debug("Registriere Target für Prop: " .. tostring(prop))
 | 
						|
        exports['qb-target']:AddTargetModel(prop, {
 | 
						|
            options = {
 | 
						|
                {
 | 
						|
                    type = "client",
 | 
						|
                    event = "nordi_bbq:OpenGrillMenu",
 | 
						|
                    icon = "fas fa-fire",
 | 
						|
                    label = "Grillen",
 | 
						|
                }
 | 
						|
            },
 | 
						|
            distance = 2.0
 | 
						|
        })
 | 
						|
    end
 | 
						|
    
 | 
						|
    Debug("Target-Optionen registriert")
 | 
						|
end)
 | 
						|
 | 
						|
-- Event zum Öffnen des Grill-Menüs
 | 
						|
RegisterNetEvent('nordi_bbq:OpenGrillMenu', function()
 | 
						|
    Debug("Öffne Grill-Menü")
 | 
						|
    OpenGrillMenu()
 | 
						|
end)
 | 
						|
 | 
						|
-- Funktion zum Überprüfen der Zutaten
 | 
						|
function CheckIngredients(recipe)
 | 
						|
    local hasItems = true
 | 
						|
    local missingItems = {}
 | 
						|
    
 | 
						|
    if not recipe or not recipe.requires then
 | 
						|
        Debug("Rezept oder Anforderungen fehlen")
 | 
						|
        return false, {}
 | 
						|
    end
 | 
						|
    
 | 
						|
    for _, item in pairs(recipe.requires) do
 | 
						|
        if not QBCore.Functions.HasItem(item.item, item.amount) then
 | 
						|
            hasItems = false
 | 
						|
            table.insert(missingItems, {
 | 
						|
                item = item.item,
 | 
						|
                amount = item.amount
 | 
						|
            })
 | 
						|
        end
 | 
						|
    end
 | 
						|
    
 | 
						|
    return hasItems, missingItems
 | 
						|
end
 | 
						|
 | 
						|
-- 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"
 | 
						|
    end
 | 
						|
    
 | 
						|
    QBCore.Functions.Notify(text, "error", 5000)
 | 
						|
end
 | 
						|
 | 
						|
-- Funktion zum Öffnen des Grill-Menüs
 | 
						|
function OpenGrillMenu()
 | 
						|
    Debug("Erstelle Grill-Menü")
 | 
						|
    
 | 
						|
    local menuOptions = {}
 | 
						|
    
 | 
						|
    for _, recipe in pairs(Config.GrillRecipes) do
 | 
						|
        local hasIngredients, _ = CheckIngredients(recipe)
 | 
						|
        local status = hasIngredients and "~g~✓" or "~r~✗"
 | 
						|
        
 | 
						|
        -- 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
 | 
						|
        end
 | 
						|
        
 | 
						|
        table.insert(menuOptions, {
 | 
						|
            title = recipe.label,
 | 
						|
            description = description,
 | 
						|
            icon = recipe.icon or "fas fa-drumstick-bite",
 | 
						|
            onSelect = function()
 | 
						|
                StartGrilling(recipe)
 | 
						|
            end
 | 
						|
        })
 | 
						|
    end
 | 
						|
    
 | 
						|
    -- Registriere und zeige das Menü mit ox_lib
 | 
						|
    if lib and lib.registerContext then
 | 
						|
        lib.registerContext({
 | 
						|
            id = 'grill_menu',
 | 
						|
            title = 'Grill',
 | 
						|
            options = menuOptions
 | 
						|
        })
 | 
						|
        
 | 
						|
        lib.showContext('grill_menu')
 | 
						|
    else
 | 
						|
        Debug("FEHLER: ox_lib nicht verfügbar")
 | 
						|
        QBCore.Functions.Notify("Fehler beim Laden des Menüs", "error")
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
-- 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
 | 
						|
    local animDict = "amb@prop_human_bbq@male@base"
 | 
						|
    local anim = "base"
 | 
						|
    
 | 
						|
    RequestAnimDict(animDict)
 | 
						|
    while not HasAnimDictLoaded(animDict) do
 | 
						|
        Wait(10)
 | 
						|
    end
 | 
						|
    
 | 
						|
    QBCore.Functions.Progressbar("grill_food", "Grille " .. recipe.label .. "...", Config.GrillTime, false, true, {
 | 
						|
        disableMovement = true,
 | 
						|
        disableCarMovement = true,
 | 
						|
        disableMouse = false,
 | 
						|
        disableCombat = true,
 | 
						|
    }, {
 | 
						|
        animDict = animDict,
 | 
						|
        anim = anim,
 | 
						|
        flags = 49,
 | 
						|
    }, {}, {}, function() -- Success
 | 
						|
        Debug("Grillvorgang abgeschlossen")
 | 
						|
        TriggerServerEvent('nordi_bbq:server:GiveGrilledFood', recipe.item, recipe.requires)
 | 
						|
    end, function() -- Cancel
 | 
						|
        Debug("Grillvorgang abgebrochen")
 | 
						|
        QBCore.Functions.Notify("Grillvorgang abgebrochen", "error")
 | 
						|
    end)
 | 
						|
end
 |