From 95ea9ceed2fc20f8ffcf977120e75ab3a5faaee5 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 30 Jul 2025 06:37:34 +0200 Subject: [PATCH] Update main.lua --- resources/[tools]/nordi_taxi/client/main.lua | 153 ++++--------------- 1 file changed, 32 insertions(+), 121 deletions(-) diff --git a/resources/[tools]/nordi_taxi/client/main.lua b/resources/[tools]/nordi_taxi/client/main.lua index 49cbdadb5..4a727007a 100644 --- a/resources/[tools]/nordi_taxi/client/main.lua +++ b/resources/[tools]/nordi_taxi/client/main.lua @@ -109,12 +109,7 @@ function CallTaxi() end function GetImprovedTaxiSpawnPosition(playerCoords) - print("^2[TAXI DEBUG]^7 Finding optimal spawn position (preferably 100m+ away)...") - - local minPreferredDistance = 100.0 -- Bevorzugter Mindestabstand in Metern - local maxDistance = 999999.0 -- Maximaler Abstand in Metern - local bestPosition = nil - local bestDistance = 999999.0 + print("^2[TAXI DEBUG]^7 Finding optimal spawn position...") -- PRIORITÄT 1: Config-Positionen prüfen if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then @@ -122,38 +117,21 @@ function GetImprovedTaxiSpawnPosition(playerCoords) -- Alle Spawn-Positionen nach Entfernung sortieren local sortedSpawns = {} - local nearbySpawns = {} -- Für Positionen, die näher als minPreferredDistance sind for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z)) - - if distance >= minPreferredDistance then - -- Bevorzugte Entfernung - table.insert(sortedSpawns, { - coords = spawnPos, - distance = distance - }) - - -- Beste Position merken (für Fallback) - if distance < bestDistance then - bestDistance = distance - bestPosition = spawnPos - end - else - -- Zu nahe Positionen für Notfall-Fallback speichern - table.insert(nearbySpawns, { - coords = spawnPos, - distance = distance - }) - end + table.insert(sortedSpawns, { + coords = spawnPos, + distance = distance + }) end - -- Nach Entfernung sortieren (nächste zuerst, aber nur die, die weit genug weg sind) + -- Nach Entfernung sortieren (nächste zuerst) table.sort(sortedSpawns, function(a, b) return a.distance < b.distance end) - -- Prüfen ob die bevorzugten Positionen frei sind + -- Prüfen ob die Positionen frei sind for i, spawn in ipairs(sortedSpawns) do local spawnCoords = spawn.coords @@ -177,54 +155,13 @@ function GetImprovedTaxiSpawnPosition(playerCoords) end end - -- Wenn keine bevorzugte Position frei ist, aber wir eine gefunden haben, verwenden wir sie trotzdem - if bestPosition then - print("^3[TAXI DEBUG]^7 All preferred config positions occupied, using best one anyway: " .. tostring(bestPosition.x) .. ", " .. tostring(bestPosition.y) .. ", " .. tostring(bestPosition.z) .. " (Distance: " .. bestDistance .. "m)") - return bestPosition - end - - -- Wenn keine bevorzugten Positionen verfügbar sind, prüfe die nahen Positionen als Notfall - if #nearbySpawns > 0 then - print("^3[TAXI DEBUG]^7 No preferred positions available, checking nearby positions") - - -- Nach Entfernung sortieren (weiteste zuerst, da sie näher als minPreferredDistance sind) - table.sort(nearbySpawns, function(a, b) - return a.distance > b.distance - end) - - -- Prüfen ob die nahen Positionen frei sind - for i, spawn in ipairs(nearbySpawns) do - local spawnCoords = spawn.coords - - -- Prüfen ob Position frei ist - local clearArea = true - local vehicles = GetGamePool('CVehicle') - - for _, vehicle in ipairs(vehicles) do - local vehCoords = GetEntityCoords(vehicle) - if #(vector3(spawnCoords.x, spawnCoords.y, spawnCoords.z) - vehCoords) < 5.0 then - clearArea = false - break - end - end - - -- Wenn Position frei ist, verwenden - if clearArea then - print("^3[TAXI DEBUG]^7 Using nearby spawn position from config: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z) .. " (Distance: " .. spawn.distance .. "m)") - return spawnCoords - end - end - end + -- Wenn keine Position frei ist, verwende die erste (nächste) Position trotzdem + print("^3[TAXI DEBUG]^7 All config positions occupied, using first one anyway: " .. tostring(sortedSpawns[1].coords.x) .. ", " .. tostring(sortedSpawns[1].coords.y) .. ", " .. tostring(sortedSpawns[1].coords.z)) + return sortedSpawns[1].coords end -- PRIORITÄT 2: Straßenknotenpunkte suchen - print("^2[TAXI DEBUG]^7 No suitable config positions, trying road nodes") - - -- Beste Position zurücksetzen für Straßensuche - bestPosition = nil - bestDistance = 999999.0 - local nearestNodePos = nil - local nearestNodeDistance = 999999.0 + print("^2[TAXI DEBUG]^7 No config positions available, trying road nodes") -- Versuche mehrere Straßenknotenpunkte zu finden for i = 1, 10 do @@ -233,54 +170,33 @@ function GetImprovedTaxiSpawnPosition(playerCoords) if foundNode then local nodeDistance = #(playerCoords - nodePos) - -- Für Notfall-Fallback: Speichere den nächsten Knotenpunkt - if nodeDistance < nearestNodeDistance then - nearestNodeDistance = nodeDistance - nearestNodePos = nodePos + -- Prüfe ob Position frei ist + local clearArea = true + local vehicles = GetGamePool('CVehicle') + + for _, vehicle in ipairs(vehicles) do + local vehCoords = GetEntityCoords(vehicle) + if #(nodePos - vehCoords) < 5.0 then + clearArea = false + break + end end - -- Wenn der Knotenpunkt im bevorzugten Bereich liegt - if nodeDistance >= minPreferredDistance then - -- Prüfe ob Position frei ist - local clearArea = true - local vehicles = GetGamePool('CVehicle') - - for _, vehicle in ipairs(vehicles) do - local vehCoords = GetEntityCoords(vehicle) - if #(nodePos - vehCoords) < 5.0 then - clearArea = false - break - end - end - - if clearArea then - print("^2[TAXI DEBUG]^7 Using road node at good distance: " .. nodeDistance .. "m") - return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} - else - -- Speichern für später, falls wir nichts Besseres finden - if nodeDistance < bestDistance then - bestDistance = nodeDistance - bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} - end - end + if clearArea then + print("^2[TAXI DEBUG]^7 Using road node at distance: " .. nodeDistance .. "m") + return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} end end end - -- Wenn wir einen guten Knotenpunkt gefunden haben, verwende ihn - if bestPosition then - print("^2[TAXI DEBUG]^7 Using best road node found at distance: " .. bestDistance .. "m") - return bestPosition - end + -- PRIORITÄT 3: Zufällige Position auf einer Straße generieren + print("^3[TAXI DEBUG]^7 Generating random position on road...") - -- PRIORITÄT 3: Zufällige Position generieren (bevorzugt weit genug weg) - print("^3[TAXI DEBUG]^7 Generating random position...") - - -- Versuche bis zu 10 Mal, eine gültige Position zu finden (bevorzugt weit genug weg) + -- Versuche bis zu 10 Mal, eine gültige Position auf einer Straße zu finden for attempt = 1, 10 do - -- Zufällige Position im bevorzugten Abstandsbereich + -- Zufällige Position im Umkreis local angle = math.random() * 2 * math.pi - local distance = math.random(minPreferredDistance, maxDistance) + local distance = math.random(50, 150) -- Moderate Entfernung local x = playerCoords.x + math.cos(angle) * distance local y = playerCoords.y + math.sin(angle) * distance local z = playerCoords.z @@ -298,16 +214,10 @@ function GetImprovedTaxiSpawnPosition(playerCoords) end end - -- NOTFALL-FALLBACK 1: Verwende den nächsten gefundenen Straßenknotenpunkt - if nearestNodePos then - print("^1[TAXI DEBUG]^7 Using nearest road node as emergency fallback at distance: " .. nearestNodeDistance .. "m") - return {x = nearestNodePos.x, y = nearestNodePos.y, z = nearestNodePos.z, w = 0.0} - end - - -- NOTFALL-FALLBACK 2: Zufällige Position in der Nähe + -- NOTFALL-FALLBACK: Zufällige Position in der Nähe print("^1[TAXI DEBUG]^7 Using emergency random spawn position") local angle = math.random() * 2 * math.pi - local distance = math.random(30, 80) -- Näher als bevorzugt, aber nicht zu nah + local distance = math.random(30, 100) local x = playerCoords.x + math.cos(angle) * distance local y = playerCoords.y + math.sin(angle) * distance local z = playerCoords.z @@ -323,6 +233,7 @@ end + function SpawnTaxi(coords) print("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords.x) .. ", " .. tostring(coords.y) .. ", " .. tostring(coords.z))