diff --git a/resources/[tools]/nordi_taxi/client/main.lua b/resources/[tools]/nordi_taxi/client/main.lua index 21df195fb..f844aa6f1 100644 --- a/resources/[tools]/nordi_taxi/client/main.lua +++ b/resources/[tools]/nordi_taxi/client/main.lua @@ -177,21 +177,62 @@ function GetTaxiSpawnPosition(playerCoords) return nil end +function SpawnTaxi(coords) + print("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords)) + + local taxiModel = GetHashKey(Config.TaxiVehicles[1].model) + print("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel) + + RequestModel(taxiModel) + local timeout = GetGameTimer() + 10000 + while not HasModelLoaded(taxiModel) and GetGameTimer() < timeout do + print("^3[TAXI DEBUG]^7 Waiting for taxi model to load...") + Wait(100) + end + + if not HasModelLoaded(taxiModel) then + print("^1[TAXI DEBUG]^7 Failed to load taxi model!") + return nil + end + + local taxi = CreateVehicle(taxiModel, coords.x, coords.y, coords.z, coords.w, true, false) + + if not DoesEntityExist(taxi) then + print("^1[TAXI DEBUG]^7 Failed to create taxi vehicle!") + return nil + end + + print("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi) + + SetEntityAsMissionEntity(taxi, true, true) + SetVehicleOnGroundProperly(taxi) + SetVehicleEngineOn(taxi, true, true, false) + SetVehicleDoorsLocked(taxi, 2) -- Locked initially + + -- Taxi-Livery setzen falls verfügbar + local liveryCount = GetVehicleLiveryCount(taxi) + if liveryCount > 0 then + SetVehicleLivery(taxi, 0) -- Erste Livery verwenden + print("^2[TAXI DEBUG]^7 Taxi livery set") + end + + SetModelAsNoLongerNeeded(taxiModel) + return taxi +end function SpawnTaxiDriver(vehicle) print("^2[TAXI DEBUG]^7 Spawning taxi driver...") -- Bessere Fahrer-Models mit Fallbacks local driverModels = { - "A_C_Chimp", -- Standard Male (sollte immer verfügbar sein) - "G_M_M_ArmGoon_01", -- Standard Female + "mp_m_freemode_01", -- Standard Male (sollte immer verfügbar sein) + "mp_f_freemode_01", -- Standard Female "a_m_y_business_01", -- Business Male "a_f_y_business_01", -- Business Female "a_m_m_business_01", -- Business Male 2 "a_m_y_downtown_01", -- Downtown Male - "A_M_O_GenStreet_01", -- Pilot - "CS_Manuel", -- Dealer - "U_M_M_Jesus_01", -- Jesus + "s_m_m_pilot_01", -- Pilot + "s_m_y_dealer_01" -- Dealer } local driver = nil @@ -610,34 +651,77 @@ end function DespawnTaxi() print("^2[TAXI DEBUG]^7 Despawning taxi") - -- Fahrer löschen + if not currentTaxi or not DoesEntityExist(currentTaxi) then + return + end + + -- Taxi wegfahren lassen, wenn ein Fahrer existiert if currentDriver and DoesEntityExist(currentDriver) then - DeleteEntity(currentDriver) - currentDriver = nil - print("^2[TAXI DEBUG]^7 Driver deleted") + print("^2[TAXI DEBUG]^7 Making taxi drive away before despawn") + + -- Zufällige Position in der Nähe finden + local taxiCoords = GetEntityCoords(currentTaxi) + local angle = math.random() * 2 * math.pi + local distance = 150.0 + local driveToX = taxiCoords.x + math.cos(angle) * distance + local driveToY = taxiCoords.y + math.sin(angle) * distance + + -- Taxi wegfahren lassen + TaskVehicleDriveToCoord(currentDriver, currentTaxi, driveToX, driveToY, taxiCoords.z, 25.0, 0, GetEntityModel(currentTaxi), 786603, 1.0, true) + + -- Blips entfernen + if taxiBlip then + RemoveBlip(taxiBlip) + taxiBlip = nil + end + + if destinationBlip then + RemoveBlip(destinationBlip) + destinationBlip = nil + } + + -- Nach 10 Sekunden tatsächlich löschen + SetTimeout(10000, function() + -- Fahrer löschen + if currentDriver and DoesEntityExist(currentDriver) then + DeleteEntity(currentDriver) + currentDriver = nil + print("^2[TAXI DEBUG]^7 Driver deleted") + end + + -- Taxi löschen + if currentTaxi and DoesEntityExist(currentTaxi) then + exports['qb-target']:RemoveTargetEntity(currentTaxi) + DeleteEntity(currentTaxi) + currentTaxi = nil + print("^2[TAXI DEBUG]^7 Taxi deleted") + end + + print("^2[TAXI DEBUG]^7 Taxi despawn completed") + end) + else + -- Sofort löschen wenn kein Fahrer da ist + if taxiBlip then + RemoveBlip(taxiBlip) + taxiBlip = nil + end + + if destinationBlip then + RemoveBlip(destinationBlip) + destinationBlip = nil + } + + -- Taxi löschen + if currentTaxi and DoesEntityExist(currentTaxi) then + exports['qb-target']:RemoveTargetEntity(currentTaxi) + DeleteEntity(currentTaxi) + currentTaxi = nil + print("^2[TAXI DEBUG]^7 Taxi deleted") + end + + print("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)") end - - -- Taxi löschen - if currentTaxi and DoesEntityExist(currentTaxi) then - exports['qb-target']:RemoveTargetEntity(currentTaxi) - DeleteEntity(currentTaxi) - currentTaxi = nil - print("^2[TAXI DEBUG]^7 Taxi deleted") - end - - -- Blips entfernen - if taxiBlip then - RemoveBlip(taxiBlip) - taxiBlip = nil - end - - if destinationBlip then - RemoveBlip(destinationBlip) - destinationBlip = nil - end - - print("^2[TAXI DEBUG]^7 Taxi despawn completed") -end +} function CalculateDistanceToCoords(coords) local playerCoords = GetEntityCoords(PlayerPedId()) diff --git a/resources/[tools]/nordi_taxi/client/stations.lua b/resources/[tools]/nordi_taxi/client/stations.lua index c1fbd3434..66a3832f1 100644 --- a/resources/[tools]/nordi_taxi/client/stations.lua +++ b/resources/[tools]/nordi_taxi/client/stations.lua @@ -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) + +