From fd82e234dad7aec43990ef7d6860024719138eed Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Wed, 30 Jul 2025 09:27:31 +0200 Subject: [PATCH] ed --- resources/[tools]/nordi_taxi/client/main.lua | 75 ++++++++++++++------ resources/[tools]/nordi_taxi/config.lua | 12 +++- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/resources/[tools]/nordi_taxi/client/main.lua b/resources/[tools]/nordi_taxi/client/main.lua index da8a355b4..4207f48e4 100644 --- a/resources/[tools]/nordi_taxi/client/main.lua +++ b/resources/[tools]/nordi_taxi/client/main.lua @@ -108,8 +108,9 @@ end function GetImprovedTaxiSpawnPosition(playerCoords) print("^2[TAXI DEBUG]^7 Finding improved spawn position...") - -- Maximale Entfernung, die wir akzeptieren - local maxAcceptableDistance = 100.0 + -- Minimale und maximale Entfernung zum Spieler + local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt + local maxAcceptableDistance = 150.0 -- Maximal 150 Meter entfernt local bestPosition = nil local bestDistance = 999999.0 @@ -119,40 +120,65 @@ function GetImprovedTaxiSpawnPosition(playerCoords) local nodePos = vector3(0.0, 0.0, 0.0) -- Versuche einen Straßenknotenpunkt in optimaler Entfernung zu finden + -- Suche in einem größeren Radius, um mehr Optionen zu haben foundNode, nodePos = GetClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0) if foundNode then local nodeDistance = #(playerCoords - nodePos) - if nodeDistance < maxAcceptableDistance then + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then roadPosition = nodePos print("^2[TAXI DEBUG]^7 Found road node for spawn at distance: " .. nodeDistance) return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0} else -- Speichern für später, falls wir nichts Besseres finden - if nodeDistance < bestDistance then + if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then bestDistance = nodeDistance bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} end end end + -- Versuche mehrere Knotenpunkte in verschiedenen Richtungen zu finden + for i = 1, 8 do + local angle = (i - 1) * 45.0 -- 8 Richtungen (0, 45, 90, 135, 180, 225, 270, 315 Grad) + local searchDistance = (minAcceptableDistance + maxAcceptableDistance) / 2 + local searchX = playerCoords.x + math.cos(math.rad(angle)) * searchDistance + local searchY = playerCoords.y + math.sin(math.rad(angle)) * searchDistance + + foundNode, nodePos = GetClosestVehicleNodeWithHeading(searchX, searchY, playerCoords.z, 1, 3.0, 0) + + if foundNode then + local nodeDistance = #(playerCoords - nodePos) + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then + print("^2[TAXI DEBUG]^7 Found directional node for spawn at distance: " .. nodeDistance .. " in direction " .. angle) + 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 and nodeDistance >= minAcceptableDistance then + bestDistance = nodeDistance + bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} + end + end + end + end + -- Versuche einen weiteren Knotenpunkt mit größerem Radius foundNode, nodePos = GetClosestMajorVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 100.0, 0) if foundNode then local nodeDistance = #(playerCoords - nodePos) - if nodeDistance < maxAcceptableDistance then + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then roadPosition = nodePos print("^2[TAXI DEBUG]^7 Found major road node for spawn at distance: " .. nodeDistance) return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0} else -- Speichern für später, falls wir nichts Besseres finden - if nodeDistance < bestDistance then + if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then bestDistance = nodeDistance bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} end end - end + } -- Fallback auf Config-Positionen if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then @@ -160,13 +186,15 @@ function GetImprovedTaxiSpawnPosition(playerCoords) local sortedSpawns = {} for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z)) - table.insert(sortedSpawns, { - coords = spawnPos, - distance = distance - }) + if distance >= minAcceptableDistance then + table.insert(sortedSpawns, { + coords = spawnPos, + distance = distance + }) + end end - -- Nach Entfernung sortieren (nächste zuerst) + -- Nach Entfernung sortieren (nächste zuerst, aber mindestens minAcceptableDistance entfernt) table.sort(sortedSpawns, function(a, b) return a.distance < b.distance end) @@ -208,21 +236,21 @@ function GetImprovedTaxiSpawnPosition(playerCoords) end end - -- Wenn wir hier sind, haben wir keine nahe Position gefunden - -- Wenn wir eine "beste" Position haben, die nur etwas zu weit weg ist, verwenden wir diese - if bestPosition then - print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m") + -- Wenn wir hier sind, haben wir keine ideale Position gefunden + -- Wenn wir eine "beste" Position haben, die den Mindestabstand einhält, verwenden wir diese + if bestPosition and bestDistance >= minAcceptableDistance then + print("^3[TAXI DEBUG]^7 Using best available position at " .. bestDistance .. "m") return bestPosition end -- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers - print("^3[TAXI DEBUG]^7 Generating random position within " .. maxAcceptableDistance .. "m of player") + print("^3[TAXI DEBUG]^7 Generating random position between " .. minAcceptableDistance .. "m and " .. maxAcceptableDistance .. "m of player") - -- Versuche bis zu 10 Mal, eine gültige Position zu finden - for attempt = 1, 10 do - -- Zufällige Position im Umkreis + -- Versuche bis zu 15 Mal, eine gültige Position zu finden + for attempt = 1, 15 do + -- Zufällige Position im Umkreis, aber mindestens minAcceptableDistance entfernt local angle = math.random() * 2 * math.pi - local distance = math.random(30, maxAcceptableDistance) + local distance = math.random(minAcceptableDistance, maxAcceptableDistance) local x = playerCoords.x + math.cos(angle) * distance local y = playerCoords.y + math.sin(angle) * distance local z = playerCoords.z @@ -240,9 +268,9 @@ function GetImprovedTaxiSpawnPosition(playerCoords) end end - -- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe + -- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe, aber mindestens minAcceptableDistance entfernt local angle = math.random() * 2 * math.pi - local distance = math.random(30, maxAcceptableDistance) + local distance = math.random(minAcceptableDistance, maxAcceptableDistance) local x = playerCoords.x + math.cos(angle) * distance local y = playerCoords.y + math.sin(angle) * distance local z = playerCoords.z @@ -257,6 +285,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords) return {x = x, y = y, z = z, w = 0.0} end + function SpawnTaxi(coords) print("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords.x) .. ", " .. tostring(coords.y) .. ", " .. tostring(coords.z)) diff --git a/resources/[tools]/nordi_taxi/config.lua b/resources/[tools]/nordi_taxi/config.lua index eb57c1133..af413e20f 100644 --- a/resources/[tools]/nordi_taxi/config.lua +++ b/resources/[tools]/nordi_taxi/config.lua @@ -6,14 +6,22 @@ Config.TaxiVehicles = { model = 'taxi', label = 'Standard Taxi', pricePerKm = 5, - spawnChance = 90 + spawnChance = 80 }, { model = 'vstretch', label = 'Luxus Limousine', pricePerKm = 15, spawnChance = 10 - } + }, + { + model = 'elegyrh7', + label = 'JDM Taxi', + pricePerKm = 15, + spawnChance = 10 + }, + + } -- Taxi Stationen mit festen Fahrzeugen