1
0
Fork 0
forked from Simnation/Main

neue version

This commit is contained in:
Nordi98 2025-06-18 06:13:19 +02:00
parent 9fecb76a14
commit 616ce8e4f6
4 changed files with 158 additions and 230 deletions

View file

@ -1,205 +1,148 @@
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-Funktion
local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg)
end
-- Wait for QBCore to be fully initialized
-- Warte auf vollständige Initialisierung von QBCore
CreateThread(function()
while not QBCore do
Wait(100)
if not QBCore then
Debug("QBCore nicht gefunden, warte...")
while not QBCore do
QBCore = exports['qb-core']:GetCoreObject()
Wait(100)
end
end
while not QBCore.Shared or not QBCore.Shared.Items do
Debug("Waiting for QBCore.Shared.Items to be initialized...")
Wait(1000)
end
Debug("QBCore initialisiert")
Debug("Script starting...")
-- Registriere Grill-Props für qb-target
for _, prop in pairs(Config.GrillProps) do
Debug("Registriere Target für Prop: " .. tostring(prop))
exports['qb-target']:AddTargetModel(prop, {
options = {
{
num = 1,
type = "client",
event = "nordi_bbq:client:OpenMenu",
icon = 'fas fa-fire',
label = 'Grillen',
event = "nordi_bbq:OpenGrillMenu",
icon = "fas fa-fire",
label = "Grillen",
}
},
distance = 2.0
})
end
Debug("Target options registered")
Debug("Target-Optionen registriert")
end)
-- Event Handler for opening the menu
RegisterNetEvent('nordi_bbq:client:OpenMenu')
AddEventHandler('nordi_bbq:client:OpenMenu', function()
Debug("Opening menu...")
-- Event zum Öffnen des Grill-Menüs
RegisterNetEvent('nordi_bbq:OpenGrillMenu', function()
Debug("Öffne Grill-Menü")
OpenGrillMenu()
end)
function CheckIngredients(requirements)
-- Funktion zum Überprüfen der Zutaten
function CheckIngredients(recipe)
local hasItems = true
local missingItems = {}
if not requirements then
Debug("FEHLER: requirements ist nil")
if not recipe or not recipe.requires then
Debug("Rezept oder Anforderungen fehlen")
return false, {}
end
for _, requirement in ipairs(requirements) do
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
for _, item in pairs(recipe.requires) do
if not QBCore.Functions.HasItem(item.item, item.amount) then
hasItems = false
table.insert(missingItems, {
item = requirement.item,
required = amount
item = item.item,
amount = item.amount
})
end
::continue_req::
end
return hasItems, missingItems
end
function ShowMissingIngredientsWarning(missingItems)
local warningText = "Fehlende Zutaten:\n"
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
-- Safely check if the item exists in QBCore.Shared.Items
if QBCore.Shared and QBCore.Shared.Items and QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label then
itemLabel = QBCore.Shared.Items[item.item].label
end
warningText = warningText .. "- " .. itemLabel .. " (benötigt: " .. item.required .. ")\n"
::continue_missing::
-- Funktion zum Anzeigen fehlender Zutaten
function ShowMissingIngredients(missingItems)
local text = "Fehlende Zutaten:\n"
for _, item in pairs(missingItems) do
local itemLabel = QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label or item.item
text = text .. "- " .. itemLabel .. " (" .. item.amount .. "x)\n"
end
QBCore.Functions.Notify(warningText, "error", 5000)
QBCore.Functions.Notify(text, "error", 5000)
end
-- Funktion zum Öffnen des Grill-Menüs
function OpenGrillMenu()
Debug("Building menu options...")
Debug("Erstelle Grill-Menü")
-- 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 menuOptions = {}
local options = {}
for _, food in ipairs(Config.GrillOptions) do
-- Make sure food.requires exists
if not food or not food.requires then
Debug("ERROR: food oder food.requires ist nil für " .. (food.label or "unbekanntes Essen"))
goto continue
for _, recipe in pairs(Config.GrillRecipes) do
local hasIngredients, _ = CheckIngredients(recipe)
local status = hasIngredients and "~g~✓" or "~r~✗"
-- Erstelle Beschreibung mit Zutaten
local description = recipe.description .. "\n\nZutaten:"
for _, item in pairs(recipe.requires) do
local itemLabel = QBCore.Shared.Items[item.item] and QBCore.Shared.Items[item.item].label or item.item
local hasItem = QBCore.Functions.HasItem(item.item, item.amount)
local itemStatus = hasItem and "~g~✓" or "~r~✗"
description = description .. "\n- " .. item.amount .. "x " .. itemLabel .. " " .. itemStatus
end
local hasIngredients, missing = CheckIngredients(food.requires)
local description = (food.description or "Keine Beschreibung") .. "\n\nBenötigt:"
for _, req in ipairs(food.requires) do
-- Make sure req.item exists
if not req or not req.item then
Debug("ERROR: req oder req.item ist nil")
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] then
if QBCore.Shared.Items[req.item].label then
itemLabel = QBCore.Shared.Items[req.item].label
end
hasItem = QBCore.Functions.HasItem(req.item, req.amount or 1)
else
Debug("Warnung: Item " .. req.item .. " nicht in QBCore.Shared.Items gefunden")
end
local status = hasItem and "~g~✓" or "~r~✗"
description = description .. "\n- " .. (req.amount or 1) .. "x " .. itemLabel .. " " .. status
::continue_req::
end
table.insert(options, {
title = food.label or "Unbekanntes Essen",
table.insert(menuOptions, {
title = recipe.label,
description = description,
icon = food.icon or "fas fa-question",
icon = recipe.icon or "fas fa-drumstick-bite",
onSelect = function()
local canMake, missingItems = CheckIngredients(food.requires)
if canMake then
PrepareFood(food)
else
ShowMissingIngredientsWarning(missingItems)
end
StartGrilling(recipe)
end
})
::continue::
end
Debug("Showing menu with " .. #options .. " options")
-- Safely register and show context
-- Registriere und zeige das Menü mit ox_lib
if lib and lib.registerContext then
lib.registerContext({
id = 'grill_menu',
title = 'Grill',
options = options
options = menuOptions
})
if lib.showContext then
lib.showContext('grill_menu')
else
Debug("ERROR: lib.showContext is not available")
QBCore.Functions.Notify("Fehler beim Anzeigen des Menüs", "error")
end
lib.showContext('grill_menu')
else
Debug("ERROR: lib.registerContext is not available")
QBCore.Functions.Notify("Fehler beim Erstellen des Menüs", "error")
Debug("FEHLER: ox_lib nicht verfügbar")
QBCore.Functions.Notify("Fehler beim Laden des Menüs", "error")
end
end
function PrepareFood(selectedFood)
Debug("Starting food preparation...")
local player = PlayerPedId()
-- Funktion zum Starten des Grillvorgangs
function StartGrilling(recipe)
Debug("Starte Grillvorgang für: " .. recipe.label)
-- Überprüfe Zutaten erneut
local hasIngredients, missingItems = CheckIngredients(recipe)
if not hasIngredients then
ShowMissingIngredients(missingItems)
return
end
-- Animation und Progressbar
local animDict = "amb@prop_human_bbq@male@base"
local anim = "base"
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(0)
Wait(10)
end
QBCore.Functions.Progressbar("grill_food", selectedFood.label.." wird gegrillt...", Config.ProgressTime or 5000, false, true, {
QBCore.Functions.Progressbar("grill_food", "Grille " .. recipe.label .. "...", Config.GrillTime, false, true, {
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
@ -209,18 +152,10 @@ function PrepareFood(selectedFood)
anim = anim,
flags = 49,
}, {}, {}, function() -- Success
Debug("Food preparation successful, triggering server event...")
TriggerServerEvent('grill-script:giveFood', selectedFood.item, selectedFood.requires)
end, function() -- Cancelled
Debug("Food preparation cancelled")
QBCore.Functions.Notify("Zubereitung abgebrochen", "error")
Debug("Grillvorgang abgeschlossen")
TriggerServerEvent('nordi_bbq:server:GiveGrilledFood', recipe.item, recipe.requires)
end, function() -- Cancel
Debug("Grillvorgang abgebrochen")
QBCore.Functions.Notify("Grillvorgang abgebrochen", "error")
end)
end
-- Debug Event
RegisterNetEvent('grill-script:debug')
AddEventHandler('grill-script:debug', function(msg)
Debug(msg)
end)

View file

@ -1,24 +1,51 @@
Config = {}
-- Validate that the items exist in QBCore.Shared.Items
-- Grill-Props (Standard-GTA-Props)
Config.GrillProps = {
"prop_bbq_1",
"prop_bbq_2",
"prop_bbq_3",
"prop_bbq_4",
"prop_bbq_5"
}
-- Zeit zum Grillen (in ms)
Config.GrillTime = 5000
-- Grill-Rezepte
Config.GrillRecipes = {
{
label = "Steak",
description = "Ein perfekt gegrilltes Steak",
item = "cooked_bbq_ribeye",
icon = "fas fa-drumstick-bite",
requires = {
{item = "rawmeat", amount = 1}
}
}
-- Hier kannst du weitere Rezepte hinzufügen
}
-- Überprüfe, ob alle Items existieren
CreateThread(function()
Wait(2000) -- Wait for QBCore to be fully initialized
Wait(5000) -- Warte auf vollständige Initialisierung
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")
print("^1FEHLER: QBCore.Shared.Items nicht verfügbar^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)
-- Überprüfe Rezept-Items
for _, recipe in pairs(Config.GrillRecipes) do
if not QBCore.Shared.Items[recipe.item] then
table.insert(missingItems, recipe.item)
end
for _, req in ipairs(option.requires) do
-- Überprüfe Zutaten
for _, req in pairs(recipe.requires) do
if not QBCore.Shared.Items[req.item] then
table.insert(missingItems, req.item)
end
@ -26,37 +53,13 @@ CreateThread(function()
end
if #missingItems > 0 then
print("^1WARNING: The following items are missing from QBCore.Shared.Items:^7")
print("^1WARNUNG: Folgende Items fehlen in 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")
print("^2Alle Grill-Items existieren in QBCore.Shared.Items^7")
end
end)
-- Change coffee props to grill props
Config.GrillProps = {
`prop_bbq_1`,
`prop_bbq_2`,
`prop_bbq_3`,
`prop_bbq_4`,
`prop_bbq_5`,
}
-- Progressbar duration in ms
Config.ProgressTime = 5000
-- Change coffee options to grilling options
Config.GrillOptions = {
{
label = "Steak",
description = "Ein perfekt gegrilltes Steak",
item = "cooked_bbq_ribeye",
icon = "fa-solid fa-drumstick-bite",
requires = {
{item = "rawmeat", amount = 1},
}
},
}

View file

@ -1,7 +1,7 @@
fx_version 'cerulean'
game 'gta5'
description 'Grill mit qb_target'
description 'Grill-Script'
author 'Nordi'
version '1.0.0'

View file

@ -1,68 +1,58 @@
local QBCore = exports['qb-core']:GetCoreObject()
-- Debug Print Function
-- Debug-Funktion
local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg)
end
RegisterNetEvent('grill-script:giveFood')
AddEventHandler('grill-script:giveFood', function(itemName, requirements)
Debug("Give food event triggered")
-- Event zum Geben des gegrillten Essens
RegisterNetEvent('nordi_bbq:server:GiveGrilledFood', function(itemName, requirements)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
if not Player then
Debug("ERROR: Player not found")
Debug("Spieler nicht gefunden")
return
end
-- Check if the item is in the allowed grill options
local isValidItem = false
for _, food in ipairs(Config.GrillOptions) do
if food.item == itemName then
isValidItem = true
-- Überprüfe, ob das Item in den erlaubten Rezepten ist
local validRecipe = false
for _, recipe in pairs(Config.GrillRecipes) do
if recipe.item == itemName then
validRecipe = true
break
end
end
if isValidItem then
Debug("Valid food item requested: " .. itemName)
-- Double-check ingredients
local hasAllItems = true
for _, requirement in ipairs(requirements) do
if not Player.Functions.HasItem(requirement.item, requirement.amount) then
hasAllItems = false
Debug("Player missing item: " .. requirement.item)
break
end
end
if hasAllItems then
Debug("Player has all required items")
-- Remove required items
for _, requirement in ipairs(requirements) do
Player.Functions.RemoveItem(requirement.item, requirement.amount)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove")
end
-- Give the finished food
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('QBCore:Notify', src, "Du hast " .. itemLabel .. " gegrillt!", "success")
else
Debug("Player missing required items")
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
end
else
Debug("Invalid food item requested: " .. itemName)
if not validRecipe then
Debug("Ungültiges Rezept: " .. itemName)
TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error")
return
end
-- Überprüfe Zutaten
local hasAllItems = true
for _, requirement in pairs(requirements) do
if not Player.Functions.HasItem(requirement.item, requirement.amount) then
hasAllItems = false
break
end
end
if hasAllItems then
-- Entferne Zutaten
for _, requirement in pairs(requirements) do
Player.Functions.RemoveItem(requirement.item, requirement.amount)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[requirement.item], "remove")
end
-- Gib das fertige Essen
Player.Functions.AddItem(itemName, 1)
TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add")
local itemLabel = QBCore.Shared.Items[itemName] and QBCore.Shared.Items[itemName].label or itemName
TriggerClientEvent('QBCore:Notify', src, "Du hast " .. itemLabel .. " gegrillt!", "success")
else
TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
end
end)