Update stations.lua
This commit is contained in:
		
							parent
							
								
									7c23484c7c
								
							
						
					
					
						commit
						395693bac1
					
				
					 1 changed files with 146 additions and 59 deletions
				
			
		|  | @ -157,36 +157,84 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data) | ||||||
|     -- Türen entsperren |     -- Türen entsperren | ||||||
|     SetVehicleDoorsLocked(vehicle, 1) |     SetVehicleDoorsLocked(vehicle, 1) | ||||||
|      |      | ||||||
|     -- Fahrer spawnen |     -- Verschiedene Fahrer-Models versuchen | ||||||
|     local driverHash = GetHashKey("a_m_m_taxi_01") |     local driverModels = { | ||||||
|     RequestModel(driverHash) |         "a_m_m_taxi_01", | ||||||
|     local timeout = GetGameTimer() + 10000 |         "s_m_y_taxi_01",  | ||||||
|     while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do |         "a_m_y_business_01", | ||||||
|         print("^3[TAXI STATIONS DEBUG]^7 Waiting for driver model to load...") |         "a_m_m_business_01", | ||||||
|         Wait(100) |         "a_m_y_downtown_01" | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     local driver = nil | ||||||
|  |     local driverHash = nil | ||||||
|  |      | ||||||
|  |     for _, modelName in pairs(driverModels) do | ||||||
|  |         print("^2[TAXI STATIONS DEBUG]^7 Trying driver model: " .. modelName) | ||||||
|  |         driverHash = GetHashKey(modelName) | ||||||
|  |          | ||||||
|  |         RequestModel(driverHash) | ||||||
|  |         local timeout = GetGameTimer() + 5000 | ||||||
|  |         while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do | ||||||
|  |             print("^3[TAXI STATIONS DEBUG]^7 Waiting for driver model " .. modelName .. " to load...") | ||||||
|  |             Wait(100) | ||||||
|  |         end | ||||||
|  |          | ||||||
|  |         if HasModelLoaded(driverHash) then | ||||||
|  |             print("^2[TAXI STATIONS DEBUG]^7 Driver model " .. modelName .. " loaded successfully") | ||||||
|  |              | ||||||
|  |             driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) | ||||||
|  |              | ||||||
|  |             if DoesEntityExist(driver) then | ||||||
|  |                 print("^2[TAXI STATIONS DEBUG]^7 Driver created successfully: " .. driver) | ||||||
|  |                 break | ||||||
|  |             else | ||||||
|  |                 print("^1[TAXI STATIONS DEBUG]^7 Failed to create driver with model: " .. modelName) | ||||||
|  |                 SetModelAsNoLongerNeeded(driverHash) | ||||||
|  |             end | ||||||
|  |         else | ||||||
|  |             print("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model: " .. modelName) | ||||||
|  |         end | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     if not HasModelLoaded(driverHash) then |     -- Fallback: Fahrer ohne Model erstellen | ||||||
|         print("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model!") |     if not driver or not DoesEntityExist(driver) then | ||||||
|         return |         print("^3[TAXI STATIONS DEBUG]^7 Using fallback driver creation...") | ||||||
|     end |          | ||||||
|  |         -- Standard Male Model verwenden | ||||||
|     local driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) |         driverHash = GetHashKey("mp_m_freemode_01") | ||||||
|      |         RequestModel(driverHash) | ||||||
|     if not DoesEntityExist(driver) then |         local timeout = GetGameTimer() + 5000 | ||||||
|         print("^1[TAXI STATIONS DEBUG]^7 Failed to create driver!") |         while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do | ||||||
|         return |             Wait(100) | ||||||
|  |         end | ||||||
|  |          | ||||||
|  |         if HasModelLoaded(driverHash) then | ||||||
|  |             driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) | ||||||
|  |             print("^2[TAXI STATIONS DEBUG]^7 Fallback driver created: " .. (driver or "nil")) | ||||||
|  |         end | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     print("^2[TAXI STATIONS DEBUG]^7 Driver created: " .. driver) |     -- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren | ||||||
|      |     if not driver or not DoesEntityExist(driver) then | ||||||
|     SetEntityAsMissionEntity(driver, true, true) |         print("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver") | ||||||
|     SetPedFleeAttributes(driver, 0, 0) |         driver = nil | ||||||
|     SetPedCombatAttributes(driver, 17, 1) |     else | ||||||
|     SetPedSeeingRange(driver, 0.0) |         -- Fahrer konfigurieren | ||||||
|     SetPedHearingRange(driver, 0.0) |         SetEntityAsMissionEntity(driver, true, true) | ||||||
|     SetPedAlertness(driver, 0) |         SetPedFleeAttributes(driver, 0, 0) | ||||||
|     SetPedKeepTask(driver, true) |         SetPedCombatAttributes(driver, 17, 1) | ||||||
|  |         SetPedSeeingRange(driver, 0.0) | ||||||
|  |         SetPedHearingRange(driver, 0.0) | ||||||
|  |         SetPedAlertness(driver, 0) | ||||||
|  |         SetPedKeepTask(driver, true) | ||||||
|  |          | ||||||
|  |         -- Fahrer-Outfit für Taxi | ||||||
|  |         SetPedComponentVariation(driver, 8, 0, 0, 0) -- Shirt | ||||||
|  |         SetPedComponentVariation(driver, 11, 0, 0, 0) -- Jacket | ||||||
|  |         SetPedComponentVariation(driver, 4, 0, 0, 0) -- Pants | ||||||
|  |         SetPedComponentVariation(driver, 6, 0, 0, 0) -- Shoes | ||||||
|  |     end | ||||||
|      |      | ||||||
|     -- Spieler einsteigen lassen |     -- Spieler einsteigen lassen | ||||||
|     TaskEnterVehicle(playerPed, vehicle, 10000, 0, 1.0, 1, 0) |     TaskEnterVehicle(playerPed, vehicle, 10000, 0, 1.0, 1, 0) | ||||||
|  | @ -210,7 +258,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data) | ||||||
|         if not IsPedInVehicle(playerPed, vehicle, false) then |         if not IsPedInVehicle(playerPed, vehicle, false) then | ||||||
|             print("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle") |             print("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle") | ||||||
|             -- Cleanup |             -- Cleanup | ||||||
|             if DoesEntityExist(driver) then |             if driver and DoesEntityExist(driver) then | ||||||
|                 DeleteEntity(driver) |                 DeleteEntity(driver) | ||||||
|             end |             end | ||||||
|             SetVehicleDoorsLocked(vehicle, 2) |             SetVehicleDoorsLocked(vehicle, 2) | ||||||
|  | @ -269,6 +317,18 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) | ||||||
|         end |         end | ||||||
|     }) |     }) | ||||||
|      |      | ||||||
|  |     -- Selbst fahren Option (wenn kein Fahrer) | ||||||
|  |     if not driver or not DoesEntityExist(driver) then | ||||||
|  |         table.insert(options, { | ||||||
|  |             title = '🚗 Selbst fahren', | ||||||
|  |             description = 'Du fährst das Taxi selbst (kostenlos)', | ||||||
|  |             icon = 'car', | ||||||
|  |             onSelect = function() | ||||||
|  |                 SelfDriveStationTaxi(stationId, vehicleId, vehicle) | ||||||
|  |             end | ||||||
|  |         }) | ||||||
|  |     end | ||||||
|  |      | ||||||
|     -- Aussteigen Option |     -- Aussteigen Option | ||||||
|     table.insert(options, { |     table.insert(options, { | ||||||
|         title = 'Aussteigen', |         title = 'Aussteigen', | ||||||
|  | @ -288,6 +348,41 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) | ||||||
|     lib.showContext('station_taxi_menu') |     lib.showContext('station_taxi_menu') | ||||||
| end | end | ||||||
|  |  | ||||||
|  | function SelfDriveStationTaxi(stationId, vehicleId, vehicle) | ||||||
|  |     print("^2[TAXI STATIONS DEBUG]^7 Player driving taxi themselves") | ||||||
|  |      | ||||||
|  |     local playerPed = PlayerPedId() | ||||||
|  |      | ||||||
|  |     -- Spieler zum Fahrersitz bewegen | ||||||
|  |     TaskShuffleToNextVehicleSeat(playerPed, vehicle) | ||||||
|  |      | ||||||
|  |     lib.notify({ | ||||||
|  |         title = 'Taxi Service', | ||||||
|  |         description = 'Du fährst das Taxi jetzt selbst. Bringe es zur Station zurück wenn du fertig bist.', | ||||||
|  |         type = 'info' | ||||||
|  |     }) | ||||||
|  |      | ||||||
|  |     -- Überwachung für Rückgabe | ||||||
|  |     CreateThread(function() | ||||||
|  |         while DoesEntityExist(vehicle) do | ||||||
|  |             local playerPed = PlayerPedId() | ||||||
|  |              | ||||||
|  |             -- Prüfen ob Spieler noch im Fahrzeug ist | ||||||
|  |             if not IsPedInVehicle(playerPed, vehicle, false) then | ||||||
|  |                 print("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi") | ||||||
|  |                  | ||||||
|  |                 -- Nach 30 Sekunden Taxi zurück zur Station | ||||||
|  |                 SetTimeout(30000, function() | ||||||
|  |                     ReturnTaxiToStation(stationId, vehicleId, vehicle, nil) | ||||||
|  |                 end) | ||||||
|  |                 break | ||||||
|  |             end | ||||||
|  |              | ||||||
|  |             Wait(5000) | ||||||
|  |         end | ||||||
|  |     end) | ||||||
|  | end | ||||||
|  |  | ||||||
| function OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePerKm) | function OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePerKm) | ||||||
|     print("^2[TAXI STATIONS DEBUG]^7 Opening station selection menu") |     print("^2[TAXI STATIONS DEBUG]^7 Opening station selection menu") | ||||||
|      |      | ||||||
|  | @ -331,6 +426,29 @@ end | ||||||
| function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination, price) | function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination, price) | ||||||
|     print("^2[TAXI STATIONS DEBUG]^7 Starting station taxi ride to: " .. tostring(destination)) |     print("^2[TAXI STATIONS DEBUG]^7 Starting station taxi ride to: " .. tostring(destination)) | ||||||
|      |      | ||||||
|  |     -- Wenn kein Fahrer, Spieler selbst fahren lassen | ||||||
|  |     if not driver or not DoesEntityExist(driver) then | ||||||
|  |         lib.notify({ | ||||||
|  |             title = 'Taxi Service', | ||||||
|  |             description = 'Kein Fahrer verfügbar. Fahre selbst zum Ziel! (Kostenlos)', | ||||||
|  |             type = 'info' | ||||||
|  |         }) | ||||||
|  |          | ||||||
|  |         -- Destination Blip erstellen | ||||||
|  |         local destinationBlip = AddBlipForCoord(destination.x, destination.y, destination.z) | ||||||
|  |         SetBlipSprite(destinationBlip, 1) | ||||||
|  |         SetBlipColour(destinationBlip, 2) | ||||||
|  |         SetBlipScale(destinationBlip, 0.8) | ||||||
|  |         BeginTextCommandSetBlipName("STRING") | ||||||
|  |         AddTextComponentString("Taxi Ziel") | ||||||
|  |         EndTextCommandSetBlipName(destinationBlip) | ||||||
|  |          | ||||||
|  |         -- Route setzen | ||||||
|  |         SetNewWaypoint(destination.x, destination.y) | ||||||
|  |          | ||||||
|  |         return | ||||||
|  |     end | ||||||
|  |      | ||||||
|     lib.notify({ |     lib.notify({ | ||||||
|         title = 'Taxi Service', |         title = 'Taxi Service', | ||||||
|         description = 'Fahrt gestartet - Preis: $' .. price, |         description = 'Fahrt gestartet - Preis: $' .. price, | ||||||
|  | @ -412,7 +530,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     -- Fahrer löschen |     -- Fahrer löschen | ||||||
|     if DoesEntityExist(driver) then |     if driver and DoesEntityExist(driver) then | ||||||
|         DeleteEntity(driver) |         DeleteEntity(driver) | ||||||
|         print("^2[TAXI STATIONS DEBUG]^7 Driver deleted") |         print("^2[TAXI STATIONS DEBUG]^7 Driver deleted") | ||||||
|     end |     end | ||||||
|  | @ -520,37 +638,6 @@ RegisterNetEvent('taxi:respawnAllStations', function() | ||||||
|     }) |     }) | ||||||
| end) | end) | ||||||
|  |  | ||||||
| -- Verbesserte Fahrzeug-Respawn-Logik |  | ||||||
| function RespawnStationVehicle(stationId, vehicleId) |  | ||||||
|     if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then |  | ||||||
|         return |  | ||||||
|     end |  | ||||||
|      |  | ||||||
|     local vehicleData = stationVehicles[stationId][vehicleId].data |  | ||||||
|      |  | ||||||
|     -- Prüfen ob Position frei ist |  | ||||||
|     local coords = vehicleData.coords |  | ||||||
|     local existingVehicles = GetGamePool('CVehicle') |  | ||||||
|     local positionBlocked = false |  | ||||||
|      |  | ||||||
|     for _, veh in pairs(existingVehicles) do |  | ||||||
|         local vehCoords = GetEntityCoords(veh) |  | ||||||
|         if #(vector3(coords.x, coords.y, coords.z) - vehCoords) < 3.0 then |  | ||||||
|             positionBlocked = true |  | ||||||
|             break |  | ||||||
|         end |  | ||||||
|     end |  | ||||||
|      |  | ||||||
|     if not positionBlocked then |  | ||||||
|         SpawnStationVehicle(stationId, vehicleId, vehicleData) |  | ||||||
|     else |  | ||||||
|         -- Erneut versuchen nach 30 Sekunden |  | ||||||
|         SetTimeout(30000, function() |  | ||||||
|             RespawnStationVehicle(stationId, vehicleId) |  | ||||||
|         end) |  | ||||||
|     end |  | ||||||
| end |  | ||||||
|  |  | ||||||
| -- Cleanup beim Resource Stop | -- Cleanup beim Resource Stop | ||||||
| AddEventHandler('onResourceStop', function(resourceName) | AddEventHandler('onResourceStop', function(resourceName) | ||||||
|     if GetCurrentResourceName() == resourceName then |     if GetCurrentResourceName() == resourceName then | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nordi98
						Nordi98