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)
|
function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
print("^2[TAXI DEBUG]^7 Finding improved spawn position...")
|
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
|
-- Versuche zuerst einen Straßenknotenpunkt zu finden
|
||||||
local roadPosition = nil
|
local roadPosition = nil
|
||||||
local foundNode = false
|
local foundNode = false
|
||||||
|
@ -121,10 +126,16 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
|
|
||||||
if foundNode then
|
if foundNode then
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
if nodeDistance > 50.0 and nodeDistance < 150.0 then
|
if nodeDistance < maxAcceptableDistance then
|
||||||
roadPosition = nodePos
|
roadPosition = nodePos
|
||||||
print("^2[TAXI DEBUG]^7 Found road node for spawn at distance: " .. nodeDistance)
|
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}
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -133,10 +144,16 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
|
|
||||||
if foundNode then
|
if foundNode then
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
if nodeDistance > 40.0 and nodeDistance < 200.0 then
|
if nodeDistance < maxAcceptableDistance then
|
||||||
roadPosition = nodePos
|
roadPosition = nodePos
|
||||||
print("^2[TAXI DEBUG]^7 Found major road node for spawn at distance: " .. nodeDistance)
|
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}
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -157,10 +174,20 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
return a.distance < b.distance
|
return a.distance < b.distance
|
||||||
end)
|
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
|
for i, spawn in ipairs(sortedSpawns) do
|
||||||
local spawnCoords = spawn.coords
|
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
|
-- Prüfen ob Position frei ist
|
||||||
local clearArea = true
|
local clearArea = true
|
||||||
local vehicles = GetGamePool('CVehicle')
|
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)")
|
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
|
return spawnCoords
|
||||||
end
|
end
|
||||||
|
|
||||||
|
::continue::
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn keine freie Position gefunden wurde, die am weitesten entfernte verwenden
|
-- Wenn wir hier sind, haben wir keine nahe Position gefunden
|
||||||
local fallbackSpawn = sortedSpawns[#sortedSpawns].coords
|
-- Wenn wir eine "beste" Position haben, die nur etwas zu weit weg ist, verwenden wir diese
|
||||||
print("^3[TAXI DEBUG]^7 No clear spawn position found, using fallback: " .. tostring(fallbackSpawn.x) .. ", " .. tostring(fallbackSpawn.y) .. ", " .. tostring(fallbackSpawn.z))
|
if bestPosition then
|
||||||
return fallbackSpawn
|
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
|
||||||
|
return bestPosition
|
||||||
end
|
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 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 x = playerCoords.x + math.cos(angle) * distance
|
||||||
local y = playerCoords.y + math.sin(angle) * distance
|
local y = playerCoords.y + math.sin(angle) * distance
|
||||||
local z = playerCoords.z
|
local z = playerCoords.z
|
||||||
|
@ -200,10 +256,11 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
z = groundZ
|
z = groundZ
|
||||||
end
|
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}
|
return {x = x, y = y, z = z, w = 0.0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function SpawnTaxi(coords)
|
function SpawnTaxi(coords)
|
||||||
print("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords.x) .. ", " .. tostring(coords.y) .. ", " .. tostring(coords.z))
|
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