forked from Simnation/Main
ed
This commit is contained in:
parent
ab1a686ee2
commit
4551f8c51a
2 changed files with 200 additions and 56 deletions
|
@ -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")
|
||||
end
|
||||
print("^2[TAXI DEBUG]^7 Making taxi drive away before despawn")
|
||||
|
||||
-- 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
|
||||
-- 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
|
||||
|
||||
-- Blips entfernen
|
||||
if taxiBlip then
|
||||
RemoveBlip(taxiBlip)
|
||||
taxiBlip = nil
|
||||
end
|
||||
-- Taxi wegfahren lassen
|
||||
TaskVehicleDriveToCoord(currentDriver, currentTaxi, driveToX, driveToY, taxiCoords.z, 25.0, 0, GetEntityModel(currentTaxi), 786603, 1.0, true)
|
||||
|
||||
if destinationBlip then
|
||||
RemoveBlip(destinationBlip)
|
||||
destinationBlip = nil
|
||||
end
|
||||
-- Blips entfernen
|
||||
if taxiBlip then
|
||||
RemoveBlip(taxiBlip)
|
||||
taxiBlip = nil
|
||||
end
|
||||
|
||||
print("^2[TAXI DEBUG]^7 Taxi despawn completed")
|
||||
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
|
||||
}
|
||||
|
||||
function CalculateDistanceToCoords(coords)
|
||||
local playerCoords = GetEntityCoords(PlayerPedId())
|
||||
|
|
|
@ -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
|
||||
print("^2[TAXI STATIONS DEBUG]^7 Making taxi drive back to station")
|
||||
|
||||
-- qb-target entfernen
|
||||
if DoesEntityExist(vehicle) then
|
||||
-- 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 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
|
||||
|
||||
-- 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)
|
||||
-- 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'
|
||||
})
|
||||
|
||||
|
@ -877,3 +935,5 @@ AddEventHandler('onResourceStop', function(resourceName)
|
|||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue