forked from Simnation/Main
Update main.lua
This commit is contained in:
parent
7981aba9e5
commit
f4caa0335a
1 changed files with 75 additions and 135 deletions
|
@ -109,15 +109,58 @@ function CallTaxi()
|
|||
end
|
||||
|
||||
function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||
print("^2[TAXI DEBUG]^7 Finding optimal spawn position...")
|
||||
print("^2[TAXI DEBUG]^7 Finding improved spawn position...")
|
||||
|
||||
-- PRIORITÄT 1: Config-Positionen prüfen
|
||||
-- Maximale Entfernung, die wir akzeptieren
|
||||
local maxAcceptableDistance = 100.0
|
||||
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
|
||||
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 = {}
|
||||
|
||||
for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do
|
||||
local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z))
|
||||
table.insert(sortedSpawns, {
|
||||
|
@ -131,10 +174,20 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
|||
return a.distance < b.distance
|
||||
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
|
||||
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')
|
||||
|
@ -153,50 +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)")
|
||||
return spawnCoords
|
||||
end
|
||||
end
|
||||
|
||||
-- Wenn keine Position frei ist, verwende die erste (nächste) Position trotzdem
|
||||
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))
|
||||
return sortedSpawns[1].coords
|
||||
end
|
||||
|
||||
-- PRIORITÄT 2: Straßenknotenpunkte suchen
|
||||
print("^2[TAXI DEBUG]^7 No config positions available, trying road nodes")
|
||||
|
||||
-- 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)
|
||||
|
||||
-- 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 distance: " .. nodeDistance .. "m")
|
||||
return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
||||
end
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
-- PRIORITÄT 3: Zufällige Position auf einer Straße generieren
|
||||
print("^3[TAXI DEBUG]^7 Generating random position on road...")
|
||||
-- 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
|
||||
if bestPosition then
|
||||
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
|
||||
return bestPosition
|
||||
end
|
||||
|
||||
-- Versuche bis zu 10 Mal, eine gültige Position auf einer Straße zu finden
|
||||
-- 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 distance = math.random(50, 150) -- Moderate Entfernung
|
||||
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
|
||||
|
@ -208,16 +237,15 @@ 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 .. "m")
|
||||
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
|
||||
|
||||
-- NOTFALL-FALLBACK: Zufällige Position in der Nähe
|
||||
print("^1[TAXI DEBUG]^7 Using emergency random spawn position")
|
||||
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
|
||||
local angle = math.random() * 2 * math.pi
|
||||
local distance = math.random(30, 100)
|
||||
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
|
||||
|
@ -228,12 +256,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))
|
||||
|
||||
|
@ -293,12 +320,6 @@ function SpawnTaxi(coords)
|
|||
|
||||
-- Fahrzeug konfigurieren
|
||||
SetEntityAsMissionEntity(taxi, true, true)
|
||||
SetEntityInvincible(taxi, true)
|
||||
SetVehicleCanBeVisiblyDamaged(taxi, false)
|
||||
SetEntityProofs(taxi, true, true, true, true, true, true, true, true)
|
||||
SetVehicleExplodesOnHighExplosionDamage(taxi, false)
|
||||
SetVehicleHasBeenOwnedByPlayer(taxi, true)
|
||||
SetVehicleIsConsideredByPlayer(taxi, true)
|
||||
SetVehicleOnGroundProperly(taxi)
|
||||
SetVehicleEngineOn(taxi, true, true, false)
|
||||
SetVehicleDoorsLocked(taxi, 2) -- Locked initially
|
||||
|
@ -1283,84 +1304,3 @@ AddEventHandler('onResourceStop', function(resourceName)
|
|||
print("^2[TAXI DEBUG]^7 Main cleanup completed")
|
||||
end
|
||||
end)
|
||||
|
||||
-- Starte die Taxi-Überwachung
|
||||
function MonitorTaxiExistence()
|
||||
CreateThread(function()
|
||||
local lastKnownPosition = nil
|
||||
local lastKnownHeading = 0.0
|
||||
|
||||
while true do
|
||||
Wait(2000) -- Alle 2 Sekunden prüfen
|
||||
|
||||
if currentTaxi ~= nil then
|
||||
if DoesEntityExist(currentTaxi) then
|
||||
-- Speichere aktuelle Position für Notfall-Respawn
|
||||
lastKnownPosition = GetEntityCoords(currentTaxi)
|
||||
lastKnownHeading = GetEntityHeading(currentTaxi)
|
||||
else
|
||||
-- Taxi existiert nicht mehr, aber sollte existieren
|
||||
print("^1[TAXI DEBUG]^7 Taxi disappeared unexpectedly, respawning...")
|
||||
|
||||
-- Speichere wichtige Informationen
|
||||
local hadDriver = (currentDriver ~= nil and DoesEntityExist(currentDriver))
|
||||
local playerInTaxi = false
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
-- Altes Taxi und Fahrer aufräumen
|
||||
if currentDriver and DoesEntityExist(currentDriver) then
|
||||
DeleteEntity(currentDriver)
|
||||
end
|
||||
currentDriver = nil
|
||||
|
||||
-- Bestimme Respawn-Position
|
||||
local respawnPos
|
||||
if lastKnownPosition then
|
||||
respawnPos = {
|
||||
x = lastKnownPosition.x,
|
||||
y = lastKnownPosition.y,
|
||||
z = lastKnownPosition.z,
|
||||
w = lastKnownHeading
|
||||
}
|
||||
else
|
||||
-- Fallback: In der Nähe des Spielers spawnen
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
respawnPos = {
|
||||
x = playerCoords.x + math.random(-10, 10),
|
||||
y = playerCoords.y + math.random(-10, 10),
|
||||
z = playerCoords.z,
|
||||
w = 0.0
|
||||
}
|
||||
end
|
||||
|
||||
-- Neues Taxi spawnen
|
||||
local newTaxi = SpawnTaxi(respawnPos)
|
||||
if newTaxi then
|
||||
currentTaxi = newTaxi
|
||||
|
||||
-- Neuen Fahrer spawnen wenn nötig
|
||||
if hadDriver then
|
||||
local newDriver = SpawnTaxiDriver(newTaxi)
|
||||
if newDriver then
|
||||
currentDriver = newDriver
|
||||
|
||||
-- Navigation fortsetzen wenn nötig
|
||||
local playerCoords = GetEntityCoords(playerPed)
|
||||
NavigateToPlayer(currentDriver, currentTaxi, playerCoords)
|
||||
end
|
||||
end
|
||||
|
||||
-- Blips neu erstellen
|
||||
CreateTaxiBlips(newTaxi)
|
||||
|
||||
lib.notify({
|
||||
title = 'Taxi Service',
|
||||
description = 'Dein Taxi wurde ersetzt.',
|
||||
type = 'info'
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue