forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
8cbfc70b00
commit
81d9da934d
1 changed files with 68 additions and 11 deletions
|
@ -111,6 +111,11 @@ end
|
|||
function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||
print("^2[TAXI DEBUG]^7 Finding improved spawn position...")
|
||||
|
||||
-- Maximale Entfernung, die wir akzeptieren
|
||||
local maxAcceptableDistance = 100.0
|
||||
local bestPosition = nil
|
||||
local bestDistance = 999999.0
|
||||
|
||||
-- Versuche zuerst einen Straßenknotenpunkt zu finden
|
||||
local roadPosition = nil
|
||||
local foundNode = false
|
||||
|
@ -121,10 +126,16 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
|
||||
if foundNode then
|
||||
local nodeDistance = #(playerCoords - nodePos)
|
||||
if nodeDistance > 50.0 and nodeDistance < 150.0 then
|
||||
if 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
|
||||
bestDistance = nodeDistance
|
||||
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -133,10 +144,16 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
|
||||
if foundNode then
|
||||
local nodeDistance = #(playerCoords - nodePos)
|
||||
if nodeDistance > 40.0 and nodeDistance < 200.0 then
|
||||
if 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
|
||||
bestDistance = nodeDistance
|
||||
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -157,10 +174,20 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
return a.distance < b.distance
|
||||
end)
|
||||
|
||||
-- Prüfen ob die nächsten Positionen frei sind
|
||||
-- Prüfen ob die nächsten Positionen frei und nah genug sind
|
||||
for i, spawn in ipairs(sortedSpawns) do
|
||||
local spawnCoords = spawn.coords
|
||||
|
||||
-- Wenn Position zu weit weg ist, überspringen
|
||||
if spawn.distance > maxAcceptableDistance then
|
||||
-- Speichern für später, falls wir nichts Besseres finden
|
||||
if spawn.distance < bestDistance then
|
||||
bestDistance = spawn.distance
|
||||
bestPosition = spawnCoords
|
||||
end
|
||||
goto continue
|
||||
end
|
||||
|
||||
-- Prüfen ob Position frei ist
|
||||
local clearArea = true
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
|
@ -179,17 +206,46 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
print("^2[TAXI DEBUG]^7 Using spawn position from config: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z) .. " (Distance: " .. spawn.distance .. "m)")
|
||||
return spawnCoords
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
-- Wenn keine freie Position gefunden wurde, die am weitesten entfernte verwenden
|
||||
local fallbackSpawn = sortedSpawns[#sortedSpawns].coords
|
||||
print("^3[TAXI DEBUG]^7 No clear spawn position found, using fallback: " .. tostring(fallbackSpawn.x) .. ", " .. tostring(fallbackSpawn.y) .. ", " .. tostring(fallbackSpawn.z))
|
||||
return fallbackSpawn
|
||||
-- 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")
|
||||
return bestPosition
|
||||
end
|
||||
|
||||
-- Absolute Notfall-Fallback: Zufällige Position um Spieler herum
|
||||
-- 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")
|
||||
|
||||
-- Versuche bis zu 10 Mal, eine gültige Position zu finden
|
||||
for attempt = 1, 10 do
|
||||
-- Zufällige Position im Umkreis
|
||||
local angle = math.random() * 2 * math.pi
|
||||
local distance = math.random(80, 120)
|
||||
local distance = math.random(30, maxAcceptableDistance)
|
||||
local x = playerCoords.x + math.cos(angle) * distance
|
||||
local y = playerCoords.y + math.sin(angle) * distance
|
||||
local z = playerCoords.z
|
||||
|
||||
-- Versuche eine gültige Z-Koordinate zu bekommen
|
||||
local success, groundZ = GetGroundZFor_3dCoord(x, y, z, true)
|
||||
if success then
|
||||
-- Prüfe ob die Position auf einer Straße ist
|
||||
local isOnRoad = IsPointOnRoad(x, y, groundZ)
|
||||
|
||||
if isOnRoad then
|
||||
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance)
|
||||
return {x = x, y = y, z = groundZ, w = 0.0}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
|
||||
local angle = math.random() * 2 * math.pi
|
||||
local distance = math.random(30, maxAcceptableDistance)
|
||||
local x = playerCoords.x + math.cos(angle) * distance
|
||||
local y = playerCoords.y + math.sin(angle) * distance
|
||||
local z = playerCoords.z
|
||||
|
@ -200,10 +256,11 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
z = groundZ
|
||||
end
|
||||
|
||||
print("^3[TAXI DEBUG]^7 Using emergency random spawn position")
|
||||
print("^3[TAXI DEBUG]^7 Using emergency random spawn position at distance: " .. distance)
|
||||
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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue