forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
5b0effa7af
commit
d2b98317d3
1 changed files with 59 additions and 17 deletions
|
@ -12,6 +12,31 @@ local function IsVehicleClassAllowed(vehicle)
|
|||
return false
|
||||
end
|
||||
|
||||
-- Stärkere Despawn-Verhinderung
|
||||
local function PreventDespawn(vehicle)
|
||||
if DoesEntityExist(vehicle) then
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleNeedsToBeHotwired(vehicle, false)
|
||||
SetEntityLoadCollisionFlag(vehicle, true)
|
||||
|
||||
-- Zusätzliche Flags
|
||||
SetVehicleIsStolen(vehicle, false)
|
||||
SetVehicleIsWanted(vehicle, false)
|
||||
|
||||
-- Verhindere dass das Fahrzeug als "abandoned" markiert wird
|
||||
if DecorExistOn(vehicle, "IgnoredByQuickSave") then
|
||||
DecorSetBool(vehicle, "IgnoredByQuickSave", false)
|
||||
end
|
||||
|
||||
-- Setze Fahrzeug auf Boden
|
||||
SetVehicleOnGroundProperly(vehicle)
|
||||
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Funktion um Fahrzeugmods zu erhalten
|
||||
local function GetVehicleMods(vehicle)
|
||||
local mods = {}
|
||||
|
@ -113,9 +138,8 @@ CreateThread(function()
|
|||
local plate = QBCore.Functions.GetPlate(currentVehicle)
|
||||
playerDrivenVehicles[plate] = currentVehicle
|
||||
|
||||
-- Verhindere sofort Despawn
|
||||
SetEntityAsMissionEntity(currentVehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(currentVehicle, true)
|
||||
-- Sofort starke Despawn-Verhinderung
|
||||
PreventDespawn(currentVehicle)
|
||||
|
||||
if Config.Debug then
|
||||
print(string.format("Player started driving vehicle: %s", plate))
|
||||
|
@ -127,6 +151,27 @@ CreateThread(function()
|
|||
end
|
||||
end)
|
||||
|
||||
-- Kontinuierliche Despawn-Verhinderung für alle getrackten Fahrzeuge
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(10000) -- Alle 10 Sekunden
|
||||
|
||||
for plate, vehicle in pairs(playerDrivenVehicles) do
|
||||
if DoesEntityExist(vehicle) then
|
||||
PreventDespawn(vehicle)
|
||||
if Config.Debug then
|
||||
print(string.format("Refreshing despawn protection for: %s", plate))
|
||||
end
|
||||
else
|
||||
playerDrivenVehicles[plate] = nil
|
||||
if Config.Debug then
|
||||
print(string.format("Player driven vehicle no longer exists: %s", plate))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Hauptloop für Fahrzeugtracking (nur für vom Spieler gefahrene Fahrzeuge)
|
||||
CreateThread(function()
|
||||
while true do
|
||||
|
@ -137,9 +182,8 @@ CreateThread(function()
|
|||
if DoesEntityExist(vehicle) then
|
||||
local vehicleCoords = GetEntityCoords(vehicle)
|
||||
|
||||
-- Verhindere Despawn
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
-- Verstärke Despawn-Schutz bei jedem Save
|
||||
PreventDespawn(vehicle)
|
||||
|
||||
-- Speichere Fahrzeugdaten
|
||||
local vehicleData = {
|
||||
|
@ -218,7 +262,7 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic
|
|||
local vehicle = CreateVehicle(modelHash, position.x, position.y, position.z, rotation.z, true, false)
|
||||
|
||||
if DoesEntityExist(vehicle) then
|
||||
Wait(1000) -- Längere Wartezeit
|
||||
Wait(1000) -- Warte bis Fahrzeug vollständig geladen
|
||||
|
||||
-- Setze Fahrzeugdaten
|
||||
SetVehicleNumberPlateText(vehicle, vehicleData.plate)
|
||||
|
@ -240,10 +284,8 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic
|
|||
end
|
||||
end
|
||||
|
||||
-- Verhindere Despawn
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(vehicle, true)
|
||||
SetVehicleOnGroundProperly(vehicle)
|
||||
-- Starke Despawn-Verhinderung
|
||||
PreventDespawn(vehicle)
|
||||
|
||||
playerDrivenVehicles[vehicleData.plate] = vehicle
|
||||
|
||||
|
@ -266,8 +308,7 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic
|
|||
else
|
||||
-- Fahrzeug existiert bereits, füge zu Liste hinzu
|
||||
playerDrivenVehicles[vehicleData.plate] = existingVehicle
|
||||
SetEntityAsMissionEntity(existingVehicle, true, true)
|
||||
SetVehicleHasBeenOwnedByPlayer(existingVehicle, true)
|
||||
PreventDespawn(existingVehicle)
|
||||
|
||||
if Config.Debug then
|
||||
print(string.format("Vehicle already exists: %s", vehicleData.plate))
|
||||
|
@ -293,7 +334,7 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|||
print("Player loaded, waiting before loading vehicles...")
|
||||
end
|
||||
|
||||
Wait(15000) -- Längere Wartezeit
|
||||
Wait(15000)
|
||||
|
||||
if Config.Debug then
|
||||
print("Loading vehicles...")
|
||||
|
@ -302,9 +343,9 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
|||
TriggerServerEvent('vehicle-persistence:server:loadVehicles')
|
||||
end)
|
||||
|
||||
-- Lade Fahrzeuge auch beim Resource Start (falls Spieler bereits online)
|
||||
-- Lade Fahrzeuge auch beim Resource Start
|
||||
CreateThread(function()
|
||||
Wait(20000) -- Noch längere Wartezeit beim Resource Start
|
||||
Wait(20000)
|
||||
|
||||
local playerData = QBCore.Functions.GetPlayerData()
|
||||
if playerData and playerData.citizenid then
|
||||
|
@ -334,7 +375,7 @@ RegisterNetEvent('jg-advancedgarages:client:vehicle-spawned', function(data)
|
|||
end
|
||||
end)
|
||||
|
||||
-- Debug Command zum manuellen Laden
|
||||
-- Debug Command
|
||||
RegisterCommand('loadvehicles', function()
|
||||
if Config.Debug then
|
||||
print("Manual vehicle load triggered...")
|
||||
|
@ -348,3 +389,4 @@ AddEventHandler('onResourceStop', function(resourceName)
|
|||
playerDrivenVehicles = {}
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue