1
0
Fork 0
forked from Simnation/Main
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

@ -177,21 +177,62 @@ function GetTaxiSpawnPosition(playerCoords)
return nil return nil
end 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) function SpawnTaxiDriver(vehicle)
print("^2[TAXI DEBUG]^7 Spawning taxi driver...") print("^2[TAXI DEBUG]^7 Spawning taxi driver...")
-- Bessere Fahrer-Models mit Fallbacks -- Bessere Fahrer-Models mit Fallbacks
local driverModels = { local driverModels = {
"A_C_Chimp", -- Standard Male (sollte immer verfügbar sein) "mp_m_freemode_01", -- Standard Male (sollte immer verfügbar sein)
"G_M_M_ArmGoon_01", -- Standard Female "mp_f_freemode_01", -- Standard Female
"a_m_y_business_01", -- Business Male "a_m_y_business_01", -- Business Male
"a_f_y_business_01", -- Business Female "a_f_y_business_01", -- Business Female
"a_m_m_business_01", -- Business Male 2 "a_m_m_business_01", -- Business Male 2
"a_m_y_downtown_01", -- Downtown Male "a_m_y_downtown_01", -- Downtown Male
"A_M_O_GenStreet_01", -- Pilot "s_m_m_pilot_01", -- Pilot
"CS_Manuel", -- Dealer "s_m_y_dealer_01" -- Dealer
"U_M_M_Jesus_01", -- Jesus
} }
local driver = nil local driver = nil
@ -610,34 +651,77 @@ end
function DespawnTaxi() function DespawnTaxi()
print("^2[TAXI DEBUG]^7 Despawning taxi") 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 if currentDriver and DoesEntityExist(currentDriver) then
DeleteEntity(currentDriver) print("^2[TAXI DEBUG]^7 Making taxi drive away before despawn")
currentDriver = nil
print("^2[TAXI DEBUG]^7 Driver deleted")
end
-- Taxi löschen -- Zufällige Position in der Nähe finden
if currentTaxi and DoesEntityExist(currentTaxi) then local taxiCoords = GetEntityCoords(currentTaxi)
exports['qb-target']:RemoveTargetEntity(currentTaxi) local angle = math.random() * 2 * math.pi
DeleteEntity(currentTaxi) local distance = 150.0
currentTaxi = nil local driveToX = taxiCoords.x + math.cos(angle) * distance
print("^2[TAXI DEBUG]^7 Taxi deleted") local driveToY = taxiCoords.y + math.sin(angle) * distance
end
-- Blips entfernen -- Taxi wegfahren lassen
if taxiBlip then TaskVehicleDriveToCoord(currentDriver, currentTaxi, driveToX, driveToY, taxiCoords.z, 25.0, 0, GetEntityModel(currentTaxi), 786603, 1.0, true)
RemoveBlip(taxiBlip)
taxiBlip = nil
end
if destinationBlip then -- Blips entfernen
RemoveBlip(destinationBlip) if taxiBlip then
destinationBlip = nil RemoveBlip(taxiBlip)
end taxiBlip = nil
end
print("^2[TAXI DEBUG]^7 Taxi despawn completed") if destinationBlip then
end 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) function CalculateDistanceToCoords(coords)
local playerCoords = GetEntityCoords(PlayerPedId()) local playerCoords = GetEntityCoords(PlayerPedId())

View file

@ -744,33 +744,91 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
return return
end 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 if driver and DoesEntityExist(driver) then
DeleteEntity(driver) print("^2[TAXI STATIONS DEBUG]^7 Making taxi drive back to station")
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end
-- qb-target entfernen -- Zufällige Position in der Nähe der Station finden
if DoesEntityExist(vehicle) then 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) exports['qb-target']:RemoveTargetEntity(vehicle)
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
-- Fahrzeug als nicht besetzt markieren -- Nach 10 Sekunden tatsächlich löschen
stationVehicles[stationId][vehicleId].occupied = false SetTimeout(10000, function()
stationVehicles[stationId][vehicleId].driver = nil -- Fahrer löschen
stationVehicles[stationId][vehicleId].entity = nil if driver and DoesEntityExist(driver) then
DeleteEntity(driver)
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end
-- Nach Respawn-Zeit neues Fahrzeug spawnen -- Fahrzeug löschen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds") if DoesEntityExist(vehicle) then
SetTimeout(Config.StationTaxiRespawnTime * 1000, function() DeleteEntity(vehicle)
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
local vehicleData = stationVehicles[stationId][vehicleId].data end
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData) -- 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
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 end
function CalculateDistanceToCoords(coords) function CalculateDistanceToCoords(coords)
@ -795,7 +853,7 @@ RegisterCommand('nearesttaxi', function()
if nearestStation then if nearestStation then
lib.notify({ lib.notify({
title = 'Taxi Service', 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' type = 'info'
}) })
@ -877,3 +935,5 @@ AddEventHandler('onResourceStop', function(resourceName)
end end
end) end)