From a47b4f6672985ed94e70f1cb2b170e30fec2ef4f Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 30 Jul 2025 05:16:13 +0200 Subject: [PATCH] ed --- resources/[tools]/nordi_taxi/client/main.lua | 125 ++++++++++++++++++- resources/[tools]/nordi_taxi/config.lua | 2 +- 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/resources/[tools]/nordi_taxi/client/main.lua b/resources/[tools]/nordi_taxi/client/main.lua index bf7e9fc2d..8014d56a3 100644 --- a/resources/[tools]/nordi_taxi/client/main.lua +++ b/resources/[tools]/nordi_taxi/client/main.lua @@ -384,11 +384,19 @@ 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 distance = #(playerCoords - taxiCoords) + local currentDistance = #(playerCoords - taxiCoords) + local elapsedTime = GetGameTimer() - startTime - if distance < 15.0 then + -- Taxi ist angekommen + if currentDistance < 15.0 then print("^2[TAXI DEBUG]^7 Taxi arrived!") -- Taxi stoppen @@ -420,11 +428,124 @@ 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") diff --git a/resources/[tools]/nordi_taxi/config.lua b/resources/[tools]/nordi_taxi/config.lua index 0f91b33d0..26e9e8576 100644 --- a/resources/[tools]/nordi_taxi/config.lua +++ b/resources/[tools]/nordi_taxi/config.lua @@ -138,7 +138,7 @@ Config.KnownDestinations = { }, { name = "Maze Bank Tower", - coords = vector3(-75.0, -818.0, 326.0), + coords = vector3(-46.24, -787.47, 44.14), price = 40 }, {