This commit is contained in:
Nordi98 2025-08-06 11:48:14 +02:00
parent a3cb0050da
commit a74a0dda77
3 changed files with 475 additions and 68 deletions

View file

@ -3,33 +3,46 @@ local QBCore = exports['qb-core']:GetCoreObject()
-- Get vehicle state text
local function GetStateText(state)
if state == 0 then
return "Ausgefahren"
return "🚗 Ausgefahren"
elseif state == 1 then
return "In Garage"
return "🏠 In Garage"
elseif state == 2 then
return "Beschlagnahmt"
return "🚫 Beschlagnahmt"
else
return "Unbekannt"
return "Unbekannt"
end
end
-- Get vehicle condition text
-- Get vehicle condition text with color coding
local function GetConditionText(value)
if value >= 900 then
return "Sehr gut"
return "🟢 Sehr gut (" .. math.floor(value/10) .. "%)"
elseif value >= 700 then
return "Gut"
return "🟡 Gut (" .. math.floor(value/10) .. "%)"
elseif value >= 500 then
return "Mittelmäßig"
return "🟠 Mittelmäßig (" .. math.floor(value/10) .. "%)"
elseif value >= 300 then
return "Schlecht"
return "🔴 Schlecht (" .. math.floor(value/10) .. "%)"
else
return "Sehr schlecht"
return "💀 Sehr schlecht (" .. math.floor(value/10) .. "%)"
end
end
-- Get fuel text with color coding
local function GetFuelText(fuel)
if fuel >= 80 then
return "" .. math.floor(fuel) .. "% (Voll)"
elseif fuel >= 50 then
return "" .. math.floor(fuel) .. "% (Gut)"
elseif fuel >= 25 then
return "" .. math.floor(fuel) .. "% (Niedrig)"
else
return "" .. math.floor(fuel) .. "% (Sehr niedrig)"
end
end
-- Show vehicle actions menu
local function ShowVehicleActions(vehicle)
local function ShowVehicleActions(vehicle, playerJob)
QBCore.Functions.TriggerCallback('vehicleadmin:getGarages', function(garages)
if not garages then return end
@ -41,20 +54,59 @@ local function ShowVehicleActions(vehicle)
})
end
local input = lib.inputDialog('Fahrzeug Aktionen - ' .. vehicle.plate, {
-- Different options based on job
local actionOptions = {}
if playerJob.jobName == 'police' then
actionOptions = {
{value = 'move', label = '🏠 In Garage stellen'},
{value = 'delete', label = '🗑️ Von Map löschen'},
{value = 'impound', label = '🚫 Beschlagnahmen'},
{value = 'release', label = '✅ Aus Beschlagnahme freigeben'},
{value = 'repair', label = '🔧 Reparieren'}
}
elseif playerJob.jobName == 'mechanic' then
actionOptions = {
{value = 'move', label = '🏠 In Garage stellen'},
{value = 'repair', label = '🔧 Reparieren'},
{value = 'delete', label = '🗑️ Von Map löschen'}
}
elseif playerJob.jobName == 'ambulance' then
actionOptions = {
{value = 'move', label = '🏠 In Garage stellen'},
{value = 'delete', label = '🗑️ Von Map löschen'},
{value = 'repair', label = '🔧 Reparieren (Notfall)'}
}
elseif playerJob.jobName == 'cardealer' then
actionOptions = {
{value = 'move', label = '🏠 In Garage stellen'},
{value = 'delete', label = '🗑️ Von Map löschen'},
{value = 'repair', label = '🔧 Reparieren'}
}
else -- Admin or other jobs
actionOptions = {
{value = 'move', label = '🏠 In Garage stellen'},
{value = 'delete', label = '🗑️ Von Map löschen'},
{value = 'repair', label = '🔧 Reparieren'},
{value = 'impound', label = '🚫 Beschlagnahmen'},
{value = 'release', label = '✅ Aus Beschlagnahme freigeben'}
}
end
local vehicleLabel = QBCore.Shared.Vehicles[vehicle.vehicle]?.name or vehicle.vehicle
local input = lib.inputDialog('Fahrzeug Aktionen - ' .. vehicleLabel .. ' (' .. vehicle.plate .. ')', {
{
type = 'select',
label = 'Aktion wählen',
options = {
{value = 'move', label = 'In Garage stellen'},
{value = 'delete', label = 'Von Map löschen'},
{value = 'repair', label = 'Reparieren'}
},
label = 'Aktion wählen (' .. playerJob.jobLabel .. ')',
description = 'Wähle eine Aktion für das Fahrzeug',
options = actionOptions,
required = true
},
{
type = 'select',
label = 'Garage auswählen (nur für "In Garage stellen")',
label = 'Garage auswählen',
description = 'Nur für "In Garage stellen" und "Freigeben" benötigt',
options = garageOptions,
required = false
}
@ -75,16 +127,60 @@ local function ShowVehicleActions(vehicle)
end
TriggerServerEvent('vehicleadmin:moveToGarage', vehicle.plate, garage)
elseif action == 'delete' then
TriggerServerEvent('vehicleadmin:deleteFromMap', vehicle.plate)
local alert = lib.alertDialog({
header = 'Fahrzeug löschen',
content = 'Bist du sicher, dass du das Fahrzeug ' .. vehicleLabel .. ' (' .. vehicle.plate .. ') von der Map löschen möchtest?',
centered = true,
cancel = true
})
if alert == 'confirm' then
TriggerServerEvent('vehicleadmin:deleteFromMap', vehicle.plate)
end
elseif action == 'repair' then
TriggerServerEvent('vehicleadmin:repairVehicle', vehicle.plate)
local alert = lib.alertDialog({
header = 'Fahrzeug reparieren',
content = 'Möchtest du das Fahrzeug ' .. vehicleLabel .. ' (' .. vehicle.plate .. ') vollständig reparieren?',
centered = true,
cancel = true
})
if alert == 'confirm' then
TriggerServerEvent('vehicleadmin:repairVehicle', vehicle.plate)
end
elseif action == 'impound' then
local alert = lib.alertDialog({
header = 'Fahrzeug beschlagnahmen',
content = 'Möchtest du das Fahrzeug ' .. vehicleLabel .. ' (' .. vehicle.plate .. ') beschlagnahmen? (500€ Gebühr)',
centered = true,
cancel = true
})
if alert == 'confirm' then
TriggerServerEvent('vehicleadmin:impoundVehicle', vehicle.plate)
end
elseif action == 'release' then
if not garage then
lib.notify({
title = 'Fehler',
description = 'Bitte wähle eine Garage für die Freigabe aus',
type = 'error'
})
return
end
local alert = lib.alertDialog({
header = 'Fahrzeug freigeben',
content = 'Möchtest du das Fahrzeug ' .. vehicleLabel .. ' (' .. vehicle.plate .. ') aus der Beschlagnahme freigeben?',
centered = true,
cancel = true
})
if alert == 'confirm' then
TriggerServerEvent('vehicleadmin:releaseFromImpound', vehicle.plate, garage)
end
end
end
end)
end
-- Show vehicles for selected player
local function ShowPlayerVehicles(citizenid, playerName)
local function ShowPlayerVehicles(citizenid, playerName, playerJob)
QBCore.Functions.TriggerCallback('vehicleadmin:getPlayerVehicles', function(vehicles)
if not vehicles then return end
@ -102,21 +198,44 @@ local function ShowPlayerVehicles(citizenid, playerName)
local vehicle = vehicles[i]
local vehicleLabel = QBCore.Shared.Vehicles[vehicle.vehicle]?.name or vehicle.vehicle
-- Color coding based on state
local icon = 'car'
local iconColor = '#3b82f6'
if vehicle.state == 0 then
icon = 'car-side' -- Ausgefahren
iconColor = '#10b981'
elseif vehicle.state == 1 then
icon = 'warehouse' -- In Garage
iconColor = '#6b7280'
elseif vehicle.state == 2 then
icon = 'ban' -- Beschlagnahmt
iconColor = '#ef4444'
end
local description = GetStateText(vehicle.state) .. ' | 🏠 ' .. (vehicle.garage or 'Keine Garage') ..
'\n🔧 Motor: ' .. GetConditionText(vehicle.engine) .. ' | 🚗 Karosserie: ' .. GetConditionText(vehicle.body) ..
'\n' .. GetFuelText(vehicle.fuel)
if vehicle.depotprice and vehicle.depotprice > 0 then
description = description .. '\n💰 Gebühr: ' .. vehicle.depotprice .. ''
end
table.insert(options, {
title = vehicleLabel .. ' (' .. vehicle.plate .. ')',
description = 'Zustand: ' .. GetStateText(vehicle.state) .. ' | Garage: ' .. (vehicle.garage or 'Keine') ..
'\nMotor: ' .. GetConditionText(vehicle.engine) .. ' | Karosserie: ' .. GetConditionText(vehicle.body) ..
'\nSprit: ' .. math.floor(vehicle.fuel) .. '%',
icon = 'car',
description = description,
icon = icon,
iconColor = iconColor,
onSelect = function()
ShowVehicleActions(vehicle)
ShowVehicleActions(vehicle, playerJob)
end
})
end
lib.registerContext({
id = 'vehicle_list',
title = 'Fahrzeuge von ' .. playerName,
title = '🚗 Fahrzeuge von ' .. playerName,
menu = 'player_selection',
options = options
})
@ -126,36 +245,48 @@ end
-- Show player selection menu
local function ShowPlayerMenu()
QBCore.Functions.TriggerCallback('vehicleadmin:getPlayers', function(players)
if not players then
QBCore.Functions.TriggerCallback('vehicleadmin:getPlayerJob', function(jobData)
if not jobData or not jobData.hasPermission then
lib.notify({
title = 'Fehler',
description = 'Keine Berechtigung oder Fehler beim Laden',
title = 'Keine Berechtigung',
description = 'Dein Job hat keine Berechtigung für dieses System',
type = 'error'
})
return
end
local options = {}
for i = 1, #players do
local player = players[i]
table.insert(options, {
title = player.name,
description = 'Citizen ID: ' .. player.citizenid,
icon = 'user',
onSelect = function()
ShowPlayerVehicles(player.citizenid, player.name)
end
QBCore.Functions.TriggerCallback('vehicleadmin:getPlayers', function(players)
if not players then
lib.notify({
title = 'Fehler',
description = 'Fehler beim Laden der Spieler',
type = 'error'
})
return
end
local options = {}
for i = 1, #players do
local player = players[i]
table.insert(options, {
title = player.name,
description = '🆔 Citizen ID: ' .. player.citizenid,
icon = 'user',
iconColor = '#8b5cf6',
onSelect = function()
ShowPlayerVehicles(player.citizenid, player.name, jobData)
end
})
end
lib.registerContext({
id = 'player_selection',
title = '👥 Fahrzeugverwaltung - ' .. jobData.jobLabel,
options = options
})
end
lib.registerContext({
id = 'player_selection',
title = 'Spieler auswählen',
options = options
})
lib.showContext('player_selection')
lib.showContext('player_selection')
end)
end)
end
@ -163,3 +294,35 @@ end
RegisterNetEvent('vehicleadmin:openMenu', function()
ShowPlayerMenu()
end)
-- Keybind for quick access (optional)
RegisterKeyMapping('vehicleadmin', 'Öffne Fahrzeug Admin Menu', 'keyboard', '')
-- Show help text when menu is opened
RegisterNetEvent('vehicleadmin:showHelp', function()
lib.notify({
title = 'Fahrzeugverwaltung',
description = 'Verwende /vehicleadmin oder die entsprechenden Job-Befehle um das Menu zu öffnen',
type = 'info',
duration = 5000
})
end)
-- Auto-refresh function for real-time updates
local function RefreshCurrentMenu()
-- This can be used to refresh the current menu if needed
-- Implementation depends on your specific needs
end
-- Export functions for other scripts
exports('OpenVehicleAdmin', function()
ShowPlayerMenu()
end)
exports('HasVehicleAdminPermission', function()
local hasPermission = false
QBCore.Functions.TriggerCallback('vehicleadmin:getPlayerJob', function(jobData)
hasPermission = jobData and jobData.hasPermission or false
end)
return hasPermission
end)