ed
This commit is contained in:
parent
b6e1da51c2
commit
0e7adf65df
3 changed files with 361 additions and 0 deletions
108
resources/[carscripts]/nordi_tracking/server.lua
Normal file
108
resources/[carscripts]/nordi_tracking/server.lua
Normal file
|
@ -0,0 +1,108 @@
|
|||
local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
local activeTrackings = {}
|
||||
|
||||
-- Callback für Fahrzeug Tracking
|
||||
QBCore.Functions.CreateCallback('tracking:server:trackVehicle', function(source, cb, plate)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if not Player then
|
||||
cb(false, 'Spieler nicht gefunden!')
|
||||
return
|
||||
end
|
||||
|
||||
-- Überprüfe Job Berechtigung
|
||||
local allowedJobs = {'police', 'ambulance', 'mechanic'}
|
||||
local hasPermission = false
|
||||
|
||||
for _, job in pairs(allowedJobs) do
|
||||
if Player.PlayerData.job.name == job then
|
||||
hasPermission = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not hasPermission then
|
||||
cb(false, 'Keine Berechtigung!')
|
||||
return
|
||||
end
|
||||
|
||||
-- Suche Fahrzeug in der Datenbank
|
||||
MySQL.Async.fetchAll('SELECT * FROM player_vehicles WHERE plate = ?', {plate}, function(result)
|
||||
if result[1] then
|
||||
-- Suche das Fahrzeug in der Welt
|
||||
local vehicles = GetAllVehicles()
|
||||
local foundVehicle = nil
|
||||
local vehicleCoords = nil
|
||||
|
||||
for _, vehicle in pairs(vehicles) do
|
||||
if DoesEntityExist(vehicle) then
|
||||
local vehiclePlate = GetVehicleNumberPlateText(vehicle)
|
||||
if vehiclePlate and string.gsub(vehiclePlate, '^%s*(.-)%s*$', '%1') == plate then
|
||||
foundVehicle = vehicle
|
||||
vehicleCoords = GetEntityCoords(vehicle)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if foundVehicle and vehicleCoords then
|
||||
activeTrackings[plate] = {
|
||||
vehicle = foundVehicle,
|
||||
coords = {x = vehicleCoords.x, y = vehicleCoords.y, z = vehicleCoords.z},
|
||||
tracker = src
|
||||
}
|
||||
|
||||
cb(true, 'Fahrzeug gefunden!', {
|
||||
vehicle = foundVehicle,
|
||||
coords = {x = vehicleCoords.x, y = vehicleCoords.y, z = vehicleCoords.z}
|
||||
})
|
||||
else
|
||||
cb(false, 'Fahrzeug nicht in der Welt gefunden!')
|
||||
end
|
||||
else
|
||||
cb(false, 'Fahrzeug mit diesem Kennzeichen existiert nicht!')
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
-- Update Fahrzeug Position
|
||||
RegisterNetEvent('tracking:server:updateVehicleLocation', function(plate)
|
||||
local src = source
|
||||
|
||||
if activeTrackings[plate] and activeTrackings[plate].tracker == src then
|
||||
local vehicle = activeTrackings[plate].vehicle
|
||||
|
||||
if DoesEntityExist(vehicle) then
|
||||
local coords = GetEntityCoords(vehicle)
|
||||
activeTrackings[plate].coords = {x = coords.x, y = coords.y, z = coords.z}
|
||||
|
||||
TriggerClientEvent('tracking:client:updatePosition', src, plate, {x = coords.x, y = coords.y, z = coords.z})
|
||||
else
|
||||
-- Fahrzeug existiert nicht mehr
|
||||
activeTrackings[plate] = nil
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Tracking verloren - Fahrzeug nicht mehr verfügbar!', 'error')
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Stoppe Tracking
|
||||
RegisterNetEvent('tracking:server:stopTracking', function(plate)
|
||||
local src = source
|
||||
|
||||
if activeTrackings[plate] and activeTrackings[plate].tracker == src then
|
||||
activeTrackings[plate] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
-- Cleanup bei Disconnect
|
||||
AddEventHandler('playerDropped', function()
|
||||
local src = source
|
||||
|
||||
for plate, data in pairs(activeTrackings) do
|
||||
if data.tracker == src then
|
||||
activeTrackings[plate] = nil
|
||||
end
|
||||
end
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue