1
0
Fork 0
forked from Simnation/Main
Main/resources/[inventory]/nordi_bbq/client.lua

151 lines
5.2 KiB
Lua
Raw Normal View History

2025-06-18 02:30:02 +02:00
local QBCore = exports['qb-core']:GetCoreObject()
-- Debug Print Function
local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg) -- Changed from Coffee to Grill
end
CreateThread(function()
Debug("Script starting...")
for _, prop in pairs(Config.GrillProps) do -- Changed from CoffeeProps to GrillProps
exports['qb-target']:AddTargetModel(prop, {
options = {
{
num = 1,
type = "client",
event = "nordi_grill:client:OpenMenu", -- Changed event name
icon = 'fas fa-fire', -- Changed icon
label = 'Grillen', -- Changed label
}
},
distance = 2.0
})
end
Debug("Target options registered")
end)
-- Event Handler for opening the menu
RegisterNetEvent('nordi_grill:client:OpenMenu') -- Changed event name
AddEventHandler('nordi_grill:client:OpenMenu', function() -- Changed event name
Debug("Opening menu...")
OpenGrillMenu() -- Changed function name
end)
function CheckIngredients(requirements)
local hasItems = true
local missingItems = {}
for _, requirement in ipairs(requirements) do
local hasItem = QBCore.Functions.HasItem(requirement.item, requirement.amount)
if not hasItem then
hasItems = false
table.insert(missingItems, {
item = requirement.item,
required = requirement.amount
})
end
end
return hasItems, missingItems
end
2025-06-18 05:33:48 +02:00
2025-06-18 02:30:02 +02:00
function ShowMissingIngredientsWarning(missingItems)
local warningText = "Fehlende Zutaten:\n"
for _, item in ipairs(missingItems) do
2025-06-18 05:33:48 +02:00
-- Add a check to make sure the item exists in QBCore.Shared.Items
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
2025-06-18 02:30:02 +02:00
end
QBCore.Functions.Notify(warningText, "error", 5000)
end
2025-06-18 05:33:48 +02:00
function OpenGrillMenu()
2025-06-18 02:30:02 +02:00
Debug("Building menu options...")
local options = {}
2025-06-18 05:33:48 +02:00
for _, food in ipairs(Config.GrillOptions) do
2025-06-18 02:30:02 +02:00
local hasIngredients, missing = CheckIngredients(food.requires)
local description = food.description .. "\n\nBenötigt:"
for _, req in ipairs(food.requires) do
2025-06-18 05:33:48 +02:00
-- Add a check to make sure the item exists in QBCore.Shared.Items
if QBCore.Shared.Items[req.item] then
local itemLabel = QBCore.Shared.Items[req.item].label
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
2025-06-18 02:30:02 +02:00
end
table.insert(options, {
title = food.label,
description = description,
icon = food.icon,
onSelect = function()
local canMake, missingItems = CheckIngredients(food.requires)
if canMake then
2025-06-18 05:33:48 +02:00
PrepareFood(food)
2025-06-18 02:30:02 +02:00
else
ShowMissingIngredientsWarning(missingItems)
end
end
})
end
Debug("Showing menu...")
lib.registerContext({
2025-06-18 05:33:48 +02:00
id = 'grill_menu',
title = 'Grill',
2025-06-18 02:30:02 +02:00
options = options
})
2025-06-18 05:33:48 +02:00
lib.showContext('grill_menu')
2025-06-18 02:30:02 +02:00
end
function PrepareFood(selectedFood) -- Changed function name
Debug("Starting food preparation...")
local player = PlayerPedId()
local animDict = "amb@prop_human_bbq@male@base" -- Changed animation
local anim = "base" -- Changed animation
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(0)
end
QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, { -- Changed text and function name
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
animDict = animDict,
anim = anim,
flags = 49,
}, {}, {}, function() -- Success
Debug("Food preparation successful, triggering server event...")
TriggerServerEvent('grill-script:giveFood', selectedFood.item, selectedFood.requires) -- Changed event name
end, function() -- Cancelled
Debug("Food preparation cancelled")
QBCore.Functions.Notify("Zubereitung abgebrochen", "error")
end)
end
-- Debug Event
RegisterNetEvent('grill-script:debug') -- Changed event name
AddEventHandler('grill-script:debug', function(msg)
Debug(msg)
end)