1
0
Fork 0
forked from Simnation/Main

Update stations.lua

This commit is contained in:
Nordi98 2025-07-30 08:31:19 +02:00
parent 6a9aa73201
commit 764079c6a7

View file

@ -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") -- Bezahlung
lib.notify({ TriggerServerEvent('taxi:payFare', price)
title = 'Taxi Service',
description = 'Du bist angekommen! Preis: $' .. price,
type = 'success'
})
-- Bezahlung -- Blip entfernen
TriggerServerEvent('taxi:payFare', price) RemoveBlip(destinationBlip)
-- Blip entfernen -- Nach 10 Sekunden Taxi zurück zur Station
RemoveBlip(destinationBlip) SetTimeout(10000, function()
ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
end)
-- Nach 10 Sekunden Taxi zurück zur Station break
SetTimeout(10000, function() end
ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
end)
break -- Überprüfen ob das Taxi stecken geblieben ist
-- Prüfe auch ob das Fahrzeug steht (Geschwindigkeit nahe 0)
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 currentTime - lastStuckWarning > 30000 then
lastStuckWarning = currentTime
if stuckCounter >= maxStuckCount then
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 -- Überprüfen ob die Fahrt zu lange dauert
if GetGameTimer() > rideTimeout then if GetGameTimer() > rideTimeout then
print("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!") print("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Die Fahrt dauert zu lange. Wir sind fast da!', description = 'Die Fahrt dauert zu lange. Wir sind fast da!',
type = 'warning' type = 'warning'
}) })
-- Teleportiere Taxi in die Nähe des Ziels -- Teleportiere Taxi in die Nähe des Ziels
local offset = vector3( local offset = vector3(
math.random(-20, 20), math.random(-20, 20),
math.random(-20, 20), math.random(-20, 20),
0 0
) )
local nearDestination = vector3(destination.x, destination.y, destination.z) + offset local nearDestination = vector3(destination.x, destination.y, destination.z) + offset
-- Finde gültige Z-Koordinate -- Finde gültige Z-Koordinate
local success, groundZ = GetGroundZFor_3dCoord(nearDestination.x, nearDestination.y, nearDestination.z, true) local success, groundZ = GetGroundZFor_3dCoord(nearDestination.x, nearDestination.y, nearDestination.z, true)
if success then if success then
nearDestination = vector3(nearDestination.x, nearDestination.y, groundZ) 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")