1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-06-18 05:39:08 +02:00
parent 349f167025
commit 271588ccb0
2 changed files with 143 additions and 79 deletions

View file

@ -1,21 +1,36 @@
local QBCore = exports['qb-core']:GetCoreObject() 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 Print Function
local function Debug(msg) local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg) -- Changed from Coffee to Grill print("^2[Grill Debug] ^7" .. msg)
end end
-- Wait for QBCore to be fully initialized
CreateThread(function() CreateThread(function()
while not QBCore do
Wait(100)
end
while not QBCore.Shared or not QBCore.Shared.Items do
Debug("Waiting for QBCore.Shared.Items to be initialized...")
Wait(1000)
end
Debug("Script starting...") Debug("Script starting...")
for _, prop in pairs(Config.GrillProps) do -- Changed from CoffeeProps to GrillProps for _, prop in pairs(Config.GrillProps) do
exports['qb-target']:AddTargetModel(prop, { exports['qb-target']:AddTargetModel(prop, {
options = { options = {
{ {
num = 1, num = 1,
type = "client", type = "client",
event = "nordi_grill:client:OpenMenu", -- Changed event name event = "nordi_grill:client:OpenMenu",
icon = 'fas fa-fire', -- Changed icon icon = 'fas fa-fire',
label = 'Grillen', -- Changed label label = 'Grillen',
} }
}, },
distance = 2.0 distance = 2.0
@ -25,10 +40,10 @@ CreateThread(function()
end) end)
-- Event Handler for opening the menu -- Event Handler for opening the menu
RegisterNetEvent('nordi_grill:client:OpenMenu') -- Changed event name RegisterNetEvent('nordi_grill:client:OpenMenu')
AddEventHandler('nordi_grill:client:OpenMenu', function() -- Changed event name AddEventHandler('nordi_grill:client:OpenMenu', function()
Debug("Opening menu...") Debug("Opening menu...")
OpenGrillMenu() -- Changed function name OpenGrillMenu()
end) end)
function CheckIngredients(requirements) function CheckIngredients(requirements)
@ -49,50 +64,72 @@ 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
-- Add a check to make sure the item exists in QBCore.Shared.Items local itemLabel = item.item -- Default to item name if label not found
if QBCore.Shared.Items[item.item] then
local itemLabel = QBCore.Shared.Items[item.item].label -- Safely check if the item exists in QBCore.Shared.Items
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n" if QBCore.Shared and QBCore.Shared.Items and QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label then
else itemLabel = QBCore.Shared.Items[item.item].label
-- 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
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
end end
QBCore.Functions.Notify(warningText, "error", 5000) QBCore.Functions.Notify(warningText, "error", 5000)
end end
function OpenGrillMenu() function OpenGrillMenu()
Debug("Building menu options...") Debug("Building menu options...")
-- 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 options = {} local options = {}
for _, food in ipairs(Config.GrillOptions) do for _, food in ipairs(Config.GrillOptions) do
-- Make sure food.requires exists
if not food.requires then
Debug("ERROR: food.requires is nil for " .. (food.label or "unknown food"))
goto continue
end
local hasIngredients, missing = CheckIngredients(food.requires) local hasIngredients, missing = CheckIngredients(food.requires)
local description = food.description .. "\n\nBenötigt:" local description = (food.description or "No description") .. "\n\nBenötigt:"
for _, req in ipairs(food.requires) do for _, req in ipairs(food.requires) do
-- Add a check to make sure the item exists in QBCore.Shared.Items -- Make sure req.item exists
if QBCore.Shared.Items[req.item] then if not req.item then
local itemLabel = QBCore.Shared.Items[req.item].label Debug("ERROR: req.item is nil")
local hasItem = QBCore.Functions.HasItem(req.item, req.amount) 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] and QBCore.Shared.Items[req.item].label then
itemLabel = QBCore.Shared.Items[req.item].label
hasItem = QBCore.Functions.HasItem(req.item, req.amount)
else
Debug("Warning: Item " .. req.item .. " not found in QBCore.Shared.Items")
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 .. "x " .. itemLabel .. " " .. status
else
-- Handle the case where the item doesn't exist ::continue_req::
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, {
title = food.label, title = food.label or "Unknown Food",
description = description, description = description,
icon = food.icon, icon = food.icon or "fas fa-question",
onSelect = function() onSelect = function()
local canMake, missingItems = CheckIngredients(food.requires) local canMake, missingItems = CheckIngredients(food.requires)
if canMake then if canMake then
@ -102,30 +139,44 @@ function OpenGrillMenu()
end end
end end
}) })
::continue::
end end
Debug("Showing menu...") Debug("Showing menu with " .. #options .. " options")
-- Safely register and show context
if lib and lib.registerContext then
lib.registerContext({ lib.registerContext({
id = 'grill_menu', id = 'grill_menu',
title = 'Grill', title = 'Grill',
options = options options = options
}) })
if lib.showContext then
lib.showContext('grill_menu') lib.showContext('grill_menu')
else
Debug("ERROR: lib.showContext is not available")
QBCore.Functions.Notify("Fehler beim Anzeigen des Menüs", "error")
end
else
Debug("ERROR: lib.registerContext is not available")
QBCore.Functions.Notify("Fehler beim Erstellen des Menüs", "error")
end
end end
function PrepareFood(selectedFood) -- Changed function name function PrepareFood(selectedFood)
Debug("Starting food preparation...") Debug("Starting food preparation...")
local player = PlayerPedId() local player = PlayerPedId()
local animDict = "amb@prop_human_bbq@male@base" -- Changed animation local animDict = "amb@prop_human_bbq@male@base"
local anim = "base" -- Changed animation local anim = "base"
RequestAnimDict(animDict) RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do while not HasAnimDictLoaded(animDict) do
Wait(0) Wait(0)
end end
QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, { -- Changed text and function name QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, {
disableMovement = true, disableMovement = true,
disableCarMovement = true, disableCarMovement = true,
disableMouse = false, disableMouse = false,
@ -136,7 +187,7 @@ function PrepareFood(selectedFood) -- Changed function name
flags = 49, flags = 49,
}, {}, {}, function() -- Success }, {}, {}, function() -- Success
Debug("Food preparation successful, triggering server event...") Debug("Food preparation successful, triggering server event...")
TriggerServerEvent('grill-script:giveFood', selectedFood.item, selectedFood.requires) -- Changed event name TriggerServerEvent('grill-script:giveFood', selectedFood.item, selectedFood.requires)
end, function() -- Cancelled end, function() -- Cancelled
Debug("Food preparation cancelled") Debug("Food preparation cancelled")
QBCore.Functions.Notify("Zubereitung abgebrochen", "error") QBCore.Functions.Notify("Zubereitung abgebrochen", "error")
@ -144,7 +195,8 @@ function PrepareFood(selectedFood) -- Changed function name
end end
-- Debug Event -- Debug Event
RegisterNetEvent('grill-script:debug') -- Changed event name RegisterNetEvent('grill-script:debug')
AddEventHandler('grill-script:debug', function(msg) AddEventHandler('grill-script:debug', function(msg)
Debug(msg) Debug(msg)
end) end)

View file

@ -2,19 +2,23 @@ local QBCore = exports['qb-core']:GetCoreObject()
-- Debug Print Function -- Debug Print Function
local function Debug(msg) local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg) -- Changed from Coffee to Grill print("^2[Grill Debug] ^7" .. msg)
end end
RegisterNetEvent('grill-script:giveFood') -- Changed event name RegisterNetEvent('grill-script:giveFood')
AddEventHandler('grill-script:giveFood', function(itemName, requirements) -- Changed event name AddEventHandler('grill-script:giveFood', function(itemName, requirements)
Debug("Give food event triggered") -- Changed text Debug("Give food event triggered")
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) local Player = QBCore.Functions.GetPlayer(src)
if Player then if not Player then
Debug("ERROR: Player not found")
return
end
-- Check if the item is in the allowed grill options -- Check if the item is in the allowed grill options
local isValidItem = false local isValidItem = false
for _, food in ipairs(Config.GrillOptions) do -- Changed from CoffeeOptions to GrillOptions for _, food in ipairs(Config.GrillOptions) do
if food.item == itemName then if food.item == itemName then
isValidItem = true isValidItem = true
break break
@ -22,12 +26,13 @@ AddEventHandler('grill-script:giveFood', function(itemName, requirements) -- Ch
end end
if isValidItem then if isValidItem then
Debug("Valid food item requested") -- Changed text Debug("Valid food item requested: " .. itemName)
-- Double-check ingredients -- Double-check ingredients
local hasAllItems = true local hasAllItems = true
for _, requirement in ipairs(requirements) do for _, requirement in ipairs(requirements) do
if not Player.Functions.HasItem(requirement.item, requirement.amount) then if not Player.Functions.HasItem(requirement.item, requirement.amount) then
hasAllItems = false hasAllItems = false
Debug("Player missing item: " .. requirement.item)
break break
end end
end end
@ -42,15 +47,22 @@ AddEventHandler('grill-script:giveFood', function(itemName, requirements) -- Ch
-- Give the finished food -- Give the finished food
Player.Functions.AddItem(itemName, 1) Player.Functions.AddItem(itemName, 1)
-- Safely get the item label
local itemLabel = itemName
if QBCore.Shared.Items[itemName] and QBCore.Shared.Items[itemName].label then
itemLabel = QBCore.Shared.Items[itemName].label
end
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add") TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add")
TriggerClientEvent('QBCore:Notify', src, "Du hast " .. QBCore.Shared.Items[itemName].label .. " gegrillt!", "success") -- Changed text TriggerClientEvent('QBCore:Notify', src, "Du hast " .. itemLabel .. " gegrillt!", "success")
else else
Debug("Player missing required items") Debug("Player missing required items")
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error") TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
end end
else else
Debug("Invalid food item requested: " .. itemName) -- Changed text Debug("Invalid food item requested: " .. itemName)
TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error") -- Changed text TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error")
end
end end
end) end)