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

View file

@ -1,24 +1,51 @@
Config = {} 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() CreateThread(function()
Wait(2000) -- Wait for QBCore to be fully initialized Wait(5000) -- Warte auf vollständige Initialisierung
local QBCore = exports['qb-core']:GetCoreObject() local QBCore = exports['qb-core']:GetCoreObject()
if not QBCore or not QBCore.Shared or not QBCore.Shared.Items then 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 return
end end
-- Check if all required items exist
local missingItems = {} local missingItems = {}
for _, option in ipairs(Config.GrillOptions) do -- Überprüfe Rezept-Items
if not QBCore.Shared.Items[option.item] then for _, recipe in pairs(Config.GrillRecipes) do
table.insert(missingItems, option.item) if not QBCore.Shared.Items[recipe.item] then
table.insert(missingItems, recipe.item)
end 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 if not QBCore.Shared.Items[req.item] then
table.insert(missingItems, req.item) table.insert(missingItems, req.item)
end end
@ -26,37 +53,13 @@ CreateThread(function()
end end
if #missingItems > 0 then 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 for _, item in ipairs(missingItems) do
print("^1- " .. item .. "^7") print("^1- " .. item .. "^7")
end end
else else
print("^2All grill items exist in QBCore.Shared.Items^7") print("^2Alle Grill-Items existieren in QBCore.Shared.Items^7")
end end
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' fx_version 'cerulean'
game 'gta5' game 'gta5'
description 'Grill mit qb_target' description 'Grill-Script'
author 'Nordi' author 'Nordi'
version '1.0.0' version '1.0.0'

View file

@ -1,68 +1,58 @@
local QBCore = exports['qb-core']:GetCoreObject() local QBCore = exports['qb-core']:GetCoreObject()
-- Debug Print Function -- Debug-Funktion
local function Debug(msg) local function Debug(msg)
print("^2[Grill Debug] ^7" .. msg) print("^2[Grill Debug] ^7" .. msg)
end end
RegisterNetEvent('grill-script:giveFood') -- Event zum Geben des gegrillten Essens
AddEventHandler('grill-script:giveFood', function(itemName, requirements) RegisterNetEvent('nordi_bbq:server:GiveGrilledFood', function(itemName, requirements)
Debug("Give food event triggered")
local src = source local src = source
local Player = QBCore.Functions.GetPlayer(src) local Player = QBCore.Functions.GetPlayer(src)
if not Player then if not Player then
Debug("ERROR: Player not found") Debug("Spieler nicht gefunden")
return return
end end
-- Check if the item is in the allowed grill options -- Überprüfe, ob das Item in den erlaubten Rezepten ist
local isValidItem = false local validRecipe = false
for _, food in ipairs(Config.GrillOptions) do for _, recipe in pairs(Config.GrillRecipes) do
if food.item == itemName then if recipe.item == itemName then
isValidItem = true validRecipe = true
break break
end end
end end
if isValidItem then if not validRecipe then
Debug("Valid food item requested: " .. itemName) Debug("Ungültiges Rezept: " .. 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)
TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error") 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
end) end)