ed
This commit is contained in:
		
							parent
							
								
									a3cb0050da
								
							
						
					
					
						commit
						a74a0dda77
					
				
					 3 changed files with 475 additions and 68 deletions
				
			
		| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,9 @@
 | 
			
		|||
fx_version 'cerulean'
 | 
			
		||||
game 'gta5'
 | 
			
		||||
 | 
			
		||||
author 'YourName'
 | 
			
		||||
description 'Vehicle Admin Script for QBCore'
 | 
			
		||||
version '1.0.0'
 | 
			
		||||
author 'VehicleAdmin'
 | 
			
		||||
description 'Job-based Vehicle Admin Script for QBCore with ox_lib'
 | 
			
		||||
version '2.0.0'
 | 
			
		||||
 | 
			
		||||
shared_scripts {
 | 
			
		||||
    '@ox_lib/init.lua'
 | 
			
		||||
| 
						 | 
				
			
			@ -23,3 +23,5 @@ dependencies {
 | 
			
		|||
    'ox_lib',
 | 
			
		||||
    'oxmysql'
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
lua54 'yes'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,15 +1,33 @@
 | 
			
		|||
local QBCore = exports['qb-core']:GetCoreObject()
 | 
			
		||||
 | 
			
		||||
-- Admin Permission Check
 | 
			
		||||
local function IsAdmin(source)
 | 
			
		||||
-- Erlaubte Jobs für das Vehicle Admin System
 | 
			
		||||
local AllowedJobs = {
 | 
			
		||||
    ['police'] = true,
 | 
			
		||||
    ['admin'] = true,
 | 
			
		||||
    ['mechanic'] = true,
 | 
			
		||||
    ['ambulance'] = true,
 | 
			
		||||
    ['cardealer'] = true,
 | 
			
		||||
    -- Füge hier weitere Jobs hinzu
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
-- Job Permission Check
 | 
			
		||||
local function HasPermission(source)
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(source)
 | 
			
		||||
    if not Player then return false end
 | 
			
		||||
    return QBCore.Functions.HasPermission(source, 'admin') or Player.PlayerData.job.name == 'admin'
 | 
			
		||||
    
 | 
			
		||||
    -- Check if player has admin permission
 | 
			
		||||
    if QBCore.Functions.HasPermission(source, 'admin') then
 | 
			
		||||
        return true
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Check if player has allowed job
 | 
			
		||||
    local playerJob = Player.PlayerData.job.name
 | 
			
		||||
    return AllowedJobs[playerJob] == true
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- Get all players from database
 | 
			
		||||
QBCore.Functions.CreateCallback('vehicleadmin:getPlayers', function(source, cb)
 | 
			
		||||
    if not IsAdmin(source) then
 | 
			
		||||
    if not HasPermission(source) then
 | 
			
		||||
        cb(false)
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +47,7 @@ end)
 | 
			
		|||
 | 
			
		||||
-- Get vehicles for specific player
 | 
			
		||||
QBCore.Functions.CreateCallback('vehicleadmin:getPlayerVehicles', function(source, cb, citizenid)
 | 
			
		||||
    if not IsAdmin(source) then
 | 
			
		||||
    if not HasPermission(source) then
 | 
			
		||||
        cb(false)
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -38,7 +56,6 @@ QBCore.Functions.CreateCallback('vehicleadmin:getPlayerVehicles', function(sourc
 | 
			
		|||
        local vehicles = {}
 | 
			
		||||
        for i = 1, #result do
 | 
			
		||||
            local vehicle = result[i]
 | 
			
		||||
            local vehicleData = json.decode(vehicle.mods)
 | 
			
		||||
            
 | 
			
		||||
            table.insert(vehicles, {
 | 
			
		||||
                plate = vehicle.plate,
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +76,7 @@ end)
 | 
			
		|||
 | 
			
		||||
-- Get all garages
 | 
			
		||||
QBCore.Functions.CreateCallback('vehicleadmin:getGarages', function(source, cb)
 | 
			
		||||
    if not IsAdmin(source) then
 | 
			
		||||
    if not HasPermission(source) then
 | 
			
		||||
        cb(false)
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			@ -74,10 +91,36 @@ QBCore.Functions.CreateCallback('vehicleadmin:getGarages', function(source, cb)
 | 
			
		|||
    cb(garages)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Check player's job and return permissions
 | 
			
		||||
QBCore.Functions.CreateCallback('vehicleadmin:getPlayerJob', function(source, cb)
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(source)
 | 
			
		||||
    if not Player then 
 | 
			
		||||
        cb(false)
 | 
			
		||||
        return 
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    local hasPermission = HasPermission(source)
 | 
			
		||||
    local jobName = Player.PlayerData.job.name
 | 
			
		||||
    local jobLabel = Player.PlayerData.job.label
 | 
			
		||||
    
 | 
			
		||||
    cb({
 | 
			
		||||
        hasPermission = hasPermission,
 | 
			
		||||
        jobName = jobName,
 | 
			
		||||
        jobLabel = jobLabel
 | 
			
		||||
    })
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Move vehicle to garage
 | 
			
		||||
RegisterNetEvent('vehicleadmin:moveToGarage', function(plate, garage)
 | 
			
		||||
    local src = source
 | 
			
		||||
    if not IsAdmin(src) then return end
 | 
			
		||||
    if not HasPermission(src) then 
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Du hast keine Berechtigung für diese Aktion',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return 
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Delete vehicle from world if it exists
 | 
			
		||||
    local vehicles = GetAllVehicles()
 | 
			
		||||
| 
						 | 
				
			
			@ -93,6 +136,15 @@ RegisterNetEvent('vehicleadmin:moveToGarage', function(plate, garage)
 | 
			
		|||
    -- Update database
 | 
			
		||||
    MySQL.Async.execute('UPDATE player_vehicles SET state = ?, garage = ? WHERE plate = ?', {1, garage, plate}, function(affectedRows)
 | 
			
		||||
        if affectedRows > 0 then
 | 
			
		||||
            -- Log the action
 | 
			
		||||
            local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
            print(string.format('[VEHICLE ADMIN] %s (%s) moved vehicle %s to garage %s', 
 | 
			
		||||
                Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
 | 
			
		||||
                Player.PlayerData.job.label,
 | 
			
		||||
                plate,
 | 
			
		||||
                garage
 | 
			
		||||
            ))
 | 
			
		||||
            
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
                description = 'Fahrzeug wurde in Garage ' .. garage .. ' gestellt',
 | 
			
		||||
| 
						 | 
				
			
			@ -111,7 +163,14 @@ end)
 | 
			
		|||
-- Delete vehicle from map
 | 
			
		||||
RegisterNetEvent('vehicleadmin:deleteFromMap', function(plate)
 | 
			
		||||
    local src = source
 | 
			
		||||
    if not IsAdmin(src) then return end
 | 
			
		||||
    if not HasPermission(src) then 
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Du hast keine Berechtigung für diese Aktion',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return 
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    local vehicles = GetAllVehicles()
 | 
			
		||||
    local deleted = false
 | 
			
		||||
| 
						 | 
				
			
			@ -126,6 +185,14 @@ RegisterNetEvent('vehicleadmin:deleteFromMap', function(plate)
 | 
			
		|||
        end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Log the action
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    print(string.format('[VEHICLE ADMIN] %s (%s) deleted vehicle %s from map', 
 | 
			
		||||
        Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
 | 
			
		||||
        Player.PlayerData.job.label,
 | 
			
		||||
        plate
 | 
			
		||||
    ))
 | 
			
		||||
    
 | 
			
		||||
    if deleted then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Fahrzeugverwaltung',
 | 
			
		||||
| 
						 | 
				
			
			@ -136,7 +203,7 @@ RegisterNetEvent('vehicleadmin:deleteFromMap', function(plate)
 | 
			
		|||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Fahrzeugverwaltung',
 | 
			
		||||
            description = 'Fahrzeug nicht auf der Map gefunden',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
            type = 'info'
 | 
			
		||||
        })
 | 
			
		||||
    end
 | 
			
		||||
end)
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +211,14 @@ end)
 | 
			
		|||
-- Repair vehicle
 | 
			
		||||
RegisterNetEvent('vehicleadmin:repairVehicle', function(plate)
 | 
			
		||||
    local src = source
 | 
			
		||||
    if not IsAdmin(src) then return end
 | 
			
		||||
    if not HasPermission(src) then 
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Du hast keine Berechtigung für diese Aktion',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return 
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Update database
 | 
			
		||||
    MySQL.Async.execute('UPDATE player_vehicles SET engine = ?, body = ? WHERE plate = ?', {1000, 1000, plate}, function(affectedRows)
 | 
			
		||||
| 
						 | 
				
			
			@ -162,6 +236,14 @@ RegisterNetEvent('vehicleadmin:repairVehicle', function(plate)
 | 
			
		|||
            end
 | 
			
		||||
        end
 | 
			
		||||
        
 | 
			
		||||
        -- Log the action
 | 
			
		||||
        local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
        print(string.format('[VEHICLE ADMIN] %s (%s) repaired vehicle %s', 
 | 
			
		||||
            Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
 | 
			
		||||
            Player.PlayerData.job.label,
 | 
			
		||||
            plate
 | 
			
		||||
        ))
 | 
			
		||||
        
 | 
			
		||||
        if affectedRows > 0 then
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
| 
						 | 
				
			
			@ -178,17 +260,177 @@ RegisterNetEvent('vehicleadmin:repairVehicle', function(plate)
 | 
			
		|||
    end)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Impound vehicle (Police only)
 | 
			
		||||
RegisterNetEvent('vehicleadmin:impoundVehicle', function(plate)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or Player.PlayerData.job.name ~= 'police' then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur Polizisten können Fahrzeuge beschlagnahmen',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Delete vehicle from world if it exists
 | 
			
		||||
    local vehicles = GetAllVehicles()
 | 
			
		||||
    for i = 1, #vehicles do
 | 
			
		||||
        local veh = vehicles[i]
 | 
			
		||||
        local vehPlate = GetVehicleNumberPlateText(veh):gsub("%s+", "")
 | 
			
		||||
        if vehPlate == plate:gsub("%s+", "") then
 | 
			
		||||
            DeleteEntity(veh)
 | 
			
		||||
            break
 | 
			
		||||
        end
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Set state to impounded (2) and move to impound garage
 | 
			
		||||
    MySQL.Async.execute('UPDATE player_vehicles SET state = ?, garage = ?, depotprice = ? WHERE plate = ?', 
 | 
			
		||||
        {2, 'impound', 500, plate}, function(affectedRows)
 | 
			
		||||
        if affectedRows > 0 then
 | 
			
		||||
            print(string.format('[VEHICLE ADMIN] %s (Police) impounded vehicle %s', 
 | 
			
		||||
                Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
 | 
			
		||||
                plate
 | 
			
		||||
            ))
 | 
			
		||||
            
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
                description = 'Fahrzeug wurde beschlagnahmt (500€ Gebühr)',
 | 
			
		||||
                type = 'success'
 | 
			
		||||
            })
 | 
			
		||||
        else
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
                description = 'Fehler beim Beschlagnahmen des Fahrzeugs',
 | 
			
		||||
                type = 'error'
 | 
			
		||||
            })
 | 
			
		||||
        end
 | 
			
		||||
    end)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Release from impound (Police/Admin only)
 | 
			
		||||
RegisterNetEvent('vehicleadmin:releaseFromImpound', function(plate, garage)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or (Player.PlayerData.job.name ~= 'police' and not QBCore.Functions.HasPermission(src, 'admin')) then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur Polizisten oder Admins können Fahrzeuge freigeben',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    -- Set state to in garage (1) and move to specified garage
 | 
			
		||||
    MySQL.Async.execute('UPDATE player_vehicles SET state = ?, garage = ?, depotprice = ? WHERE plate = ?', 
 | 
			
		||||
        {1, garage, 0, plate}, function(affectedRows)
 | 
			
		||||
        if affectedRows > 0 then
 | 
			
		||||
            print(string.format('[VEHICLE ADMIN] %s (%s) released vehicle %s from impound to garage %s', 
 | 
			
		||||
                Player.PlayerData.charinfo.firstname .. ' ' .. Player.PlayerData.charinfo.lastname,
 | 
			
		||||
                Player.PlayerData.job.label,
 | 
			
		||||
                plate,
 | 
			
		||||
                garage
 | 
			
		||||
            ))
 | 
			
		||||
            
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
                description = 'Fahrzeug wurde aus der Beschlagnahme freigegeben',
 | 
			
		||||
                type = 'success'
 | 
			
		||||
            })
 | 
			
		||||
        else
 | 
			
		||||
            TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
                title = 'Fahrzeugverwaltung',
 | 
			
		||||
                description = 'Fehler beim Freigeben des Fahrzeugs',
 | 
			
		||||
                type = 'error'
 | 
			
		||||
            })
 | 
			
		||||
        end
 | 
			
		||||
    end)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Command to open admin menu
 | 
			
		||||
QBCore.Commands.Add('vehicleadmin', 'Öffne Fahrzeug Admin Menu', {}, false, function(source, args)
 | 
			
		||||
    local src = source
 | 
			
		||||
    if not IsAdmin(src) then
 | 
			
		||||
    if not HasPermission(src) then
 | 
			
		||||
        local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
        local jobName = Player and Player.PlayerData.job.name or 'Unbekannt'
 | 
			
		||||
        
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Du hast keine Admin-Rechte',
 | 
			
		||||
            description = 'Dein Job (' .. jobName .. ') hat keine Berechtigung für dieses System',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    TriggerClientEvent('vehicleadmin:openMenu', src)
 | 
			
		||||
end, 'admin')
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Alternative command for police
 | 
			
		||||
QBCore.Commands.Add('policegarage', 'Öffne Polizei Fahrzeug Menu', {}, false, function(source, args)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or Player.PlayerData.job.name ~= 'police' then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur Polizisten können diesen Befehl verwenden',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    TriggerClientEvent('vehicleadmin:openMenu', src)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Alternative command for mechanics
 | 
			
		||||
QBCore.Commands.Add('mechanicadmin', 'Öffne Mechaniker Fahrzeug Menu', {}, false, function(source, args)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or Player.PlayerData.job.name ~= 'mechanic' then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur Mechaniker können diesen Befehl verwenden',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    TriggerClientEvent('vehicleadmin:openMenu', src)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Alternative command for ambulance
 | 
			
		||||
QBCore.Commands.Add('emsadmin', 'Öffne EMS Fahrzeug Menu', {}, false, function(source, args)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or Player.PlayerData.job.name ~= 'ambulance' then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur EMS können diesen Befehl verwenden',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    TriggerClientEvent('vehicleadmin:openMenu', src)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
-- Alternative command for cardealer
 | 
			
		||||
QBCore.Commands.Add('dealeradmin', 'Öffne Autohändler Fahrzeug Menu', {}, false, function(source, args)
 | 
			
		||||
    local src = source
 | 
			
		||||
    local Player = QBCore.Functions.GetPlayer(src)
 | 
			
		||||
    
 | 
			
		||||
    if not Player or Player.PlayerData.job.name ~= 'cardealer' then
 | 
			
		||||
        TriggerClientEvent('ox_lib:notify', src, {
 | 
			
		||||
            title = 'Keine Berechtigung',
 | 
			
		||||
            description = 'Nur Autohändler können diesen Befehl verwenden',
 | 
			
		||||
            type = 'error'
 | 
			
		||||
        })
 | 
			
		||||
        return
 | 
			
		||||
    end
 | 
			
		||||
    
 | 
			
		||||
    TriggerClientEvent('vehicleadmin:openMenu', src)
 | 
			
		||||
end)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue