1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-30 09:27:31 +02:00
parent 0b8f45315a
commit fd82e234da
2 changed files with 62 additions and 25 deletions

View file

@ -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))

View file

@ -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