1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-06 12:37:47 +02:00
parent 6b4ab46e6c
commit 8a0d378308
3 changed files with 67 additions and 60 deletions

View file

@ -6,7 +6,8 @@ description 'Job-based Vehicle Admin Script for QBCore with ox_lib'
version '2.0.0' version '2.0.0'
shared_scripts { shared_scripts {
'@ox_lib/init.lua' '@ox_lib/init.lua',
'config.lua'
} }
client_scripts { client_scripts {

View file

@ -1,14 +1,18 @@
local QBCore = exports['qb-core']:GetCoreObject() local QBCore = exports['qb-core']:GetCoreObject()
-- Erlaubte Jobs für das Vehicle Admin System -- Lade die Garagen aus dem Hauptsystem
local AllowedJobs = { Citizen.CreateThread(function()
['police'] = true, Wait(1000) -- Warte kurz, damit das Hauptsystem geladen ist
['admin'] = true,
['mechanic'] = true, -- Versuche, die Garagen aus dem Hauptsystem zu laden
['ambulance'] = true, if _G.Config and _G.Config.Zonen then
['cardealer'] = true, Config.Zonen = _G.Config.Zonen
-- Füge hier weitere Jobs hinzu print("[Fahrzeugadmin] Garagen aus dem Hauptsystem geladen: " .. #Config.Zonen .. " Garagen gefunden.")
} else
print("[Fahrzeugadmin] Konnte keine Garagen aus dem Hauptsystem laden, verwende Standard-Garagen.")
end
end)
-- Job Permission Check -- Job Permission Check
local function HasPermission(source) local function HasPermission(source)
@ -22,7 +26,7 @@ local function HasPermission(source)
-- Check if player has allowed job -- Check if player has allowed job
local playerJob = Player.PlayerData.job.name local playerJob = Player.PlayerData.job.name
return AllowedJobs[playerJob] == true return Config.AllowedJobs[playerJob] == true
end end
-- Get all players from database -- Get all players from database
@ -95,13 +99,23 @@ QBCore.Functions.CreateCallback('vehicleadmin:getGarages', function(source, cb)
local garages = {} local garages = {}
-- Verwende die Garagen aus eurem Config -- Verwende die externen Garagen aus dem Garagensystem
if Config.Zonen then
for k, v in pairs(Config.Zonen) do for k, v in pairs(Config.Zonen) do
table.insert(garages, { table.insert(garages, {
name = v.name, name = v.name,
label = v.name -- Ihr könnt hier auch eine Label-Property hinzufügen label = v.name -- Ihr könnt hier auch eine Label-Property hinzufügen
}) })
end end
else
-- Fallback auf Standard-Garagen
for garageName, garageData in pairs(Config.DefaultGarages) do
table.insert(garages, {
name = garageName,
label = garageData.label or garageName
})
end
end
-- Sortiere alphabetisch -- Sortiere alphabetisch
table.sort(garages, function(a, b) table.sort(garages, function(a, b)
@ -172,13 +186,9 @@ RegisterNetEvent('vehicleadmin:moveToGarage', function(plate, garage)
)) ))
-- Log für Discord -- Log für Discord
TriggerEvent('mh_garage:log', { if Config.Log and Config.Log.Enabled then
type = "admin_move", sendToDiscord("Fahrzeugadmin", Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname .. " (" .. Player.PlayerData.job.label .. ") hat Fahrzeug " .. plate .. " in Garage " .. garage .. " gestellt.", "blue")
user = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname, end
citizenid = Player.PlayerData.citizenid,
plate = plate,
garage = garage
})
end end
TriggerClientEvent('ox_lib:notify', src, { TriggerClientEvent('ox_lib:notify', src, {
@ -233,12 +243,9 @@ RegisterNetEvent('vehicleadmin:deleteFromMap', function(plate)
)) ))
-- Log für Discord -- Log für Discord
TriggerEvent('mh_garage:log', { if Config.Log and Config.Log.Enabled then
type = "admin_delete", sendToDiscord("Fahrzeugadmin", Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname .. " (" .. Player.PlayerData.job.label .. ") hat Fahrzeug " .. plate .. " von der Map gelöscht.", "orange")
user = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname, end
citizenid = Player.PlayerData.citizenid,
plate = plate
})
end end
if deleted then if deleted then
@ -320,12 +327,9 @@ RegisterNetEvent('vehicleadmin:repairVehicle', function(plate)
)) ))
-- Log für Discord -- Log für Discord
TriggerEvent('mh_garage:log', { if Config.Log and Config.Log.Enabled then
type = "admin_repair", sendToDiscord("Fahrzeugadmin", Player.PlayerData.charinfo.firstname .. " " .. Player.PlayerData.charinfo.lastname .. " (" .. Player.PlayerData.job.label .. ") hat Fahrzeug " .. plate .. " repariert.", "green")
user = Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname, end
citizenid = Player.PlayerData.citizenid,
plate = plate
})
end end
if affectedRows > 0 then if affectedRows > 0 then
@ -352,6 +356,32 @@ RegisterNetEvent('vehicleadmin:repairVehicle', function(plate)
end) end)
end) end)
-- Discord Log Funktion
function sendToDiscord(title, message, color)
if not Config.Log or not Config.Log.Enabled or not Config.Log.Webhook then return end
local embed = {
{
["title"] = message,
["type"] = "rich",
["color"] = Config.Log.Colors[color] or Config.Log.Colors.blue,
["footer"] = {
["text"] = Config.Log.SystemName or "Fahrzeugadmin",
},
}
}
PerformHttpRequest(Config.Log.Webhook, function(err, text, headers)
if err and err ~= 204 and err ~= 200 then
print("Fehler beim Discord Webhook [" .. tostring(err) .. "]: " .. tostring(text))
end
end, 'POST', json.encode({
username = title .. " - System",
avatar_url = Config.Log.SystemAvatar,
embeds = embed
}), { ['Content-Type'] = 'application/json' })
end
-- Command to open admin menu -- Command to open admin menu
QBCore.Commands.Add('vehicleadmin', 'Öffne Fahrzeug Admin Menu', {}, false, function(source, args) QBCore.Commands.Add('vehicleadmin', 'Öffne Fahrzeug Admin Menu', {}, false, function(source, args)
local src = source local src = source
@ -437,27 +467,3 @@ QBCore.Commands.Add('dealeradmin', 'Öffne Autohändler Fahrzeug Menu', {}, fals
TriggerClientEvent('vehicleadmin:openMenu', src) TriggerClientEvent('vehicleadmin:openMenu', src)
end) end)
-- Erweiterung des Log-Systems für Fahrzeugadmin
AddEventHandler('mh_garage:log', function(data)
local type = data.type
local user = data.user
local citizenid = data.citizenid
local plate = data.plate
local garage = data.garage
local Color = "purple"
local Text = ""
if type == "admin_move" then
Text = user .. " [" .. citizenid .. "] hat Fahrzeug " .. plate .. " in Garage " .. garage .. " gestellt."
Color = "blue"
elseif type == "admin_delete" then
Text = user .. " [" .. citizenid .. "] hat Fahrzeug " .. plate .. " von der Map gelöscht."
Color = "orange"
elseif type == "admin_repair" then
Text = user .. " [" .. citizenid .. "] hat Fahrzeug " .. plate .. " repariert."
Color = "green"
end
sendToDiscord("Fahrzeugadmin", Text, Color)
end)