local QBCore = exports['qb-core']:GetCoreObject() -- Get vehicle state text local function GetStateText(state) if state == 0 then return "🚗 Ausgefahren" elseif state == 1 then return "🏠 In Garage" elseif state == 2 then return "🚫 Beschlagnahmt" else return "❓ Unbekannt" end end -- Get vehicle condition text with color coding local function GetConditionText(value) if value >= 900 then return "🟢 Sehr gut (" .. math.floor(value/10) .. "%)" elseif value >= 700 then return "🟡 Gut (" .. math.floor(value/10) .. "%)" elseif value >= 500 then return "🟠 Mittelmäßig (" .. math.floor(value/10) .. "%)" elseif value >= 300 then return "🔴 Schlecht (" .. math.floor(value/10) .. "%)" else 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, playerJob) QBCore.Functions.TriggerCallback('vehicleadmin:getGarages', function(garages) if not garages then return end local garageOptions = {} for i = 1, #garages do table.insert(garageOptions, { value = garages[i].name, label = garages[i].label }) end -- 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 = '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'} } end local vehicleName = vehicle.name or "Unbekanntes Fahrzeug" local input = lib.inputDialog('Fahrzeug Aktionen - ' .. vehicleName .. ' (' .. vehicle.plate .. ')', { { type = 'select', 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', description = 'Nur für "In Garage stellen" benötigt', options = garageOptions, required = false } }) if input then local action = input[1] local garage = input[2] if action == 'move' then if not garage then lib.notify({ title = 'Fehler', description = 'Bitte wähle eine Garage aus', type = 'error' }) return end TriggerServerEvent('vehicleadmin:moveToGarage', vehicle.plate, garage) elseif action == 'delete' then local alert = lib.alertDialog({ header = 'Fahrzeug löschen', content = 'Bist du sicher, dass du das Fahrzeug ' .. vehicleName .. ' (' .. 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 local alert = lib.alertDialog({ header = 'Fahrzeug reparieren', content = 'Möchtest du das Fahrzeug ' .. vehicleName .. ' (' .. vehicle.plate .. ') vollständig reparieren?', centered = true, cancel = true }) if alert == 'confirm' then TriggerServerEvent('vehicleadmin:repairVehicle', vehicle.plate) end end end end) end -- Show vehicles for selected player local function ShowPlayerVehicles(citizenid, playerName, playerJob) QBCore.Functions.TriggerCallback('vehicleadmin:getPlayerVehicles', function(vehicles) if not vehicles then return end if #vehicles == 0 then lib.notify({ title = 'Keine Fahrzeuge', description = 'Dieser Spieler hat keine Fahrzeuge', type = 'info' }) return end local options = {} for i = 1, #vehicles do local vehicle = vehicles[i] local vehicleName = vehicle.name or "Unbekanntes Fahrzeug" -- 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 -- Parse mods if needed local mods = {} if type(vehicle.mods) == 'string' then mods = json.decode(vehicle.mods) or {} else mods = vehicle.mods or {} end local engineHealth = mods.engineHealth or 1000 local bodyHealth = mods.bodyHealth or 1000 local fuelLevel = mods.fuelLevel or 100 local description = GetStateText(vehicle.state) .. ' | 🏠 ' .. (vehicle.garage or 'Keine Garage') .. '\n🔧 Motor: ' .. GetConditionText(engineHealth) .. ' | 🚗 Karosserie: ' .. GetConditionText(bodyHealth) .. '\n' .. GetFuelText(fuelLevel) table.insert(options, { title = vehicleName .. ' (' .. vehicle.plate .. ')', description = description, icon = icon, iconColor = iconColor, onSelect = function() ShowVehicleActions(vehicle, playerJob) end }) end lib.registerContext({ id = 'vehicle_list', title = '🚗 Fahrzeuge von ' .. playerName, menu = 'player_selection', options = options }) lib.showContext('vehicle_list') end, citizenid) end -- Show player selection menu local function ShowPlayerMenu() QBCore.Functions.TriggerCallback('vehicleadmin:getPlayerJob', function(jobData) if not jobData or not jobData.hasPermission then lib.notify({ title = 'Keine Berechtigung', description = 'Dein Job hat keine Berechtigung für dieses System', type = 'error' }) return 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 }) lib.showContext('player_selection') end) end) end -- Event to open main menu RegisterNetEvent('vehicleadmin:openMenu', function() ShowPlayerMenu() end) -- Export functions for other scripts exports('OpenVehicleAdmin', function() ShowPlayerMenu() end) -- Funktion zum Abrufen der Fahrzeugklasse anhand des Modellnamens function GetVehicleClassFromName(modelName) local modelHash = GetHashKey(modelName) if not IsModelInCdimage(modelHash) then return nil end local vehicleClass = nil -- Wir müssen das Fahrzeug temporär laden, um die Klasse zu bekommen if not HasModelLoaded(modelHash) then RequestModel(modelHash) local timeout = 0 while not HasModelLoaded(modelHash) and timeout < 100 do Wait(10) timeout = timeout + 1 end end if HasModelLoaded(modelHash) then -- Wir erstellen das Fahrzeug außerhalb der Welt, um die Klasse zu bekommen local tempVeh = CreateVehicle(modelHash, 9999.0, 9999.0, 9999.0, 0.0, false, false) if DoesEntityExist(tempVeh) then vehicleClass = GetVehicleClass(tempVeh) DeleteEntity(tempVeh) end SetModelAsNoLongerNeeded(modelHash) end return vehicleClass end