forked from Simnation/Main
56 lines
2.4 KiB
Lua
56 lines
2.4 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
|
|
|
|
RegisterNetEvent('grill-script:giveFood') -- Changed event name
|
|
AddEventHandler('grill-script:giveFood', function(itemName, requirements) -- Changed event name
|
|
Debug("Give food event triggered") -- Changed text
|
|
local src = source
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
|
|
if Player then
|
|
-- Check if the item is in the allowed grill options
|
|
local isValidItem = false
|
|
for _, food in ipairs(Config.GrillOptions) do -- Changed from CoffeeOptions to GrillOptions
|
|
if food.item == itemName then
|
|
isValidItem = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if isValidItem then
|
|
Debug("Valid food item requested") -- Changed text
|
|
-- Double-check ingredients
|
|
local hasAllItems = true
|
|
for _, requirement in ipairs(requirements) do
|
|
if not Player.Functions.HasItem(requirement.item, requirement.amount) then
|
|
hasAllItems = false
|
|
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)
|
|
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
|
|
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) -- Changed text
|
|
TriggerClientEvent('QBCore:Notify', src, "Fehler beim Grillen!", "error") -- Changed text
|
|
end
|
|
end
|
|
end)
|