From 68f35420ea6256500e6123ae16aeb68fb8724ae1 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 5 Aug 2025 09:48:15 +0200 Subject: [PATCH] ed --- .../[carscripts]/nordi_tracking/client.lua | 128 +++++++++++++++--- .../[carscripts]/nordi_tracking/config.lua | 36 +++++ .../nordi_tracking/fxmanifest.lua | 3 +- 3 files changed, 144 insertions(+), 23 deletions(-) create mode 100644 resources/[carscripts]/nordi_tracking/config.lua diff --git a/resources/[carscripts]/nordi_tracking/client.lua b/resources/[carscripts]/nordi_tracking/client.lua index 6f5df2416..e86bd7cea 100644 --- a/resources/[carscripts]/nordi_tracking/client.lua +++ b/resources/[carscripts]/nordi_tracking/client.lua @@ -1,27 +1,109 @@ local QBCore = exports['qb-core']:GetCoreObject() +local activeTrackings = {} +local trackingBlips = {} +local inTrackingZone = false +local currentLocation = nil --- 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 +-- Command to open tracking menu (if enabled in config) +if Config.EnableCommand then + RegisterCommand(Config.Command, 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) +end + +-- Check if player is near a tracking location +CreateThread(function() + while true do + local playerPed = PlayerPedId() + local playerCoords = GetEntityCoords(playerPed) + local sleep = 1000 + local isInZone = false + local currentLocationData = nil + + for _, location in pairs(Config.TrackingLocations) do + local distance = #(playerCoords - location.coords) + + if distance < location.radius then + sleep = 0 + isInZone = true + currentLocationData = location + break + end + end + + if isInZone and not inTrackingZone then + inTrackingZone = true + currentLocation = currentLocationData + -- Check if player has the required job for this location + local PlayerData = QBCore.Functions.GetPlayerData() + local hasRequiredJob = false + + for _, jobName in pairs(currentLocation.job) do + if PlayerData.job.name == jobName then + hasRequiredJob = true + break + end + end + + if hasRequiredJob then + -- Show DrawText UI + exports['qb-core']:DrawText(currentLocation.label, 'left') + end + elseif not isInZone and inTrackingZone then + inTrackingZone = false + currentLocation = nil + exports['qb-core']:HideText() + end + + Wait(sleep) end - - if not hasPermission then - QBCore.Functions.Notify('Du hast keine Berechtigung für das Tracking-System!', 'error') - return +end) + +-- Key press detection for tracking locations +CreateThread(function() + while true do + local sleep = 1000 + + if inTrackingZone and currentLocation then + sleep = 0 + -- Check if player has the required job for this location + local PlayerData = QBCore.Functions.GetPlayerData() + local hasRequiredJob = false + + for _, jobName in pairs(currentLocation.job) do + if PlayerData.job.name == jobName then + hasRequiredJob = true + break + end + end + + if hasRequiredJob and IsControlJustPressed(0, Config.InteractKey) then + exports['qb-core']:HideText() + OpenTrackingMenu() + end + end + + Wait(sleep) end - - OpenTrackingMenu() end) function OpenTrackingMenu() @@ -86,9 +168,6 @@ function TrackVehicle() end, plate) end -local activeTrackings = {} -local trackingBlips = {} - function StartTracking(plate, vehicleData) if activeTrackings[plate] then QBCore.Functions.Notify('Fahrzeug wird bereits getrackt!', 'error') @@ -225,5 +304,10 @@ AddEventHandler('onResourceStop', function(resourceName) for plate, blip in pairs(trackingBlips) do RemoveBlip(blip) end + + -- Hide DrawText if active when resource stops + if inTrackingZone then + exports['qb-core']:HideText() + end end end) diff --git a/resources/[carscripts]/nordi_tracking/config.lua b/resources/[carscripts]/nordi_tracking/config.lua new file mode 100644 index 000000000..0acf3b749 --- /dev/null +++ b/resources/[carscripts]/nordi_tracking/config.lua @@ -0,0 +1,36 @@ +Config = {} + +-- Locations where the tracking system can be accessed +Config.TrackingLocations = { + { + coords = vector3(440.84, -981.14, 30.69), -- LSPD Mission Row + radius = 2.0, + job = {"police"}, -- Only police can access at this location + label = "Polizei Tracking System" + }, + { + coords = vector3(309.21, -592.82, 43.28), -- Pillbox Hospital + radius = 2.0, + job = {"ambulance"}, -- Only ambulance can access at this location + label = "Krankenhaus Tracking System" + }, + { + coords = vector3(-347.41, -133.08, 39.01), -- LS Customs + radius = 2.0, + job = {"mechanic"}, -- Only mechanics can access at this location + label = "Mechaniker Tracking System" + }, + { + coords = vector3(106.11, -1304.49, 28.77), -- Vanilla Unicorn (example for multiple jobs) + radius = 2.0, + job = {"police", "ambulance"}, -- Multiple jobs can access here + label = "VU Tracking System" + } +} + +-- Command to open tracking menu (can be disabled by setting to false) +Config.EnableCommand = true +Config.Command = "tracking" + +-- Key to press at tracking locations (default is E) +Config.InteractKey = 38 -- E key diff --git a/resources/[carscripts]/nordi_tracking/fxmanifest.lua b/resources/[carscripts]/nordi_tracking/fxmanifest.lua index 994cc4272..3e547abce 100644 --- a/resources/[carscripts]/nordi_tracking/fxmanifest.lua +++ b/resources/[carscripts]/nordi_tracking/fxmanifest.lua @@ -7,7 +7,8 @@ version '1.0.0' shared_scripts { '@ox_lib/init.lua', - '@qb-core/shared/locale.lua' + '@qb-core/shared/locale.lua', + 'config.lua' } client_scripts {