forked from Simnation/Main
hm
This commit is contained in:
parent
271588ccb0
commit
0a7362cf0b
2 changed files with 74 additions and 16 deletions
|
@ -50,15 +50,29 @@ function CheckIngredients(requirements)
|
||||||
local hasItems = true
|
local hasItems = true
|
||||||
local missingItems = {}
|
local missingItems = {}
|
||||||
|
|
||||||
|
if not requirements then
|
||||||
|
Debug("FEHLER: requirements ist nil")
|
||||||
|
return false, {}
|
||||||
|
end
|
||||||
|
|
||||||
for _, requirement in ipairs(requirements) do
|
for _, requirement in ipairs(requirements) do
|
||||||
local hasItem = QBCore.Functions.HasItem(requirement.item, requirement.amount)
|
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
|
if not hasItem then
|
||||||
hasItems = false
|
hasItems = false
|
||||||
table.insert(missingItems, {
|
table.insert(missingItems, {
|
||||||
item = requirement.item,
|
item = requirement.item,
|
||||||
required = requirement.amount
|
required = amount
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
::continue_req::
|
||||||
end
|
end
|
||||||
|
|
||||||
return hasItems, missingItems
|
return hasItems, missingItems
|
||||||
|
@ -67,6 +81,11 @@ 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
|
||||||
|
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
|
local itemLabel = item.item -- Default to item name if label not found
|
||||||
|
|
||||||
-- Safely check if the item exists in QBCore.Shared.Items
|
-- Safely check if the item exists in QBCore.Shared.Items
|
||||||
|
@ -75,6 +94,8 @@ function ShowMissingIngredientsWarning(missingItems)
|
||||||
end
|
end
|
||||||
|
|
||||||
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
|
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
|
||||||
|
|
||||||
|
::continue_missing::
|
||||||
end
|
end
|
||||||
|
|
||||||
QBCore.Functions.Notify(warningText, "error", 5000)
|
QBCore.Functions.Notify(warningText, "error", 5000)
|
||||||
|
@ -94,18 +115,18 @@ function OpenGrillMenu()
|
||||||
|
|
||||||
for _, food in ipairs(Config.GrillOptions) do
|
for _, food in ipairs(Config.GrillOptions) do
|
||||||
-- Make sure food.requires exists
|
-- Make sure food.requires exists
|
||||||
if not food.requires then
|
if not food or not food.requires then
|
||||||
Debug("ERROR: food.requires is nil for " .. (food.label or "unknown food"))
|
Debug("ERROR: food oder food.requires ist nil für " .. (food.label or "unbekanntes Essen"))
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
local hasIngredients, missing = CheckIngredients(food.requires)
|
local hasIngredients, missing = CheckIngredients(food.requires)
|
||||||
local description = (food.description or "No description") .. "\n\nBenötigt:"
|
local description = (food.description or "Keine Beschreibung") .. "\n\nBenötigt:"
|
||||||
|
|
||||||
for _, req in ipairs(food.requires) do
|
for _, req in ipairs(food.requires) do
|
||||||
-- Make sure req.item exists
|
-- Make sure req.item exists
|
||||||
if not req.item then
|
if not req or not req.item then
|
||||||
Debug("ERROR: req.item is nil")
|
Debug("ERROR: req oder req.item ist nil")
|
||||||
goto continue_req
|
goto continue_req
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,21 +134,23 @@ function OpenGrillMenu()
|
||||||
local hasItem = false
|
local hasItem = false
|
||||||
|
|
||||||
-- Safely check if the item exists in QBCore.Shared.Items
|
-- 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
|
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
|
itemLabel = QBCore.Shared.Items[req.item].label
|
||||||
hasItem = QBCore.Functions.HasItem(req.item, req.amount)
|
end
|
||||||
|
hasItem = QBCore.Functions.HasItem(req.item, req.amount or 1)
|
||||||
else
|
else
|
||||||
Debug("Warning: Item " .. req.item .. " not found in QBCore.Shared.Items")
|
Debug("Warnung: Item " .. req.item .. " nicht in QBCore.Shared.Items gefunden")
|
||||||
end
|
end
|
||||||
|
|
||||||
local status = hasItem and "~g~✓" or "~r~✗"
|
local status = hasItem and "~g~✓" or "~r~✗"
|
||||||
description = description .. "\n- " .. req.amount .. "x " .. itemLabel .. " " .. status
|
description = description .. "\n- " .. (req.amount or 1) .. "x " .. itemLabel .. " " .. status
|
||||||
|
|
||||||
::continue_req::
|
::continue_req::
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(options, {
|
table.insert(options, {
|
||||||
title = food.label or "Unknown Food",
|
title = food.label or "Unbekanntes Essen",
|
||||||
description = description,
|
description = description,
|
||||||
icon = food.icon or "fas fa-question",
|
icon = food.icon or "fas fa-question",
|
||||||
onSelect = function()
|
onSelect = function()
|
||||||
|
@ -200,3 +223,4 @@ AddEventHandler('grill-script:debug', function(msg)
|
||||||
Debug(msg)
|
Debug(msg)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,40 @@
|
||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
|
-- Validate that the items exist in QBCore.Shared.Items
|
||||||
|
CreateThread(function()
|
||||||
|
Wait(2000) -- Wait for QBCore to be fully initialized
|
||||||
|
|
||||||
|
local QBCore = exports['qb-core']:GetCoreObject()
|
||||||
|
if not QBCore or not QBCore.Shared or not QBCore.Shared.Items then
|
||||||
|
print("^1ERROR: QBCore.Shared.Items is not available^7")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check if all required items exist
|
||||||
|
local missingItems = {}
|
||||||
|
|
||||||
|
for _, option in ipairs(Config.GrillOptions) do
|
||||||
|
if not QBCore.Shared.Items[option.item] then
|
||||||
|
table.insert(missingItems, option.item)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, req in ipairs(option.requires) do
|
||||||
|
if not QBCore.Shared.Items[req.item] then
|
||||||
|
table.insert(missingItems, req.item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #missingItems > 0 then
|
||||||
|
print("^1WARNING: The following items are missing from QBCore.Shared.Items:^7")
|
||||||
|
for _, item in ipairs(missingItems) do
|
||||||
|
print("^1- " .. item .. "^7")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print("^2All grill items exist in QBCore.Shared.Items^7")
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Change coffee props to grill props
|
-- Change coffee props to grill props
|
||||||
Config.GrillProps = {
|
Config.GrillProps = {
|
||||||
`prop_bbq_1`,
|
`prop_bbq_1`,
|
||||||
|
@ -12,12 +47,10 @@ Config.GrillProps = {
|
||||||
`bzzz_grill_a`,
|
`bzzz_grill_a`,
|
||||||
`smallbbqtrailer`,
|
`smallbbqtrailer`,
|
||||||
`bigbbqtrailer`,
|
`bigbbqtrailer`,
|
||||||
|
|
||||||
-- Add any other grill props you want to use
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Progressbar duration in ms
|
-- Progressbar duration in ms
|
||||||
Config.ProgressTime = 5000 -- Maybe increase time for grilling
|
Config.ProgressTime = 5000
|
||||||
|
|
||||||
-- Change coffee options to grilling options
|
-- Change coffee options to grilling options
|
||||||
Config.GrillOptions = {
|
Config.GrillOptions = {
|
||||||
|
@ -40,3 +73,4 @@ Config.GrillOptions = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue