forked from Simnation/Main
ed
This commit is contained in:
parent
0b8f45315a
commit
fd82e234da
2 changed files with 62 additions and 25 deletions
|
@ -108,8 +108,9 @@ 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
|
-- Minimale und maximale Entfernung zum Spieler
|
||||||
local maxAcceptableDistance = 100.0
|
local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt
|
||||||
|
local maxAcceptableDistance = 150.0 -- Maximal 150 Meter entfernt
|
||||||
local bestPosition = nil
|
local bestPosition = nil
|
||||||
local bestDistance = 999999.0
|
local bestDistance = 999999.0
|
||||||
|
|
||||||
|
@ -119,40 +120,65 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
local nodePos = vector3(0.0, 0.0, 0.0)
|
local nodePos = vector3(0.0, 0.0, 0.0)
|
||||||
|
|
||||||
-- Versuche einen Straßenknotenpunkt in optimaler Entfernung zu finden
|
-- Versuche einen Straßenknotenpunkt in optimaler Entfernung zu finden
|
||||||
|
-- Suche in einem größeren Radius, um mehr Optionen zu haben
|
||||||
foundNode, nodePos = GetClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0)
|
foundNode, nodePos = GetClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0)
|
||||||
|
|
||||||
if foundNode then
|
if foundNode then
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
if nodeDistance < maxAcceptableDistance then
|
if nodeDistance >= minAcceptableDistance and 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
|
else
|
||||||
-- Speichern für später, falls wir nichts Besseres finden
|
-- Speichern für später, falls wir nichts Besseres finden
|
||||||
if nodeDistance < bestDistance then
|
if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then
|
||||||
bestDistance = nodeDistance
|
bestDistance = nodeDistance
|
||||||
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Versuche mehrere Knotenpunkte in verschiedenen Richtungen zu finden
|
||||||
|
for i = 1, 8 do
|
||||||
|
local angle = (i - 1) * 45.0 -- 8 Richtungen (0, 45, 90, 135, 180, 225, 270, 315 Grad)
|
||||||
|
local searchDistance = (minAcceptableDistance + maxAcceptableDistance) / 2
|
||||||
|
local searchX = playerCoords.x + math.cos(math.rad(angle)) * searchDistance
|
||||||
|
local searchY = playerCoords.y + math.sin(math.rad(angle)) * searchDistance
|
||||||
|
|
||||||
|
foundNode, nodePos = GetClosestVehicleNodeWithHeading(searchX, searchY, playerCoords.z, 1, 3.0, 0)
|
||||||
|
|
||||||
|
if foundNode then
|
||||||
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
|
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
|
||||||
|
print("^2[TAXI DEBUG]^7 Found directional node for spawn at distance: " .. nodeDistance .. " in direction " .. angle)
|
||||||
|
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 and nodeDistance >= minAcceptableDistance then
|
||||||
|
bestDistance = nodeDistance
|
||||||
|
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Versuche einen weiteren Knotenpunkt mit größerem Radius
|
-- Versuche einen weiteren Knotenpunkt mit größerem Radius
|
||||||
foundNode, nodePos = GetClosestMajorVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 100.0, 0)
|
foundNode, nodePos = GetClosestMajorVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 100.0, 0)
|
||||||
|
|
||||||
if foundNode then
|
if foundNode then
|
||||||
local nodeDistance = #(playerCoords - nodePos)
|
local nodeDistance = #(playerCoords - nodePos)
|
||||||
if nodeDistance < maxAcceptableDistance then
|
if nodeDistance >= minAcceptableDistance and 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
|
else
|
||||||
-- Speichern für später, falls wir nichts Besseres finden
|
-- Speichern für später, falls wir nichts Besseres finden
|
||||||
if nodeDistance < bestDistance then
|
if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then
|
||||||
bestDistance = nodeDistance
|
bestDistance = nodeDistance
|
||||||
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
}
|
||||||
|
|
||||||
-- Fallback auf Config-Positionen
|
-- Fallback auf Config-Positionen
|
||||||
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then
|
||||||
|
@ -160,13 +186,15 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
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, {
|
if distance >= minAcceptableDistance then
|
||||||
coords = spawnPos,
|
table.insert(sortedSpawns, {
|
||||||
distance = distance
|
coords = spawnPos,
|
||||||
})
|
distance = distance
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Nach Entfernung sortieren (nächste zuerst)
|
-- Nach Entfernung sortieren (nächste zuerst, aber mindestens minAcceptableDistance entfernt)
|
||||||
table.sort(sortedSpawns, function(a, b)
|
table.sort(sortedSpawns, function(a, b)
|
||||||
return a.distance < b.distance
|
return a.distance < b.distance
|
||||||
end)
|
end)
|
||||||
|
@ -208,21 +236,21 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn wir hier sind, haben wir keine nahe Position gefunden
|
-- Wenn wir hier sind, haben wir keine ideale Position gefunden
|
||||||
-- Wenn wir eine "beste" Position haben, die nur etwas zu weit weg ist, verwenden wir diese
|
-- Wenn wir eine "beste" Position haben, die den Mindestabstand einhält, verwenden wir diese
|
||||||
if bestPosition then
|
if bestPosition and bestDistance >= minAcceptableDistance then
|
||||||
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
|
print("^3[TAXI DEBUG]^7 Using best available position at " .. bestDistance .. "m")
|
||||||
return bestPosition
|
return bestPosition
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers
|
-- 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")
|
print("^3[TAXI DEBUG]^7 Generating random position between " .. minAcceptableDistance .. "m and " .. maxAcceptableDistance .. "m of player")
|
||||||
|
|
||||||
-- Versuche bis zu 10 Mal, eine gültige Position zu finden
|
-- Versuche bis zu 15 Mal, eine gültige Position zu finden
|
||||||
for attempt = 1, 10 do
|
for attempt = 1, 15 do
|
||||||
-- Zufällige Position im Umkreis
|
-- Zufällige Position im Umkreis, aber mindestens minAcceptableDistance entfernt
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(30, maxAcceptableDistance)
|
local distance = math.random(minAcceptableDistance, 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
|
||||||
|
@ -240,9 +268,9 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
|
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe, aber mindestens minAcceptableDistance entfernt
|
||||||
local angle = math.random() * 2 * math.pi
|
local angle = math.random() * 2 * math.pi
|
||||||
local distance = math.random(30, maxAcceptableDistance)
|
local distance = math.random(minAcceptableDistance, 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
|
||||||
|
@ -257,6 +285,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
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))
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,22 @@ Config.TaxiVehicles = {
|
||||||
model = 'taxi',
|
model = 'taxi',
|
||||||
label = 'Standard Taxi',
|
label = 'Standard Taxi',
|
||||||
pricePerKm = 5,
|
pricePerKm = 5,
|
||||||
spawnChance = 90
|
spawnChance = 80
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model = 'vstretch',
|
model = 'vstretch',
|
||||||
label = 'Luxus Limousine',
|
label = 'Luxus Limousine',
|
||||||
pricePerKm = 15,
|
pricePerKm = 15,
|
||||||
spawnChance = 10
|
spawnChance = 10
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
model = 'elegyrh7',
|
||||||
|
label = 'JDM Taxi',
|
||||||
|
pricePerKm = 15,
|
||||||
|
spawnChance = 10
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Taxi Stationen mit festen Fahrzeugen
|
-- Taxi Stationen mit festen Fahrzeugen
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue