forked from Simnation/Main
136 lines
4.6 KiB
Lua
136 lines
4.6 KiB
Lua
![]() |
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
|
||
|
|
||
|
function ShowMissingIngredientsWarning(missingItems)
|
||
|
local warningText = "Fehlende Zutaten:\n"
|
||
|
for _, item in ipairs(missingItems) do
|
||
|
local itemLabel = QBCore.Shared.Items[item.item].label
|
||
|
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
|
||
|
end
|
||
|
|
||
|
QBCore.Functions.Notify(warningText, "error", 5000)
|
||
|
end
|
||
|
|
||
|
function OpenGrillMenu() -- Changed function name
|
||
|
Debug("Building menu options...")
|
||
|
local options = {}
|
||
|
|
||
|
for _, food in ipairs(Config.GrillOptions) do -- Changed from CoffeeOptions to GrillOptions
|
||
|
local hasIngredients, missing = CheckIngredients(food.requires)
|
||
|
local description = food.description .. "\n\nBenötigt:"
|
||
|
|
||
|
for _, req in ipairs(food.requires) do
|
||
|
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
|
||
|
end
|
||
|
|
||
|
table.insert(options, {
|
||
|
title = food.label,
|
||
|
description = description,
|
||
|
icon = food.icon,
|
||
|
onSelect = function()
|
||
|
local canMake, missingItems = CheckIngredients(food.requires)
|
||
|
if canMake then
|
||
|
PrepareFood(food) -- Changed function name
|
||
|
else
|
||
|
ShowMissingIngredientsWarning(missingItems)
|
||
|
end
|
||
|
end
|
||
|
})
|
||
|
end
|
||
|
|
||
|
Debug("Showing menu...")
|
||
|
lib.registerContext({
|
||
|
id = 'grill_menu', -- Changed ID
|
||
|
title = 'Grill', -- Changed title
|
||
|
options = options
|
||
|
})
|
||
|
|
||
|
lib.showContext('grill_menu') -- Changed context ID
|
||
|
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)
|