ed
This commit is contained in:
		
							parent
							
								
									7fc981e7fc
								
							
						
					
					
						commit
						5b0effa7af
					
				
					 1 changed files with 63 additions and 6 deletions
				
			
		|  | @ -179,10 +179,14 @@ end) | |||
| -- Spawne gespeicherte Fahrzeuge | ||||
| RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehicles) | ||||
|     if Config.Debug then | ||||
|         print(string.format("Attempting to spawn %d saved vehicles", #vehicles)) | ||||
|         print(string.format("Received %d vehicles to spawn", #vehicles)) | ||||
|     end | ||||
|      | ||||
|     for _, vehicleData in pairs(vehicles) do | ||||
|         if Config.Debug then | ||||
|             print(string.format("Processing vehicle: %s", vehicleData.plate)) | ||||
|         end | ||||
|          | ||||
|         local position = json.decode(vehicleData.position) | ||||
|         local rotation = json.decode(vehicleData.rotation) | ||||
|          | ||||
|  | @ -195,18 +199,26 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic | |||
|                     modelHash = GetHashKey(modelHash) | ||||
|                 end | ||||
|                  | ||||
|                 if Config.Debug then | ||||
|                     print(string.format("Requesting model: %s (Hash: %s)", vehicleData.model, modelHash)) | ||||
|                 end | ||||
|                  | ||||
|                 RequestModel(modelHash) | ||||
|                 local timeout = 0 | ||||
|                 while not HasModelLoaded(modelHash) and timeout < 50 do | ||||
|                 while not HasModelLoaded(modelHash) and timeout < 100 do | ||||
|                     Wait(100) | ||||
|                     timeout = timeout + 1 | ||||
|                 end | ||||
|                  | ||||
|                 if HasModelLoaded(modelHash) then | ||||
|                     if Config.Debug then | ||||
|                         print(string.format("Model loaded, creating vehicle at: %.2f, %.2f, %.2f", position.x, position.y, position.z)) | ||||
|                     end | ||||
|                      | ||||
|                     local vehicle = CreateVehicle(modelHash, position.x, position.y, position.z, rotation.z, true, false) | ||||
|                      | ||||
|                     if DoesEntityExist(vehicle) then | ||||
|                         Wait(500) | ||||
|                         Wait(1000) -- Längere Wartezeit | ||||
|                          | ||||
|                         -- Setze Fahrzeugdaten | ||||
|                         SetVehicleNumberPlateText(vehicle, vehicleData.plate) | ||||
|  | @ -222,22 +234,33 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic | |||
|                          | ||||
|                         -- Setze Mods | ||||
|                         if vehicleData.mods then | ||||
|                             local mods = json.decode(vehicleData.mods) | ||||
|                             SetVehicleMods(vehicle, mods) | ||||
|                             local success, mods = pcall(json.decode, vehicleData.mods) | ||||
|                             if success then | ||||
|                                 SetVehicleMods(vehicle, mods) | ||||
|                             end | ||||
|                         end | ||||
|                          | ||||
|                         -- Verhindere Despawn | ||||
|                         SetEntityAsMissionEntity(vehicle, true, true) | ||||
|                         SetVehicleHasBeenOwnedByPlayer(vehicle, true) | ||||
|                         SetVehicleOnGroundProperly(vehicle) | ||||
|                          | ||||
|                         playerDrivenVehicles[vehicleData.plate] = vehicle | ||||
|                          | ||||
|                         if Config.Debug then | ||||
|                             print(string.format("Successfully spawned saved vehicle: %s", vehicleData.plate)) | ||||
|                         end | ||||
|                     else | ||||
|                         if Config.Debug then | ||||
|                             print(string.format("Failed to create vehicle: %s", vehicleData.plate)) | ||||
|                         end | ||||
|                     end | ||||
|                      | ||||
|                     SetModelAsNoLongerNeeded(modelHash) | ||||
|                 else | ||||
|                     if Config.Debug then | ||||
|                         print(string.format("Failed to load model for vehicle: %s", vehicleData.plate)) | ||||
|                     end | ||||
|                 end | ||||
|             end) | ||||
|         else | ||||
|  | @ -245,6 +268,10 @@ RegisterNetEvent('vehicle-persistence:client:spawnSavedVehicles', function(vehic | |||
|             playerDrivenVehicles[vehicleData.plate] = existingVehicle | ||||
|             SetEntityAsMissionEntity(existingVehicle, true, true) | ||||
|             SetVehicleHasBeenOwnedByPlayer(existingVehicle, true) | ||||
|              | ||||
|             if Config.Debug then | ||||
|                 print(string.format("Vehicle already exists: %s", vehicleData.plate)) | ||||
|             end | ||||
|         end | ||||
|     end | ||||
| end) | ||||
|  | @ -262,10 +289,32 @@ end | |||
|  | ||||
| -- Lade Fahrzeuge beim Spawn | ||||
| RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function() | ||||
|     Wait(10000) | ||||
|     if Config.Debug then | ||||
|         print("Player loaded, waiting before loading vehicles...") | ||||
|     end | ||||
|      | ||||
|     Wait(15000) -- Längere Wartezeit | ||||
|      | ||||
|     if Config.Debug then | ||||
|         print("Loading vehicles...") | ||||
|     end | ||||
|      | ||||
|     TriggerServerEvent('vehicle-persistence:server:loadVehicles') | ||||
| end) | ||||
|  | ||||
| -- Lade Fahrzeuge auch beim Resource Start (falls Spieler bereits online) | ||||
| CreateThread(function() | ||||
|     Wait(20000) -- Noch längere Wartezeit beim Resource Start | ||||
|      | ||||
|     local playerData = QBCore.Functions.GetPlayerData() | ||||
|     if playerData and playerData.citizenid then | ||||
|         if Config.Debug then | ||||
|             print("Resource started, loading vehicles for existing player...") | ||||
|         end | ||||
|         TriggerServerEvent('vehicle-persistence:server:loadVehicles') | ||||
|     end | ||||
| end) | ||||
|  | ||||
| -- jg-advanced-garage Events | ||||
| RegisterNetEvent('jg-advancedgarages:client:vehicle-stored', function(data) | ||||
|     if data and data.plate and playerDrivenVehicles[data.plate] then | ||||
|  | @ -285,6 +334,14 @@ RegisterNetEvent('jg-advancedgarages:client:vehicle-spawned', function(data) | |||
|     end | ||||
| end) | ||||
|  | ||||
| -- Debug Command zum manuellen Laden | ||||
| RegisterCommand('loadvehicles', function() | ||||
|     if Config.Debug then | ||||
|         print("Manual vehicle load triggered...") | ||||
|         TriggerServerEvent('vehicle-persistence:server:loadVehicles') | ||||
|     end | ||||
| end, false) | ||||
|  | ||||
| -- Cleanup beim Disconnect | ||||
| AddEventHandler('onResourceStop', function(resourceName) | ||||
|     if resourceName == GetCurrentResourceName() then | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98