57 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
	
		
			2.3 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| local QBCore = exports['qb-core']:GetCoreObject()
 | |
| 
 | |
| -- Debug Print Funktion
 | |
| local function Debug(msg)
 | |
|     print("^2[Coffee Debug] ^7" .. msg)
 | |
| end
 | |
| 
 | |
| RegisterNetEvent('coffee-script:giveCoffee')
 | |
| AddEventHandler('coffee-script:giveCoffee', function(itemName, requirements)
 | |
|     Debug("Give coffee event triggered")
 | |
|     local src = source
 | |
|     local Player = QBCore.Functions.GetPlayer(src)
 | |
| 
 | |
|     if Player then
 | |
|         -- Überprüfe ob das Item in den erlaubten Kaffee-Optionen ist
 | |
|         local isValidItem = false
 | |
|         for _, coffee in ipairs(Config.CoffeeOptions) do
 | |
|             if coffee.item == itemName then
 | |
|                 isValidItem = true
 | |
|                 break
 | |
|             end
 | |
|         end
 | |
| 
 | |
|         if isValidItem then
 | |
|             Debug("Valid coffee item requested")
 | |
|             -- Überprüfe nochmal die Zutaten
 | |
|             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")
 | |
|                 -- Entferne die benötigten 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
 | |
| 
 | |
|                 -- Gebe das fertige Getränk
 | |
|                 Player.Functions.AddItem(itemName, 1)
 | |
|                 TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[itemName], "add")
 | |
|                 TriggerClientEvent('QBCore:Notify', src, "Du hast einen " .. QBCore.Shared.Items[itemName].label .. " zubereitet!", "success")
 | |
|             else
 | |
|                 Debug("Player missing required items")
 | |
|                 TriggerClientEvent('QBCore:Notify', src, "Du hast nicht alle benötigten Zutaten!", "error")
 | |
|             end
 | |
|         else
 | |
|             Debug("Invalid coffee item requested: " .. itemName)
 | |
|             TriggerClientEvent('QBCore:Notify', src, "Fehler bei der Kaffeezubereitung!", "error")
 | |
|         end
 | |
|     end
 | |
| end)
 | |
| 
 | 
