forked from Simnation/Main
Fix Wartung
This commit is contained in:
parent
b75ab42566
commit
347c2b012b
2 changed files with 50 additions and 32 deletions
|
@ -2,7 +2,11 @@ fx_version 'cerulean'
|
||||||
game 'gta5'
|
game 'gta5'
|
||||||
|
|
||||||
author 'Duck'
|
author 'Duck'
|
||||||
description 'Duck Wartungsscript'
|
description 'Duck Wartung'
|
||||||
|
|
||||||
server_script 'server.lua'
|
|
||||||
shared_script 'config.lua'
|
shared_script 'config.lua'
|
||||||
|
server_script 'server.lua'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
'qb-core' -- Notwendig für Berechtigungen
|
||||||
|
}
|
||||||
|
|
|
@ -1,47 +1,61 @@
|
||||||
|
-- Initialisiere QBCore (kompatibel mit allen QB-Versionen)
|
||||||
local QBCore = nil
|
local QBCore = nil
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while QBCore == nil do
|
|
||||||
TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end)
|
|
||||||
Wait(200)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function DiscordNachricht()
|
|
||||||
if Config.DiscordWebhook == "" then return end
|
|
||||||
|
|
||||||
PerformHttpRequest(Config.DiscordWebhook, function() end, 'POST', json.encode({
|
|
||||||
content = Config.WartungsNachricht
|
|
||||||
}), { ['Content-Type'] = 'application/json' })
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterCommand('wartung', function(source)
|
|
||||||
|
|
||||||
while not QBCore do
|
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)
|
Wait(100)
|
||||||
end
|
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
|
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)
|
local Player = QBCore.Functions.GetPlayer(src)
|
||||||
|
|
||||||
if not Player then
|
if not Player then
|
||||||
print(("^1Error: Player not found (source: %s)^7"):format(src))
|
print("^1ERROR: Spieler-ID "..src.." nicht gefunden!^7")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Berechtigungsprüfung
|
||||||
if not QBCore.Functions.HasPermission(src, Config.ErlaubteRolle) then
|
if not QBCore.Functions.HasPermission(src, Config.ErlaubteRolle) then
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Keine Berechtigung!', 'error')
|
TriggerClientEvent('QBCore:Notify', src, "Keine Berechtigung!", "error")
|
||||||
|
print("^3WARNUNG: "..GetPlayerName(src).." versuchte, Wartung zu starten!^7")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Benachrichtige alle Spieler
|
||||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
for _, playerId in pairs(QBCore.Functions.GetPlayers()) do
|
||||||
TriggerClientEvent('QBCore:Notify', v, 'Wartungsarbeiten beginnen!', 'error')
|
TriggerClientEvent('QBCore:Notify', playerId, "Wartungsarbeiten beginnen!", "error", 10000)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Discord & Logging
|
||||||
DiscordNachricht()
|
DiscordNachricht()
|
||||||
|
TriggerClientEvent('QBCore:Notify', src, "Wartung gestartet!", "success")
|
||||||
TriggerClientEvent('QBCore:Notify', src, 'Wartung angekündigt!', 'success')
|
print("^5[Wartung]^7 Gestartet von "..GetPlayerName(src).." (ID: "..src..")")
|
||||||
print(("^5[Wartung]^7 Wartung wurde von %s gestartet"):format(GetPlayerName(src)))
|
|
||||||
end, false)
|
end, false)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue