1
0
Fork 0
forked from Simnation/Main

Update main.lua

This commit is contained in:
Nordi98 2025-07-30 06:32:52 +02:00
parent f99994396b
commit b37e81f58d

View file

@ -109,85 +109,54 @@ function CallTaxi()
end
function GetImprovedTaxiSpawnPosition(playerCoords)
print("^2[TAXI DEBUG]^7 Finding improved spawn position...")
print("^2[TAXI DEBUG]^7 Finding optimal spawn position (preferably 100m+ away)...")
-- Maximale Entfernung, die wir akzeptieren
local maxAcceptableDistance = 100.0
local minPreferredDistance = 100.0 -- Bevorzugter Mindestabstand in Metern
local maxDistance = 300.0 -- Maximaler Abstand in Metern
local bestPosition = nil
local bestDistance = 999999.0
-- 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
-- PRIORITÄT 1: Config-Positionen prüfen
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
print("^2[TAXI DEBUG]^7 Checking config spawn positions first")
-- Alle Spawn-Positionen nach Entfernung sortieren
local sortedSpawns = {}
local nearbySpawns = {} -- Für Positionen, die näher als minPreferredDistance sind
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 >= minPreferredDistance then
-- Bevorzugte Entfernung
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
-- Nach Entfernung sortieren (nächste zuerst)
-- Nach Entfernung sortieren (nächste zuerst, aber nur die, die weit genug weg sind)
table.sort(sortedSpawns, function(a, b)
return a.distance < b.distance
end)
-- Prüfen ob die nächsten Positionen frei und nah genug sind
-- Prüfen ob die bevorzugten Positionen frei 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')
@ -206,26 +175,112 @@ 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
end
-- Wenn keine bevorzugte Position frei ist, aber wir eine gefunden haben, verwenden wir sie trotzdem
if bestPosition then
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 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")
::continue::
-- 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
-- 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
-- PRIORITÄT 2: Straßenknotenpunkte suchen
print("^2[TAXI DEBUG]^7 No suitable config positions, 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
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)
-- Für Notfall-Fallback: Speichere den nächsten Knotenpunkt
if nodeDistance < nearestNodeDistance then
nearestNodeDistance = nodeDistance
nearestNodePos = nodePos
end
-- Wenn der Knotenpunkt im bevorzugten Bereich liegt
if nodeDistance >= minPreferredDistance then
-- 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
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
-- Wenn wir einen guten Knotenpunkt gefunden haben, verwende ihn
if bestPosition then
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
print("^2[TAXI DEBUG]^7 Using best road node found at distance: " .. 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")
-- PRIORITÄT 3: Zufällige Position generieren (bevorzugt weit genug weg)
print("^3[TAXI DEBUG]^7 Generating random position...")
-- Versuche bis zu 10 Mal, eine gültige Position zu finden
-- Versuche bis zu 10 Mal, eine gültige Position zu finden (bevorzugt weit genug weg)
for attempt = 1, 10 do
-- Zufällige Position im Umkreis
-- Zufällige Position im bevorzugten Abstandsbereich
local angle = math.random() * 2 * math.pi
local distance = math.random(30, maxAcceptableDistance)
local distance = math.random(minPreferredDistance, maxDistance)
local x = playerCoords.x + math.cos(angle) * distance
local y = playerCoords.y + math.sin(angle) * distance
local z = playerCoords.z
@ -237,15 +292,22 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local isOnRoad = IsPointOnRoad(x, y, groundZ)
if isOnRoad then
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance)
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance .. "m")
return {x = x, y = y, z = groundZ, w = 0.0}
end
end
end
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
-- NOTFALL-FALLBACK 1: Verwende den nächsten gefundenen Straßenknotenpunkt
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")
local angle = math.random() * 2 * math.pi
local distance = math.random(30, maxAcceptableDistance)
local distance = math.random(30, 80) -- Näher als bevorzugt, aber nicht zu nah
local x = playerCoords.x + math.cos(angle) * distance
local y = playerCoords.y + math.sin(angle) * distance
local z = playerCoords.z
@ -256,11 +318,11 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
z = groundZ
end
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))