This commit is contained in:
Nordi98 2025-07-30 03:50:38 +02:00
parent ab1a686ee2
commit 4551f8c51a
2 changed files with 200 additions and 56 deletions

View file

@ -744,33 +744,91 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
return
end
-- Fahrer löschen
if not DoesEntityExist(vehicle) then
print("^1[TAXI STATIONS DEBUG]^7 Vehicle doesn't exist anymore")
-- Fahrzeug als nicht besetzt markieren
stationVehicles[stationId][vehicleId].occupied = false
stationVehicles[stationId][vehicleId].driver = nil
stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData)
end
end)
return
end
-- Wenn Fahrer existiert, Taxi zur Station zurückfahren lassen
if driver and DoesEntityExist(driver) then
DeleteEntity(driver)
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end
-- qb-target entfernen
if DoesEntityExist(vehicle) then
print("^2[TAXI STATIONS DEBUG]^7 Making taxi drive back to station")
-- Zufällige Position in der Nähe der Station finden
local stationCoords = Config.TaxiStations[stationId].coords
-- Taxi zur Station zurückfahren lassen
TaskVehicleDriveToCoord(driver, vehicle, stationCoords.x, stationCoords.y, stationCoords.z, 25.0, 0, GetEntityModel(vehicle), 786603, 1.0, true)
-- qb-target entfernen während der Fahrt
exports['qb-target']:RemoveTargetEntity(vehicle)
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
-- Fahrzeug als nicht besetzt markieren
stationVehicles[stationId][vehicleId].occupied = false
stationVehicles[stationId][vehicleId].driver = nil
stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData)
-- Nach 10 Sekunden tatsächlich löschen
SetTimeout(10000, function()
-- Fahrer löschen
if driver and DoesEntityExist(driver) then
DeleteEntity(driver)
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end
-- Fahrzeug löschen
if DoesEntityExist(vehicle) then
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
-- Fahrzeug als nicht besetzt markieren
stationVehicles[stationId][vehicleId].occupied = false
stationVehicles[stationId][vehicleId].driver = nil
stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData)
end
end)
end)
else
-- Sofort löschen wenn kein Fahrer da ist
-- qb-target entfernen
if DoesEntityExist(vehicle) then
exports['qb-target']:RemoveTargetEntity(vehicle)
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
end)
-- Fahrzeug als nicht besetzt markieren
stationVehicles[stationId][vehicleId].occupied = false
stationVehicles[stationId][vehicleId].driver = nil
stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData)
end
end)
end
end
function CalculateDistanceToCoords(coords)
@ -795,7 +853,7 @@ RegisterCommand('nearesttaxi', function()
if nearestStation then
lib.notify({
title = 'Taxi Service',
description = 'Nächste Station: ' .. nearestStation.data.name .. ' (' .. math.ceil(nearestStation.distance) .. 'm)',
description = 'Nächste Station: ' .. nearestStation.data.name .. ' (' .. math.ceil(nearestDistance) .. 'm)',
type = 'info'
})
@ -876,4 +934,6 @@ AddEventHandler('onResourceStop', function(resourceName)
print("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
end
end)