1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-07 12:45:07 +02:00
parent 69dd8ad480
commit 8a9036936a

View file

@ -252,8 +252,6 @@ end
-- Event Handler für Fahrzeug betreten (nur Fahrersitz)
CreateThread(function()
local lastVehicle = 0
while true do
Wait(1000)
@ -261,7 +259,7 @@ CreateThread(function()
local currentVehicle = GetVehiclePedIsIn(playerPed, false)
-- Spieler ist als Fahrer in ein Fahrzeug eingestiegen
if currentVehicle ~= 0 and currentVehicle ~= lastVehicle then
if currentVehicle ~= 0 then
-- Prüfe ob Spieler auf Fahrersitz ist
local driver = GetPedInVehicleSeat(currentVehicle, -1)
@ -269,8 +267,8 @@ CreateThread(function()
if driver == playerPed and IsVehicleClassAllowed(currentVehicle) then
local plate = QBCore.Functions.GetPlate(currentVehicle)
-- Prüfe ob Fahrzeug gerade in die Garage gestellt wird
if not garagePending[plate] then
-- Check if this vehicle is already being tracked
if not trackedVehicles[plate] and not garagePending[plate] then
trackedVehicles[plate] = currentVehicle
-- Speichere letzte bekannte Position
@ -290,16 +288,13 @@ CreateThread(function()
local vehicleModel = GetEntityModel(currentVehicle)
TriggerServerEvent('antidespawn:server:registerVehicle', plate, vehicleModel, vehicleCoords, vehicleHeading, vehicleMods)
else
Debug("Fahrzeug wird gerade in Garage gestellt, nicht tracken: " .. plate)
end
end
end
lastVehicle = currentVehicle
end
end)
-- Kontinuierliche Despawn-Verhinderung für alle getrackten Fahrzeuge
CreateThread(function()
while true do
@ -613,6 +608,35 @@ RegisterCommand('fixvehicle', function()
end
end, false)
local maxTrackedVehicles = 100 -- Adjust as needed
-- Add this check before adding a new vehicle
if tableLength(trackedVehicles) >= maxTrackedVehicles then
-- Either remove the oldest tracked vehicle or prevent adding new ones
Debug("Maximum number of tracked vehicles reached")
-- Optional: Remove oldest tracked vehicle
end
-- Helper function to count table entries
function tableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
-- Add to the continuous tracking thread
local playerPos = GetEntityCoords(PlayerPedId())
local distance = #(playerPos - GetEntityCoords(vehicle))
if distance > 500.0 then -- 500 units = about 500 meters
Debug("Fahrzeug zu weit entfernt, entferne aus Tracking: " .. plate)
trackedVehicles[plate] = nil
lastKnownCoords[plate] = nil
TriggerServerEvent('antidespawn:server:removeVehicle', plate)
end
AddEventHandler('onResourceStop', function(resourceName)
if resourceName == GetCurrentResourceName() then
Debug("Resource stopping, clearing all data")