Update main.lua
This commit is contained in:
		
							parent
							
								
									a47b4f6672
								
							
						
					
					
						commit
						b56b025204
					
				
					 1 changed files with 2 additions and 123 deletions
				
			
		| 
						 | 
				
			
			@ -384,19 +384,11 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
 | 
			
		|||
    print("^2[TAXI DEBUG]^7 Monitoring taxi arrival...")
 | 
			
		||||
    
 | 
			
		||||
    CreateThread(function()
 | 
			
		||||
        local startTime = GetGameTimer()
 | 
			
		||||
        local maxWaitTime = Config.MaxWaitTime * 1000
 | 
			
		||||
        local lastDistance = 999999.0
 | 
			
		||||
        local stuckCounter = 0
 | 
			
		||||
        local routeRecalculated = false
 | 
			
		||||
        
 | 
			
		||||
        while DoesEntityExist(taxi) and (not driver or DoesEntityExist(driver)) do
 | 
			
		||||
            local taxiCoords = GetEntityCoords(taxi)
 | 
			
		||||
            local currentDistance = #(playerCoords - taxiCoords)
 | 
			
		||||
            local elapsedTime = GetGameTimer() - startTime
 | 
			
		||||
            local distance = #(playerCoords - taxiCoords)
 | 
			
		||||
            
 | 
			
		||||
            -- Taxi ist angekommen
 | 
			
		||||
            if currentDistance < 15.0 then
 | 
			
		||||
            if distance < 15.0 then
 | 
			
		||||
                print("^2[TAXI DEBUG]^7 Taxi arrived!")
 | 
			
		||||
                
 | 
			
		||||
                -- Taxi stoppen
 | 
			
		||||
| 
						 | 
				
			
			@ -428,124 +420,11 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
 | 
			
		|||
                break
 | 
			
		||||
            end
 | 
			
		||||
            
 | 
			
		||||
            -- Prüfen ob Taxi stecken geblieben ist
 | 
			
		||||
            if math.abs(currentDistance - lastDistance) < 0.5 then
 | 
			
		||||
                stuckCounter = stuckCounter + 1
 | 
			
		||||
            else
 | 
			
		||||
                stuckCounter = 0
 | 
			
		||||
            end
 | 
			
		||||
            
 | 
			
		||||
            -- Wenn Taxi zu lange stecken bleibt oder Zeit abgelaufen ist
 | 
			
		||||
            if stuckCounter > 15 or (elapsedTime > maxWaitTime and currentDistance > 50.0) then
 | 
			
		||||
                -- Versuche Route neu zu berechnen oder teleportiere näher
 | 
			
		||||
                if not routeRecalculated then
 | 
			
		||||
                    print("^3[TAXI DEBUG]^7 Taxi seems stuck, recalculating route...")
 | 
			
		||||
                    
 | 
			
		||||
                    -- Aktuelle Spielerposition holen (könnte sich bewegt haben)
 | 
			
		||||
                    local newPlayerCoords = GetEntityCoords(PlayerPedId())
 | 
			
		||||
                    
 | 
			
		||||
                    -- Finde eine nahe Position auf der Straße
 | 
			
		||||
                    local streetCoords = FindNearestVehicleNode(newPlayerCoords.x, newPlayerCoords.y, newPlayerCoords.z, 1, 3.0, 0)
 | 
			
		||||
                    
 | 
			
		||||
                    if streetCoords then
 | 
			
		||||
                        -- Neue Route zum Spieler setzen
 | 
			
		||||
                        ClearPedTasks(driver)
 | 
			
		||||
                        TaskVehicleDriveToCoord(driver, taxi, streetCoords.x, streetCoords.y, streetCoords.z, 25.0, 0, GetEntityModel(taxi), 786603, 1.0, true)
 | 
			
		||||
                        
 | 
			
		||||
                        lib.notify({
 | 
			
		||||
                            title = 'Taxi Service',
 | 
			
		||||
                            description = 'Dein Taxi hat Schwierigkeiten dich zu erreichen. Es versucht einen anderen Weg.',
 | 
			
		||||
                            type = 'info'
 | 
			
		||||
                        })
 | 
			
		||||
                        
 | 
			
		||||
                        routeRecalculated = true
 | 
			
		||||
                        stuckCounter = 0
 | 
			
		||||
                    else
 | 
			
		||||
                        -- Wenn keine Straße gefunden wurde, teleportiere näher
 | 
			
		||||
                        local teleportDistance = 100.0
 | 
			
		||||
                        local angle = math.random() * 2 * math.pi
 | 
			
		||||
                        local teleportX = newPlayerCoords.x + math.cos(angle) * teleportDistance
 | 
			
		||||
                        local teleportY = newPlayerCoords.y + math.sin(angle) * teleportDistance
 | 
			
		||||
                        
 | 
			
		||||
                        -- Finde Z-Koordinate
 | 
			
		||||
                        local groundZ = 0.0
 | 
			
		||||
                        local foundGround, z = GetGroundZFor_3dCoord(teleportX, teleportY, newPlayerCoords.z + 50.0, groundZ, false)
 | 
			
		||||
                        
 | 
			
		||||
                        if foundGround then
 | 
			
		||||
                            -- Teleportiere Taxi näher
 | 
			
		||||
                            SetEntityCoords(taxi, teleportX, teleportY, z + 1.0, false, false, false, false)
 | 
			
		||||
                            
 | 
			
		||||
                            -- Neue Route setzen
 | 
			
		||||
                            ClearPedTasks(driver)
 | 
			
		||||
                            TaskVehicleDriveToCoord(driver, taxi, newPlayerCoords.x, newPlayerCoords.y, newPlayerCoords.z, 25.0, 0, GetEntityModel(taxi), 786603, 1.0, true)
 | 
			
		||||
                            
 | 
			
		||||
                            lib.notify({
 | 
			
		||||
                                title = 'Taxi Service',
 | 
			
		||||
                                description = 'Dein Taxi wurde in deine Nähe teleportiert.',
 | 
			
		||||
                                type = 'info'
 | 
			
		||||
                            })
 | 
			
		||||
                            
 | 
			
		||||
                            routeRecalculated = true
 | 
			
		||||
                            stuckCounter = 0
 | 
			
		||||
                        end
 | 
			
		||||
                    end
 | 
			
		||||
                else
 | 
			
		||||
                    -- Wenn bereits versucht wurde, die Route neu zu berechnen, und es immer noch nicht funktioniert
 | 
			
		||||
                    if elapsedTime > maxWaitTime * 1.5 then
 | 
			
		||||
                        print("^1[TAXI DEBUG]^7 Taxi failed to arrive even after route recalculation")
 | 
			
		||||
                        
 | 
			
		||||
                        -- Teleportiere direkt zum Spieler als letzten Ausweg
 | 
			
		||||
                        local newPlayerCoords = GetEntityCoords(PlayerPedId())
 | 
			
		||||
                        local heading = GetEntityHeading(taxi)
 | 
			
		||||
                        
 | 
			
		||||
                        -- Finde eine Position in der Nähe des Spielers
 | 
			
		||||
                        local spawnDistance = 10.0
 | 
			
		||||
                        local angle = math.random() * 2 * math.pi
 | 
			
		||||
                        local spawnX = newPlayerCoords.x + math.cos(angle) * spawnDistance
 | 
			
		||||
                        local spawnY = newPlayerCoords.y + math.sin(angle) * spawnDistance
 | 
			
		||||
                        
 | 
			
		||||
                        -- Teleportiere Taxi direkt zum Spieler
 | 
			
		||||
                        SetEntityCoords(taxi, spawnX, spawnY, newPlayerCoords.z, false, false, false, false)
 | 
			
		||||
                        SetEntityHeading(taxi, heading)
 | 
			
		||||
                        
 | 
			
		||||
                        -- Stoppe das Taxi
 | 
			
		||||
                        if driver and DoesEntityExist(driver) then
 | 
			
		||||
                            TaskVehicleTempAction(driver, taxi, 27, 3000) -- Brake
 | 
			
		||||
                            Wait(2000)
 | 
			
		||||
                            SetVehicleDoorsLocked(taxi, 1) -- Unlock doors
 | 
			
		||||
                        end
 | 
			
		||||
                        
 | 
			
		||||
                        lib.notify({
 | 
			
		||||
                            title = 'Taxi Service',
 | 
			
		||||
                            description = 'Dein Taxi ist angekommen! Steige ein.',
 | 
			
		||||
                            type = 'success'
 | 
			
		||||
                        })
 | 
			
		||||
                        
 | 
			
		||||
                        -- qb-target für Einsteigen hinzufügen
 | 
			
		||||
                        exports['qb-target']:AddTargetEntity(taxi, {
 | 
			
		||||
                            options = {
 | 
			
		||||
                                {
 | 
			
		||||
                                    type = "client",
 | 
			
		||||
                                    event = "taxi:enterTaxi",
 | 
			
		||||
                                    icon = "fas fa-car-side",
 | 
			
		||||
                                    label = "Ins Taxi einsteigen"
 | 
			
		||||
                                }
 | 
			
		||||
                            },
 | 
			
		||||
                            distance = 3.0
 | 
			
		||||
                        })
 | 
			
		||||
                        
 | 
			
		||||
                        break
 | 
			
		||||
                    end
 | 
			
		||||
                end
 | 
			
		||||
            end
 | 
			
		||||
            
 | 
			
		||||
            lastDistance = currentDistance
 | 
			
		||||
            Wait(2000)
 | 
			
		||||
        end
 | 
			
		||||
    end)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- Event für Einsteigen ins Taxi
 | 
			
		||||
RegisterNetEvent('taxi:enterTaxi', function()
 | 
			
		||||
    print("^2[TAXI DEBUG]^7 Player entering taxi")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue