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
|
end
|
||||||
|
|
||||||
function GetImprovedTaxiSpawnPosition(playerCoords)
|
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
|
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, {
|
table.insert(sortedSpawns, {
|
||||||
|
@ -131,10 +174,20 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
|
||||||
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')
|
||||||
|
@ -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)")
|
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 keine Position frei ist, verwende die erste (nächste) Position trotzdem
|
::continue::
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
if clearArea then
|
-- Wenn wir hier sind, haben wir keine nahe Position gefunden
|
||||||
print("^2[TAXI DEBUG]^7 Using road node at distance: " .. nodeDistance .. "m")
|
-- Wenn wir eine "beste" Position haben, die nur etwas zu weit weg ist, verwenden wir diese
|
||||||
return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
|
if bestPosition then
|
||||||
end
|
print("^3[TAXI DEBUG]^7 No position within " .. maxAcceptableDistance .. "m found, using best available at " .. bestDistance .. "m")
|
||||||
end
|
return bestPosition
|
||||||
end
|
end
|
||||||
|
|
||||||
-- PRIORITÄT 3: Zufällige Position auf einer Straße generieren
|
-- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers
|
||||||
print("^3[TAXI DEBUG]^7 Generating random position on road...")
|
print("^3[TAXI DEBUG]^7 Generating random position within " .. maxAcceptableDistance .. "m of player")
|
||||||
|
|
||||||
-- Versuche bis zu 10 Mal, eine gültige Position auf einer Straße 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 Umkreis
|
-- Zufällige Position im Umkreis
|
||||||
local angle = math.random() * 2 * math.pi
|
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 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
|
||||||
|
@ -208,16 +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
|
||||||
|
|
||||||
-- NOTFALL-FALLBACK: Zufällige Position in der Nähe
|
-- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe
|
||||||
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, 100)
|
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
|
||||||
|
@ -228,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)
|
||||||
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))
|
||||||
|
|
||||||
|
@ -293,12 +320,6 @@ function SpawnTaxi(coords)
|
||||||
|
|
||||||
-- Fahrzeug konfigurieren
|
-- Fahrzeug konfigurieren
|
||||||
SetEntityAsMissionEntity(taxi, true, true)
|
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)
|
SetVehicleOnGroundProperly(taxi)
|
||||||
SetVehicleEngineOn(taxi, true, true, false)
|
SetVehicleEngineOn(taxi, true, true, false)
|
||||||
SetVehicleDoorsLocked(taxi, 2) -- Locked initially
|
SetVehicleDoorsLocked(taxi, 2) -- Locked initially
|
||||||
|
@ -1283,84 +1304,3 @@ AddEventHandler('onResourceStop', function(resourceName)
|
||||||
print("^2[TAXI DEBUG]^7 Main cleanup completed")
|
print("^2[TAXI DEBUG]^7 Main cleanup completed")
|
||||||
end
|
end
|
||||||
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