forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
e1a09511ea
commit
f99994396b
1 changed files with 74 additions and 87 deletions
|
@ -109,46 +109,85 @@ function CallTaxi()
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetImprovedTaxiSpawnPosition(playerCoords)
|
function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
print("^2[TAXI DEBUG]^7 Finding spawn position at least 100m away from player...")
|
print("^2[TAXI DEBUG]^7 Finding improved spawn position...")
|
||||||
|
|
||||||
local minDistance = 100.0 -- Mindestabstand in Metern
|
-- Maximale Entfernung, die wir akzeptieren
|
||||||
local maxDistance = 300.0 -- Maximaler Abstand in Metern
|
local maxAcceptableDistance = 100.0
|
||||||
local bestPosition = nil
|
local bestPosition = nil
|
||||||
local bestDistance = 999999.0 -- Für die nächste Position, die weit genug weg ist
|
local bestDistance = 999999.0
|
||||||
|
|
||||||
-- PRIORITÄT 1: Config-Positionen prüfen
|
-- Versuche zuerst einen Straßenknotenpunkt zu finden
|
||||||
|
local roadPosition = nil
|
||||||
|
local foundNode = false
|
||||||
|
local nodePos = vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
|
-- Versuche einen Straßenknotenpunkt in optimaler Entfernung zu finden
|
||||||
|
foundNode, nodePos = GetClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0)
|
||||||
|
|
||||||
|
if foundNode then
|
||||||
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
|
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
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
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
|
||||||
|
|
||||||
|
-- Fallback auf Config-Positionen
|
||||||
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
||||||
print("^2[TAXI DEBUG]^7 Checking config spawn positions first")
|
|
||||||
|
|
||||||
-- Alle Spawn-Positionen nach Entfernung sortieren
|
-- Alle Spawn-Positionen nach Entfernung sortieren
|
||||||
local sortedSpawns = {}
|
local sortedSpawns = {}
|
||||||
for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do
|
for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do
|
||||||
local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z))
|
local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z))
|
||||||
|
table.insert(sortedSpawns, {
|
||||||
-- Nur Positionen berücksichtigen, die mindestens minDistance entfernt sind
|
coords = spawnPos,
|
||||||
if distance >= minDistance then
|
distance = distance
|
||||||
table.insert(sortedSpawns, {
|
})
|
||||||
coords = spawnPos,
|
|
||||||
distance = distance
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Beste Position merken (für Fallback)
|
|
||||||
if distance < bestDistance then
|
|
||||||
bestDistance = distance
|
|
||||||
bestPosition = spawnPos
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
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)
|
table.sort(sortedSpawns, function(a, b)
|
||||||
return a.distance < b.distance
|
return a.distance < b.distance
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Prüfen ob die 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')
|
||||||
|
@ -167,77 +206,26 @@ 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
|
||||||
end
|
|
||||||
|
|
||||||
-- Wenn wir hier sind, waren alle Config-Positionen belegt
|
::continue::
|
||||||
-- Aber wenn wir eine gute Position gefunden haben, die weit genug weg ist, verwenden wir sie trotzdem
|
|
||||||
if bestPosition then
|
|
||||||
print("^3[TAXI DEBUG]^7 All config positions occupied, using best one anyway: " .. tostring(bestPosition.x) .. ", " .. tostring(bestPosition.y) .. ", " .. tostring(bestPosition.z) .. " (Distance: " .. bestDistance .. "m)")
|
|
||||||
return bestPosition
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PRIORITÄT 2: Straßenknotenpunkte suchen
|
-- Wenn wir hier sind, haben wir keine nahe Position gefunden
|
||||||
print("^2[TAXI DEBUG]^7 No suitable config positions, trying road nodes")
|
-- Wenn wir eine "beste" Position haben, die nur etwas zu weit weg ist, verwenden wir diese
|
||||||
|
|
||||||
-- Beste Position zurücksetzen für Straßensuche
|
|
||||||
bestPosition = nil
|
|
||||||
bestDistance = 999999.0
|
|
||||||
|
|
||||||
-- Versuche mehrere Straßenknotenpunkte zu finden
|
|
||||||
for i = 1, 10 do
|
|
||||||
local foundNode, nodePos = GetNthClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, i, 1, 3.0, 0)
|
|
||||||
|
|
||||||
if foundNode then
|
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
|
||||||
|
|
||||||
-- Wenn der Knotenpunkt im gewünschten Bereich liegt
|
|
||||||
if nodeDistance >= minDistance and nodeDistance <= maxDistance then
|
|
||||||
print("^2[TAXI DEBUG]^7 Found road node at good distance: " .. nodeDistance .. "m")
|
|
||||||
|
|
||||||
-- 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
|
|
||||||
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
|
|
||||||
elseif nodeDistance >= minDistance and nodeDistance < bestDistance then
|
|
||||||
-- Speichere den besten Knotenpunkt, auch wenn er nicht im idealen Bereich liegt
|
|
||||||
bestDistance = nodeDistance
|
|
||||||
bestPosition = {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
|
if bestPosition then
|
||||||
print("^2[TAXI DEBUG]^7 Using best road node found at distance: " .. bestDistance .. "m")
|
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
|
||||||
return bestPosition
|
return bestPosition
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PRIORITÄT 3: Zufällige Position generieren
|
-- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers
|
||||||
print("^3[TAXI DEBUG]^7 Generating random position between " .. minDistance .. "m and " .. maxDistance .. "m from player")
|
print("^3[TAXI DEBUG]^7 Generating random position within " .. maxAcceptableDistance .. "m of player")
|
||||||
|
|
||||||
-- Versuche bis zu 10 Mal, eine gültige Position zu finden
|
-- Versuche bis zu 10 Mal, eine gültige Position zu finden
|
||||||
for attempt = 1, 10 do
|
for attempt = 1, 10 do
|
||||||
-- Zufällige Position im gewünschten Abstandsbereich
|
-- Zufällige Position im Umkreis
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(minDistance, maxDistance)
|
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
|
||||||
|
@ -249,15 +237,15 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
local isOnRoad = IsPointOnRoad(x, y, groundZ)
|
local isOnRoad = IsPointOnRoad(x, y, groundZ)
|
||||||
|
|
||||||
if isOnRoad then
|
if isOnRoad then
|
||||||
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance .. "m")
|
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance)
|
||||||
return {x = x, y = y, z = groundZ, w = 0.0}
|
return {x = x, y = y, z = groundZ, w = 0.0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Absolute Notfall-Fallback: Einfach irgendwo in der gewünschten Entfernung
|
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(minDistance, maxDistance)
|
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
|
||||||
|
@ -268,12 +256,11 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
z = groundZ
|
z = groundZ
|
||||||
end
|
end
|
||||||
|
|
||||||
print("^3[TAXI DEBUG]^7 Using emergency random spawn position at distance: " .. distance .. "m")
|
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