forked from Simnation/Main
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
|
||||
SetVehicleDoorsLocked(vehicle, 1)
|
||||
|
||||
-- Fahrer spawnen
|
||||
local driverHash = GetHashKey("a_m_m_taxi_01")
|
||||
RequestModel(driverHash)
|
||||
local timeout = GetGameTimer() + 10000
|
||||
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
|
||||
print("^3[TAXI STATIONS DEBUG]^7 Waiting for driver model to load...")
|
||||
Wait(100)
|
||||
-- Verschiedene Fahrer-Models versuchen
|
||||
local driverModels = {
|
||||
"a_m_m_taxi_01",
|
||||
"s_m_y_taxi_01",
|
||||
"a_m_y_business_01",
|
||||
"a_m_m_business_01",
|
||||
"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
|
||||
|
||||
if not HasModelLoaded(driverHash) then
|
||||
print("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model!")
|
||||
return
|
||||
end
|
||||
|
||||
local driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false)
|
||||
|
||||
if not DoesEntityExist(driver) then
|
||||
print("^1[TAXI STATIONS DEBUG]^7 Failed to create driver!")
|
||||
return
|
||||
-- Fallback: Fahrer ohne Model erstellen
|
||||
if not driver or not DoesEntityExist(driver) then
|
||||
print("^3[TAXI STATIONS DEBUG]^7 Using fallback driver creation...")
|
||||
|
||||
-- Standard Male Model verwenden
|
||||
driverHash = GetHashKey("mp_m_freemode_01")
|
||||
RequestModel(driverHash)
|
||||
local timeout = GetGameTimer() + 5000
|
||||
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
|
||||
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
|
||||
|
||||
print("^2[TAXI STATIONS DEBUG]^7 Driver created: " .. driver)
|
||||
|
||||
SetEntityAsMissionEntity(driver, true, true)
|
||||
SetPedFleeAttributes(driver, 0, 0)
|
||||
SetPedCombatAttributes(driver, 17, 1)
|
||||
SetPedSeeingRange(driver, 0.0)
|
||||
SetPedHearingRange(driver, 0.0)
|
||||
SetPedAlertness(driver, 0)
|
||||
SetPedKeepTask(driver, true)
|
||||
-- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren
|
||||
if not driver or not DoesEntityExist(driver) then
|
||||
print("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver")
|
||||
driver = nil
|
||||
else
|
||||
-- Fahrer konfigurieren
|
||||
SetEntityAsMissionEntity(driver, true, true)
|
||||
SetPedFleeAttributes(driver, 0, 0)
|
||||
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
|
||||
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
|
||||
print("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle")
|
||||
-- Cleanup
|
||||
if DoesEntityExist(driver) then
|
||||
if driver and DoesEntityExist(driver) then
|
||||
DeleteEntity(driver)
|
||||
end
|
||||
SetVehicleDoorsLocked(vehicle, 2)
|
||||
|
@ -269,6 +317,18 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm)
|
|||
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
|
||||
table.insert(options, {
|
||||
title = 'Aussteigen',
|
||||
|
@ -288,6 +348,41 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm)
|
|||
lib.showContext('station_taxi_menu')
|
||||
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)
|
||||
print("^2[TAXI STATIONS DEBUG]^7 Opening station selection menu")
|
||||
|
||||
|
@ -331,6 +426,29 @@ end
|
|||
function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination, price)
|
||||
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({
|
||||
title = 'Taxi Service',
|
||||
description = 'Fahrt gestartet - Preis: $' .. price,
|
||||
|
@ -412,7 +530,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
|
|||
end
|
||||
|
||||
-- Fahrer löschen
|
||||
if DoesEntityExist(driver) then
|
||||
if driver and DoesEntityExist(driver) then
|
||||
DeleteEntity(driver)
|
||||
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
|
||||
end
|
||||
|
@ -520,37 +638,6 @@ RegisterNetEvent('taxi:respawnAllStations', function()
|
|||
})
|
||||
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
|
||||
AddEventHandler('onResourceStop', function(resourceName)
|
||||
if GetCurrentResourceName() == resourceName then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue