forked from Simnation/Main
Update stations.lua
This commit is contained in:
parent
6a9aa73201
commit
764079c6a7
1 changed files with 101 additions and 72 deletions
|
@ -830,50 +830,68 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
|
||||||
local drivingStyle = 786603 -- Normal/Vorsichtig
|
local drivingStyle = 786603 -- Normal/Vorsichtig
|
||||||
TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0)
|
TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0)
|
||||||
|
|
||||||
|
-- Fahrt überwachen
|
||||||
|
CreateThread(function()
|
||||||
|
local lastPos = GetEntityCoords(vehicle)
|
||||||
|
local stuckCounter = 0
|
||||||
|
local maxStuckCount = 20 -- Erhöht von 5 auf 20 für viel mehr Geduld
|
||||||
|
local stuckThreshold = 0.5 -- Reduziert von 1.0 auf 0.5 für genauere Erkennung
|
||||||
|
local checkInterval = 3000 -- Erhöht von 2000 auf 3000 ms für längere Prüfintervalle
|
||||||
|
local rideTimeout = GetGameTimer() + (8 * 60 * 1000) -- 8 Minuten Timeout (erhöht von 5)
|
||||||
|
local lastStuckWarning = 0 -- Zeitpunkt der letzten Steckenbleiben-Warnung
|
||||||
|
|
||||||
-- Fahrt überwachen
|
while DoesEntityExist(vehicle) and DoesEntityExist(driver) do
|
||||||
CreateThread(function()
|
local vehicleCoords = GetEntityCoords(vehicle)
|
||||||
local lastPos = GetEntityCoords(vehicle)
|
local distance = #(vector3(destination.x, destination.y, destination.z) - vehicleCoords)
|
||||||
local stuckCounter = 0
|
local distanceMoved = #(lastPos - vehicleCoords)
|
||||||
local maxStuckCount = 10
|
|
||||||
local rideTimeout = GetGameTimer() + (10 * 60 * 1000) -- 5 Minuten Timeout
|
|
||||||
|
|
||||||
while DoesEntityExist(vehicle) and DoesEntityExist(driver) do
|
-- Überprüfen ob wir angekommen sind
|
||||||
local vehicleCoords = GetEntityCoords(vehicle)
|
if distance < 10.0 then
|
||||||
local distance = #(vector3(destination.x, destination.y, destination.z) - vehicleCoords)
|
-- Angekommen
|
||||||
local distanceMoved = #(lastPos - vehicleCoords)
|
TaskVehicleTempAction(driver, vehicle, 27, 3000)
|
||||||
|
|
||||||
-- Überprüfen ob wir angekommen sind
|
print("^2[TAXI STATIONS DEBUG]^7 Arrived at destination")
|
||||||
if distance < 10.0 then
|
lib.notify({
|
||||||
-- Angekommen
|
title = 'Taxi Service',
|
||||||
TaskVehicleTempAction(driver, vehicle, 27, 3000)
|
description = 'Du bist angekommen! Preis: $' .. price,
|
||||||
|
type = 'success'
|
||||||
print("^2[TAXI STATIONS DEBUG]^7 Arrived at destination")
|
})
|
||||||
lib.notify({
|
|
||||||
title = 'Taxi Service',
|
-- Bezahlung
|
||||||
description = 'Du bist angekommen! Preis: $' .. price,
|
TriggerServerEvent('taxi:payFare', price)
|
||||||
type = 'success'
|
|
||||||
})
|
-- Blip entfernen
|
||||||
|
RemoveBlip(destinationBlip)
|
||||||
-- Bezahlung
|
|
||||||
TriggerServerEvent('taxi:payFare', price)
|
-- Nach 10 Sekunden Taxi zurück zur Station
|
||||||
|
SetTimeout(10000, function()
|
||||||
-- Blip entfernen
|
ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
|
||||||
RemoveBlip(destinationBlip)
|
end)
|
||||||
|
|
||||||
-- Nach 10 Sekunden Taxi zurück zur Station
|
break
|
||||||
SetTimeout(10000, function()
|
end
|
||||||
ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
|
|
||||||
end)
|
-- Überprüfen ob das Taxi stecken geblieben ist
|
||||||
|
-- Prüfe auch ob das Fahrzeug steht (Geschwindigkeit nahe 0)
|
||||||
break
|
local speed = GetEntitySpeed(vehicle)
|
||||||
|
local isAtRedLight = IsVehicleStoppedAtTrafficLights(vehicle)
|
||||||
|
|
||||||
|
-- Wenn das Fahrzeug an einer Ampel steht, nicht als steckengeblieben betrachten
|
||||||
|
if distanceMoved < stuckThreshold and speed < 0.5 and not isAtRedLight then
|
||||||
|
stuckCounter = stuckCounter + 1
|
||||||
|
|
||||||
|
-- Nur alle 5 Zähler-Erhöhungen loggen, um Spam zu vermeiden
|
||||||
|
if stuckCounter % 5 == 0 then
|
||||||
|
print("^3[TAXI STATIONS DEBUG]^7 Taxi might be stuck: " .. stuckCounter .. "/" .. maxStuckCount)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Überprüfen ob das Taxi stecken geblieben ist
|
-- Nur versuchen zu befreien, wenn wirklich lange steckengeblieben
|
||||||
if distanceMoved < 1.0 then
|
if stuckCounter >= maxStuckCount then
|
||||||
stuckCounter = stuckCounter + 1
|
-- Mindestens 30 Sekunden zwischen Befreiungsversuchen warten
|
||||||
|
local currentTime = GetGameTimer()
|
||||||
if stuckCounter >= maxStuckCount then
|
if currentTime - lastStuckWarning > 30000 then
|
||||||
|
lastStuckWarning = currentTime
|
||||||
|
|
||||||
print("^1[TAXI STATIONS DEBUG]^7 Taxi stuck during ride, attempting recovery")
|
print("^1[TAXI STATIONS DEBUG]^7 Taxi stuck during ride, attempting recovery")
|
||||||
|
|
||||||
-- Versuche, das Taxi zu befreien
|
-- Versuche, das Taxi zu befreien
|
||||||
|
@ -895,47 +913,58 @@ TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y,
|
||||||
local drivingStyle = 786603 -- Normal/Vorsichtig
|
local drivingStyle = 786603 -- Normal/Vorsichtig
|
||||||
TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0)
|
TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0)
|
||||||
|
|
||||||
stuckCounter = 0
|
-- Steckenbleiben-Zähler zurücksetzen, aber nicht ganz auf 0
|
||||||
|
-- So kann ein wirklich festgefahrenes Taxi nach einiger Zeit einen neuen Versuch starten
|
||||||
|
stuckCounter = maxStuckCount / 2
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- Wenn sich das Fahrzeug bewegt oder an einer Ampel steht, Zähler langsamer reduzieren
|
||||||
|
if isAtRedLight then
|
||||||
|
-- An Ampel: Zähler nicht erhöhen, aber auch nicht stark reduzieren
|
||||||
|
stuckCounter = math.max(0, stuckCounter - 0.2)
|
||||||
else
|
else
|
||||||
|
-- In Bewegung: Zähler reduzieren
|
||||||
stuckCounter = math.max(0, stuckCounter - 1)
|
stuckCounter = math.max(0, stuckCounter - 1)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Überprüfen ob die Fahrt zu lange dauert
|
||||||
|
if GetGameTimer() > rideTimeout then
|
||||||
|
print("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!")
|
||||||
|
lib.notify({
|
||||||
|
title = 'Taxi Service',
|
||||||
|
description = 'Die Fahrt dauert zu lange. Wir sind fast da!',
|
||||||
|
type = 'warning'
|
||||||
|
})
|
||||||
|
|
||||||
-- Überprüfen ob die Fahrt zu lange dauert
|
-- Teleportiere Taxi in die Nähe des Ziels
|
||||||
if GetGameTimer() > rideTimeout then
|
local offset = vector3(
|
||||||
print("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!")
|
math.random(-20, 20),
|
||||||
lib.notify({
|
math.random(-20, 20),
|
||||||
title = 'Taxi Service',
|
0
|
||||||
description = 'Die Fahrt dauert zu lange. Wir sind fast da!',
|
)
|
||||||
type = 'warning'
|
local nearDestination = vector3(destination.x, destination.y, destination.z) + offset
|
||||||
})
|
|
||||||
|
-- Finde gültige Z-Koordinate
|
||||||
-- Teleportiere Taxi in die Nähe des Ziels
|
local success, groundZ = GetGroundZFor_3dCoord(nearDestination.x, nearDestination.y, nearDestination.z, true)
|
||||||
local offset = vector3(
|
if success then
|
||||||
math.random(-20, 20),
|
nearDestination = vector3(nearDestination.x, nearDestination.y, groundZ)
|
||||||
math.random(-20, 20),
|
|
||||||
0
|
|
||||||
)
|
|
||||||
local nearDestination = vector3(destination.x, destination.y, destination.z) + offset
|
|
||||||
|
|
||||||
-- Finde gültige Z-Koordinate
|
|
||||||
local success, groundZ = GetGroundZFor_3dCoord(nearDestination.x, nearDestination.y, nearDestination.z, true)
|
|
||||||
if success then
|
|
||||||
nearDestination = vector3(nearDestination.x, nearDestination.y, groundZ)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Teleportiere Taxi
|
|
||||||
SetEntityCoords(vehicle, nearDestination.x, nearDestination.y, nearDestination.z, false, false, false, false)
|
|
||||||
|
|
||||||
-- Neues Timeout setzen (1 Minute)
|
|
||||||
rideTimeout = GetGameTimer() + (60 * 1000)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
lastPos = vehicleCoords
|
-- Teleportiere Taxi
|
||||||
Wait(2000)
|
SetEntityCoords(vehicle, nearDestination.x, nearDestination.y, nearDestination.z, false, false, false, false)
|
||||||
|
|
||||||
|
-- Neues Timeout setzen (1 Minute)
|
||||||
|
rideTimeout = GetGameTimer() + (60 * 1000)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
end
|
lastPos = vehicleCoords
|
||||||
|
Wait(checkInterval)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ExitStationTaxi(stationId, vehicleId, vehicle, driver)
|
function ExitStationTaxi(stationId, vehicleId, vehicle, driver)
|
||||||
print("^2[TAXI STATIONS DEBUG]^7 Player exiting station taxi")
|
print("^2[TAXI STATIONS DEBUG]^7 Player exiting station taxi")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue