1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-06-18 05:33:48 +02:00
parent 0cc6ba6923
commit 349f167025
2 changed files with 28 additions and 13 deletions

View file

@ -49,29 +49,44 @@ function CheckIngredients(requirements)
return hasItems, missingItems return hasItems, missingItems
end end
function ShowMissingIngredientsWarning(missingItems) function ShowMissingIngredientsWarning(missingItems)
local warningText = "Fehlende Zutaten:\n" local warningText = "Fehlende Zutaten:\n"
for _, item in ipairs(missingItems) do for _, item in ipairs(missingItems) do
local itemLabel = QBCore.Shared.Items[item.item].label -- Add a check to make sure the item exists in QBCore.Shared.Items
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n" if QBCore.Shared.Items[item.item] then
local itemLabel = QBCore.Shared.Items[item.item].label
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
else
-- Use the item name if the item doesn't exist in QBCore.Shared.Items
warningText = warningText .. "- " .. item.item .. " (benötigt: " .. item.required .. ")\n"
end
end end
QBCore.Functions.Notify(warningText, "error", 5000) QBCore.Functions.Notify(warningText, "error", 5000)
end end
function OpenGrillMenu() -- Changed function name
function OpenGrillMenu()
Debug("Building menu options...") Debug("Building menu options...")
local options = {} local options = {}
for _, food in ipairs(Config.GrillOptions) do -- Changed from CoffeeOptions to GrillOptions for _, food in ipairs(Config.GrillOptions) do
local hasIngredients, missing = CheckIngredients(food.requires) local hasIngredients, missing = CheckIngredients(food.requires)
local description = food.description .. "\n\nBenötigt:" local description = food.description .. "\n\nBenötigt:"
for _, req in ipairs(food.requires) do for _, req in ipairs(food.requires) do
local itemLabel = QBCore.Shared.Items[req.item].label -- Add a check to make sure the item exists in QBCore.Shared.Items
local hasItem = QBCore.Functions.HasItem(req.item, req.amount) if QBCore.Shared.Items[req.item] then
local status = hasItem and "~g~✓" or "~r~✗" local itemLabel = QBCore.Shared.Items[req.item].label
description = description .. "\n- " .. req.amount .. "x " .. itemLabel .. " " .. status local hasItem = QBCore.Functions.HasItem(req.item, req.amount)
local status = hasItem and "~g~✓" or "~r~✗"
description = description .. "\n- " .. req.amount .. "x " .. itemLabel .. " " .. status
else
-- Handle the case where the item doesn't exist
Debug("Warning: Item " .. req.item .. " not found in QBCore.Shared.Items")
description = description .. "\n- " .. req.amount .. "x " .. req.item .. " (Item not found)"
end
end end
table.insert(options, { table.insert(options, {
@ -81,7 +96,7 @@ function OpenGrillMenu() -- Changed function name
onSelect = function() onSelect = function()
local canMake, missingItems = CheckIngredients(food.requires) local canMake, missingItems = CheckIngredients(food.requires)
if canMake then if canMake then
PrepareFood(food) -- Changed function name PrepareFood(food)
else else
ShowMissingIngredientsWarning(missingItems) ShowMissingIngredientsWarning(missingItems)
end end
@ -91,12 +106,12 @@ function OpenGrillMenu() -- Changed function name
Debug("Showing menu...") Debug("Showing menu...")
lib.registerContext({ lib.registerContext({
id = 'grill_menu', -- Changed ID id = 'grill_menu',
title = 'Grill', -- Changed title title = 'Grill',
options = options options = options
}) })
lib.showContext('grill_menu') -- Changed context ID lib.showContext('grill_menu')
end end
function PrepareFood(selectedFood) -- Changed function name function PrepareFood(selectedFood) -- Changed function name

View file

@ -36,7 +36,7 @@ Config.GrillOptions = {
item = "cooked_bbq_sausages", item = "cooked_bbq_sausages",
icon = "fa-solid fa-hotdog", icon = "fa-solid fa-hotdog",
requires = { requires = {
{item = "raw_sausage", amount = 1}, {item = "raw_sausages", amount = 1},
} }
}, },
} }