forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
68ba5bd306
commit
95ea9ceed2
1 changed files with 32 additions and 121 deletions
|
@ -109,12 +109,7 @@ function CallTaxi()
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetImprovedTaxiSpawnPosition(playerCoords)
|
function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
print("^2[TAXI DEBUG]^7 Finding optimal spawn position (preferably 100m+ away)...")
|
print("^2[TAXI DEBUG]^7 Finding optimal spawn position...")
|
||||||
|
|
||||||
local minPreferredDistance = 100.0 -- Bevorzugter Mindestabstand in Metern
|
|
||||||
local maxDistance = 999999.0 -- Maximaler Abstand in Metern
|
|
||||||
local bestPosition = nil
|
|
||||||
local bestDistance = 999999.0
|
|
||||||
|
|
||||||
-- PRIORITÄT 1: Config-Positionen prüfen
|
-- PRIORITÄT 1: Config-Positionen prüfen
|
||||||
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
||||||
|
@ -122,38 +117,21 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
|
|
||||||
-- Alle Spawn-Positionen nach Entfernung sortieren
|
-- Alle Spawn-Positionen nach Entfernung sortieren
|
||||||
local sortedSpawns = {}
|
local sortedSpawns = {}
|
||||||
local nearbySpawns = {} -- Für Positionen, die näher als minPreferredDistance sind
|
|
||||||
|
|
||||||
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, {
|
||||||
if distance >= minPreferredDistance then
|
coords = spawnPos,
|
||||||
-- Bevorzugte Entfernung
|
distance = distance
|
||||||
table.insert(sortedSpawns, {
|
})
|
||||||
coords = spawnPos,
|
|
||||||
distance = distance
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Beste Position merken (für Fallback)
|
|
||||||
if distance < bestDistance then
|
|
||||||
bestDistance = distance
|
|
||||||
bestPosition = spawnPos
|
|
||||||
end
|
|
||||||
else
|
|
||||||
-- Zu nahe Positionen für Notfall-Fallback speichern
|
|
||||||
table.insert(nearbySpawns, {
|
|
||||||
coords = spawnPos,
|
|
||||||
distance = distance
|
|
||||||
})
|
|
||||||
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 bevorzugten Positionen frei sind
|
-- Prüfen ob die Positionen frei sind
|
||||||
for i, spawn in ipairs(sortedSpawns) do
|
for i, spawn in ipairs(sortedSpawns) do
|
||||||
local spawnCoords = spawn.coords
|
local spawnCoords = spawn.coords
|
||||||
|
|
||||||
|
@ -177,54 +155,13 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn keine bevorzugte Position frei ist, aber wir eine gefunden haben, verwenden wir sie trotzdem
|
-- Wenn keine Position frei ist, verwende die erste (nächste) Position trotzdem
|
||||||
if bestPosition then
|
print("^3[TAXI DEBUG]^7 All config positions occupied, using first one anyway: " .. tostring(sortedSpawns[1].coords.x) .. ", " .. tostring(sortedSpawns[1].coords.y) .. ", " .. tostring(sortedSpawns[1].coords.z))
|
||||||
print("^3[TAXI DEBUG]^7 All preferred config positions occupied, using best one anyway: " .. tostring(bestPosition.x) .. ", " .. tostring(bestPosition.y) .. ", " .. tostring(bestPosition.z) .. " (Distance: " .. bestDistance .. "m)")
|
return sortedSpawns[1].coords
|
||||||
return bestPosition
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Wenn keine bevorzugten Positionen verfügbar sind, prüfe die nahen Positionen als Notfall
|
|
||||||
if #nearbySpawns > 0 then
|
|
||||||
print("^3[TAXI DEBUG]^7 No preferred positions available, checking nearby positions")
|
|
||||||
|
|
||||||
-- Nach Entfernung sortieren (weiteste zuerst, da sie näher als minPreferredDistance sind)
|
|
||||||
table.sort(nearbySpawns, function(a, b)
|
|
||||||
return a.distance > b.distance
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Prüfen ob die nahen Positionen frei sind
|
|
||||||
for i, spawn in ipairs(nearbySpawns) do
|
|
||||||
local spawnCoords = spawn.coords
|
|
||||||
|
|
||||||
-- Prüfen ob Position frei ist
|
|
||||||
local clearArea = true
|
|
||||||
local vehicles = GetGamePool('CVehicle')
|
|
||||||
|
|
||||||
for _, vehicle in ipairs(vehicles) do
|
|
||||||
local vehCoords = GetEntityCoords(vehicle)
|
|
||||||
if #(vector3(spawnCoords.x, spawnCoords.y, spawnCoords.z) - vehCoords) < 5.0 then
|
|
||||||
clearArea = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Wenn Position frei ist, verwenden
|
|
||||||
if clearArea then
|
|
||||||
print("^3[TAXI DEBUG]^7 Using nearby spawn position from config: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z) .. " (Distance: " .. spawn.distance .. "m)")
|
|
||||||
return spawnCoords
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PRIORITÄT 2: Straßenknotenpunkte suchen
|
-- PRIORITÄT 2: Straßenknotenpunkte suchen
|
||||||
print("^2[TAXI DEBUG]^7 No suitable config positions, trying road nodes")
|
print("^2[TAXI DEBUG]^7 No config positions available, trying road nodes")
|
||||||
|
|
||||||
-- Beste Position zurücksetzen für Straßensuche
|
|
||||||
bestPosition = nil
|
|
||||||
bestDistance = 999999.0
|
|
||||||
local nearestNodePos = nil
|
|
||||||
local nearestNodeDistance = 999999.0
|
|
||||||
|
|
||||||
-- Versuche mehrere Straßenknotenpunkte zu finden
|
-- Versuche mehrere Straßenknotenpunkte zu finden
|
||||||
for i = 1, 10 do
|
for i = 1, 10 do
|
||||||
|
@ -233,54 +170,33 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
if foundNode then
|
if foundNode then
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
|
|
||||||
-- Für Notfall-Fallback: Speichere den nächsten Knotenpunkt
|
-- Prüfe ob Position frei ist
|
||||||
if nodeDistance < nearestNodeDistance then
|
local clearArea = true
|
||||||
nearestNodeDistance = nodeDistance
|
local vehicles = GetGamePool('CVehicle')
|
||||||
nearestNodePos = nodePos
|
|
||||||
|
for _, vehicle in ipairs(vehicles) do
|
||||||
|
local vehCoords = GetEntityCoords(vehicle)
|
||||||
|
if #(nodePos - vehCoords) < 5.0 then
|
||||||
|
clearArea = false
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn der Knotenpunkt im bevorzugten Bereich liegt
|
if clearArea then
|
||||||
if nodeDistance >= minPreferredDistance then
|
print("^2[TAXI DEBUG]^7 Using road node at distance: " .. nodeDistance .. "m")
|
||||||
-- Prüfe ob Position frei ist
|
return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||||
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
|
|
||||||
print("^2[TAXI DEBUG]^7 Using road node at good distance: " .. nodeDistance .. "m")
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn wir einen guten Knotenpunkt gefunden haben, verwende ihn
|
-- PRIORITÄT 3: Zufällige Position auf einer Straße generieren
|
||||||
if bestPosition then
|
print("^3[TAXI DEBUG]^7 Generating random position on road...")
|
||||||
print("^2[TAXI DEBUG]^7 Using best road node found at distance: " .. bestDistance .. "m")
|
|
||||||
return bestPosition
|
|
||||||
end
|
|
||||||
|
|
||||||
-- PRIORITÄT 3: Zufällige Position generieren (bevorzugt weit genug weg)
|
-- Versuche bis zu 10 Mal, eine gültige Position auf einer Straße zu finden
|
||||||
print("^3[TAXI DEBUG]^7 Generating random position...")
|
|
||||||
|
|
||||||
-- Versuche bis zu 10 Mal, eine gültige Position zu finden (bevorzugt weit genug weg)
|
|
||||||
for attempt = 1, 10 do
|
for attempt = 1, 10 do
|
||||||
-- Zufällige Position im bevorzugten Abstandsbereich
|
-- Zufällige Position im Umkreis
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(minPreferredDistance, maxDistance)
|
local distance = math.random(50, 150) -- Moderate Entfernung
|
||||||
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
|
||||||
|
@ -298,16 +214,10 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- NOTFALL-FALLBACK 1: Verwende den nächsten gefundenen Straßenknotenpunkt
|
-- NOTFALL-FALLBACK: Zufällige Position in der Nähe
|
||||||
if nearestNodePos then
|
|
||||||
print("^1[TAXI DEBUG]^7 Using nearest road node as emergency fallback at distance: " .. nearestNodeDistance .. "m")
|
|
||||||
return {x = nearestNodePos.x, y = nearestNodePos.y, z = nearestNodePos.z, w = 0.0}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- NOTFALL-FALLBACK 2: Zufällige Position in der Nähe
|
|
||||||
print("^1[TAXI DEBUG]^7 Using emergency random spawn position")
|
print("^1[TAXI DEBUG]^7 Using emergency random spawn position")
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(30, 80) -- Näher als bevorzugt, aber nicht zu nah
|
local distance = math.random(30, 100)
|
||||||
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
|
||||||
|
@ -323,6 +233,7 @@ 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