forked from Simnation/Main
225 lines
6.5 KiB
Lua
225 lines
6.5 KiB
Lua
local QBCore = exports['qb-core']:GetCoreObject()
|
|
|
|
-- Tracking Menu öffnen
|
|
RegisterCommand('tracking', function()
|
|
local PlayerData = QBCore.Functions.GetPlayerData()
|
|
local job = PlayerData.job.name
|
|
|
|
-- Überprüfe ob Job berechtigt ist
|
|
local allowedJobs = {'police', 'ambulance', 'mechanic'} -- Füge hier weitere Jobs hinzu
|
|
local hasPermission = false
|
|
|
|
for _, allowedJob in pairs(allowedJobs) do
|
|
if job == allowedJob then
|
|
hasPermission = true
|
|
break
|
|
end
|
|
end
|
|
|
|
if not hasPermission then
|
|
QBCore.Functions.Notify('Du hast keine Berechtigung für das Tracking-System!', 'error')
|
|
return
|
|
end
|
|
|
|
OpenTrackingMenu()
|
|
end)
|
|
|
|
function OpenTrackingMenu()
|
|
local options = {
|
|
{
|
|
title = 'Fahrzeug orten',
|
|
description = 'Fahrzeug über Kennzeichen orten',
|
|
icon = 'fas fa-search',
|
|
onSelect = function()
|
|
TrackVehicle()
|
|
end
|
|
},
|
|
{
|
|
title = 'Aktive Trackings',
|
|
description = 'Zeige alle aktiven Trackings',
|
|
icon = 'fas fa-list',
|
|
onSelect = function()
|
|
ShowActiveTrackings()
|
|
end
|
|
},
|
|
{
|
|
title = 'Tracking beenden',
|
|
description = 'Beende ein aktives Tracking',
|
|
icon = 'fas fa-times',
|
|
onSelect = function()
|
|
StopTracking()
|
|
end
|
|
}
|
|
}
|
|
|
|
lib.registerContext({
|
|
id = 'tracking_menu',
|
|
title = 'Fahrzeug Tracking System',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('tracking_menu')
|
|
end
|
|
|
|
function TrackVehicle()
|
|
local input = lib.inputDialog('Fahrzeug Tracking', {
|
|
{
|
|
type = 'input',
|
|
label = 'Kennzeichen',
|
|
description = 'Gib das Kennzeichen des Fahrzeugs ein',
|
|
required = true,
|
|
max = 8
|
|
}
|
|
})
|
|
|
|
if not input then return end
|
|
|
|
local plate = string.upper(input[1])
|
|
|
|
QBCore.Functions.TriggerCallback('tracking:server:trackVehicle', function(success, message, vehicleData)
|
|
if success then
|
|
QBCore.Functions.Notify('Fahrzeug wird getrackt!', 'success')
|
|
StartTracking(plate, vehicleData)
|
|
else
|
|
QBCore.Functions.Notify(message, 'error')
|
|
end
|
|
end, plate)
|
|
end
|
|
|
|
local activeTrackings = {}
|
|
local trackingBlips = {}
|
|
|
|
function StartTracking(plate, vehicleData)
|
|
if activeTrackings[plate] then
|
|
QBCore.Functions.Notify('Fahrzeug wird bereits getrackt!', 'error')
|
|
return
|
|
end
|
|
|
|
activeTrackings[plate] = {
|
|
vehicle = vehicleData.vehicle,
|
|
coords = vehicleData.coords,
|
|
lastUpdate = GetGameTimer()
|
|
}
|
|
|
|
-- Erstelle Blip
|
|
local blip = AddBlipForCoord(vehicleData.coords.x, vehicleData.coords.y, vehicleData.coords.z)
|
|
SetBlipSprite(blip, 225)
|
|
SetBlipDisplay(blip, 4)
|
|
SetBlipScale(blip, 0.8)
|
|
SetBlipColour(blip, 1)
|
|
SetBlipAsShortRange(blip, false)
|
|
BeginTextCommandSetBlipName("STRING")
|
|
AddTextComponentString("Tracking: " .. plate)
|
|
EndTextCommandSetBlipName(blip)
|
|
|
|
trackingBlips[plate] = blip
|
|
|
|
-- Starte Update Loop
|
|
CreateThread(function()
|
|
while activeTrackings[plate] do
|
|
TriggerServerEvent('tracking:server:updateVehicleLocation', plate)
|
|
Wait(5000) -- Update alle 5 Sekunden
|
|
end
|
|
end)
|
|
end
|
|
|
|
function ShowActiveTrackings()
|
|
local options = {}
|
|
|
|
if next(activeTrackings) == nil then
|
|
options[#options + 1] = {
|
|
title = 'Keine aktiven Trackings',
|
|
description = 'Derzeit werden keine Fahrzeuge getrackt',
|
|
icon = 'fas fa-info-circle'
|
|
}
|
|
else
|
|
for plate, data in pairs(activeTrackings) do
|
|
local distance = #(GetEntityCoords(PlayerPedId()) - vector3(data.coords.x, data.coords.y, data.coords.z))
|
|
options[#options + 1] = {
|
|
title = 'Kennzeichen: ' .. plate,
|
|
description = 'Entfernung: ' .. math.floor(distance) .. 'm | Letztes Update: ' .. math.floor((GetGameTimer() - data.lastUpdate) / 1000) .. 's',
|
|
icon = 'fas fa-car',
|
|
onSelect = function()
|
|
SetNewWaypoint(data.coords.x, data.coords.y)
|
|
QBCore.Functions.Notify('Wegpunkt zum Fahrzeug gesetzt!', 'success')
|
|
end
|
|
}
|
|
end
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'active_trackings',
|
|
title = 'Aktive Trackings',
|
|
menu = 'tracking_menu',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('active_trackings')
|
|
end
|
|
|
|
function StopTracking()
|
|
local options = {}
|
|
|
|
if next(activeTrackings) == nil then
|
|
options[#options + 1] = {
|
|
title = 'Keine aktiven Trackings',
|
|
description = 'Derzeit werden keine Fahrzeuge getrackt',
|
|
icon = 'fas fa-info-circle'
|
|
}
|
|
else
|
|
for plate, data in pairs(activeTrackings) do
|
|
options[#options + 1] = {
|
|
title = 'Stoppe: ' .. plate,
|
|
description = 'Tracking für dieses Fahrzeug beenden',
|
|
icon = 'fas fa-stop',
|
|
onSelect = function()
|
|
StopVehicleTracking(plate)
|
|
end
|
|
}
|
|
end
|
|
end
|
|
|
|
lib.registerContext({
|
|
id = 'stop_tracking',
|
|
title = 'Tracking beenden',
|
|
menu = 'tracking_menu',
|
|
options = options
|
|
})
|
|
|
|
lib.showContext('stop_tracking')
|
|
end
|
|
|
|
function StopVehicleTracking(plate)
|
|
if activeTrackings[plate] then
|
|
activeTrackings[plate] = nil
|
|
|
|
if trackingBlips[plate] then
|
|
RemoveBlip(trackingBlips[plate])
|
|
trackingBlips[plate] = nil
|
|
end
|
|
|
|
TriggerServerEvent('tracking:server:stopTracking', plate)
|
|
QBCore.Functions.Notify('Tracking für ' .. plate .. ' beendet!', 'success')
|
|
end
|
|
end
|
|
|
|
-- Update Tracking Position
|
|
RegisterNetEvent('tracking:client:updatePosition', function(plate, coords)
|
|
if activeTrackings[plate] then
|
|
activeTrackings[plate].coords = coords
|
|
activeTrackings[plate].lastUpdate = GetGameTimer()
|
|
|
|
if trackingBlips[plate] then
|
|
SetBlipCoords(trackingBlips[plate], coords.x, coords.y, coords.z)
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Cleanup beim Disconnect
|
|
AddEventHandler('onResourceStop', function(resourceName)
|
|
if GetCurrentResourceName() == resourceName then
|
|
for plate, blip in pairs(trackingBlips) do
|
|
RemoveBlip(blip)
|
|
end
|
|
end
|
|
end)
|