61 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| -- Initialisiere QBCore (kompatibel mit allen QB-Versionen)
 | |
| local QBCore = nil
 | |
| CreateThread(function()
 | |
|     while not QBCore do
 | |
|         QBCore = exports['qb-core']:GetCoreObject() -- Funktioniert mit QB v2/v4
 | |
|         if not QBCore then
 | |
|             TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end) -- Fallback für ältere QB-Versionen
 | |
|         end
 | |
|         Wait(100)
 | |
|     end
 | |
|     print("[Wartung] QBCore erfolgreich initialisiert!") -- Debug
 | |
| end)
 | |
| 
 | |
| -- Discord-Webhook-Funktion
 | |
| local function DiscordNachricht()
 | |
|     if Config.DiscordWebhook == "" or Config.DiscordWebhook == "HIER_WEBHOOK_EINFÜGEN" then
 | |
|         print("^1ERROR: Kein Discord-Webhook in config.lua gesetzt!^7")
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     PerformHttpRequest(Config.DiscordWebhook, function(err, text, headers)
 | |
|         if err == 200 then
 | |
|             print("^2Discord-Nachricht erfolgreich gesendet!^7")
 | |
|         else
 | |
|             print("^1Fehler beim Senden an Discord (Code "..err.."):^7", text)
 | |
|         end
 | |
|     end, 'POST', json.encode({content = Config.WartungsNachricht}), { ['Content-Type'] = 'application/json' })
 | |
| end
 | |
| 
 | |
| -- Hauptbefehl
 | |
| RegisterCommand('wartung', function(source)
 | |
|     local src = source
 | |
|     if not QBCore then
 | |
|         print("^1ERROR: QBCore nicht initialisiert!^7")
 | |
|         TriggerClientEvent('QBCore:Notify', src, "Systemfehler: QBCore nicht bereit.", "error")
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     local Player = QBCore.Functions.GetPlayer(src)
 | |
|     if not Player then
 | |
|         print("^1ERROR: Spieler-ID "..src.." nicht gefunden!^7")
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     -- Berechtigungsprüfung
 | |
|     if not QBCore.Functions.HasPermission(src, Config.ErlaubteRolle) then
 | |
|         TriggerClientEvent('QBCore:Notify', src, "Keine Berechtigung!", "error")
 | |
|         print("^3WARNUNG: "..GetPlayerName(src).." versuchte, Wartung zu starten!^7")
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     -- Benachrichtige alle Spieler
 | |
|     for _, playerId in pairs(QBCore.Functions.GetPlayers()) do
 | |
|         TriggerClientEvent('QBCore:Notify', playerId, "Wartungsarbeiten beginnen!", "error", 10000)
 | |
|     end
 | |
| 
 | |
|     -- Discord & Logging
 | |
|     DiscordNachricht()
 | |
|     TriggerClientEvent('QBCore:Notify', src, "Wartung gestartet!", "success")
 | |
|     print("^5[Wartung]^7 Gestartet von "..GetPlayerName(src).." (ID: "..src..")")
 | |
| end, false)
 | 
