1
0
Fork 0
forked from Simnation/Main

neue version

This commit is contained in:
Nordi98 2025-06-18 06:13:19 +02:00
parent 9fecb76a14
commit 616ce8e4f6
4 changed files with 158 additions and 230 deletions

View file

@ -1,205 +1,148 @@
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
-- Debug-Funktion
local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg)
end
-- Wait for QBCore to be fully initialized
-- Warte auf vollständige Initialisierung von QBCore
CreateThread(function()
while not QBCore do
Wait(100)
if not QBCore then
Debug("QBCore nicht gefunden, warte...")
while not QBCore do
QBCore = exports['qb-core']:GetCoreObject()
Wait(100)
end
end
while not QBCore.Shared or not QBCore.Shared.Items do
Debug("Waiting for QBCore.Shared.Items to be initialized...")
Wait(1000)
end
Debug("QBCore initialisiert")
Debug("Script starting...")
-- 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 = {
{
num = 1,
type = "client",
event = "nordi_bbq:client:OpenMenu",
icon = 'fas fa-fire',
label = 'Grillen',
event = "nordi_bbq:OpenGrillMenu",
icon = "fas fa-fire",
label = "Grillen",
}
},
distance = 2.0
})
end
Debug("Target options registered")
Debug("Target-Optionen registriert")
end)
-- Event Handler for opening the menu
RegisterNetEvent('nordi_bbq:client:OpenMenu')
AddEventHandler('nordi_bbq:client:OpenMenu', function()
Debug("Opening menu...")
-- Event zum Öffnen des Grill-Menüs
RegisterNetEvent('nordi_bbq:OpenGrillMenu', function()
Debug("Öffne Grill-Menü")
OpenGrillMenu()
end)
function CheckIngredients(requirements)
-- Funktion zum Überprüfen der Zutaten
function CheckIngredients(recipe)
local hasItems = true
local missingItems = {}
if not requirements then
Debug("FEHLER: requirements ist nil")
if not recipe or not recipe.requires then
Debug("Rezept oder Anforderungen fehlen")
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
for _, item in pairs(recipe.requires) do
if not QBCore.Functions.HasItem(item.item, item.amount) then
hasItems = false
table.insert(missingItems, {
item = requirement.item,
required = amount
item = item.item,
amount = item.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::
-- 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(warningText, "error", 5000)
QBCore.Functions.Notify(text, "error", 5000)
end
-- Funktion zum Öffnen des Grill-Menüs
function OpenGrillMenu()
Debug("Building menu options...")
Debug("Erstelle Grill-Menü")
-- 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 menuOptions = {}
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
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
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",
table.insert(menuOptions, {
title = recipe.label,
description = description,
icon = food.icon or "fas fa-question",
icon = recipe.icon or "fas fa-drumstick-bite",
onSelect = function()
local canMake, missingItems = CheckIngredients(food.requires)
if canMake then
PrepareFood(food)
else
ShowMissingIngredientsWarning(missingItems)
end
StartGrilling(recipe)
end
})
::continue::
end
Debug("Showing menu with " .. #options .. " options")
-- Safely register and show context
-- Registriere und zeige das Menü mit ox_lib
if lib and lib.registerContext then
lib.registerContext({
id = 'grill_menu',
title = 'Grill',
options = options
options = menuOptions
})
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
lib.showContext('grill_menu')
else
Debug("ERROR: lib.registerContext is not available")
QBCore.Functions.Notify("Fehler beim Erstellen des Menüs", "error")
Debug("FEHLER: ox_lib nicht verfügbar")
QBCore.Functions.Notify("Fehler beim Laden des Menüs", "error")
end
end
function PrepareFood(selectedFood)
Debug("Starting food preparation...")
local player = PlayerPedId()
-- 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(0)
Wait(10)
end
QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, {
QBCore.Functions.Progressbar("grill_food", "Grille " .. recipe.label .. "...", Config.GrillTime, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
@ -209,18 +152,10 @@ function PrepareFood(selectedFood)
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")
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
-- Debug Event
RegisterNetEvent('grill-script:debug')
AddEventHandler('grill-script:debug', function(msg)
Debug(msg)
end)