1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-07-31 07:35:56 +02:00
parent 16b0058156
commit 3279494318
3 changed files with 193 additions and 168 deletions

View file

@ -11,14 +11,14 @@ local taxiMeter = {
pricePerKm = 0 pricePerKm = 0
} }
print("^2[TAXI DEBUG]^7 Main script loaded") DebugPrint("^2[TAXI DEBUG]^7 Main script loaded")
-- Taxi rufen Command -- Taxi rufen Command
RegisterCommand('taxi', function() RegisterCommand('taxi', function()
print("^2[TAXI DEBUG]^7 Taxi command executed") DebugPrint("^2[TAXI DEBUG]^7 Taxi command executed")
if currentTaxi and DoesEntityExist(currentTaxi) then if currentTaxi and DoesEntityExist(currentTaxi) then
print("^1[TAXI DEBUG]^7 Taxi already exists") DebugPrint("^1[TAXI DEBUG]^7 Taxi already exists")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Du hast bereits ein Taxi gerufen', description = 'Du hast bereits ein Taxi gerufen',
@ -31,7 +31,7 @@ RegisterCommand('taxi', function()
end) end)
function CallTaxi() function CallTaxi()
print("^2[TAXI DEBUG]^7 CallTaxi function started") DebugPrint("^2[TAXI DEBUG]^7 CallTaxi function started")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
@ -43,12 +43,12 @@ function CallTaxi()
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed) local playerCoords = GetEntityCoords(playerPed)
print("^2[TAXI DEBUG]^7 Player coords: " .. tostring(playerCoords)) DebugPrint("^2[TAXI DEBUG]^7 Player coords: " .. tostring(playerCoords))
-- Verbesserte Spawn-Position für Taxi finden -- Verbesserte Spawn-Position für Taxi finden
local spawnCoords = GetImprovedTaxiSpawnPosition(playerCoords) local spawnCoords = GetImprovedTaxiSpawnPosition(playerCoords)
if not spawnCoords then if not spawnCoords then
print("^1[TAXI DEBUG]^7 No spawn position found") DebugPrint("^1[TAXI DEBUG]^7 No spawn position found")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Kein geeigneter Spawn-Punkt gefunden', description = 'Kein geeigneter Spawn-Punkt gefunden',
@ -57,12 +57,12 @@ function CallTaxi()
return return
end end
print("^2[TAXI DEBUG]^7 Spawn coords found: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z)) DebugPrint("^2[TAXI DEBUG]^7 Spawn coords found: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z))
-- Taxi spawnen -- Taxi spawnen
local taxi = SpawnTaxi(spawnCoords) local taxi = SpawnTaxi(spawnCoords)
if not taxi then if not taxi then
print("^1[TAXI DEBUG]^7 Failed to spawn taxi") DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn taxi")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Taxi konnte nicht gespawnt werden', description = 'Taxi konnte nicht gespawnt werden',
@ -71,14 +71,14 @@ function CallTaxi()
return return
end end
print("^2[TAXI DEBUG]^7 Taxi spawned: " .. taxi) DebugPrint("^2[TAXI DEBUG]^7 Taxi spawned: " .. taxi)
currentTaxi = taxi currentTaxi = taxi
-- Fahrer spawnen -- Fahrer spawnen
local driver = SpawnTaxiDriver(taxi) local driver = SpawnTaxiDriver(taxi)
if driver then if driver then
currentDriver = driver currentDriver = driver
print("^2[TAXI DEBUG]^7 Driver spawned: " .. driver) DebugPrint("^2[TAXI DEBUG]^7 Driver spawned: " .. driver)
-- Verbesserte Navigation zum Spieler -- Verbesserte Navigation zum Spieler
NavigateToPlayer(driver, taxi, playerCoords) NavigateToPlayer(driver, taxi, playerCoords)
@ -95,7 +95,7 @@ function CallTaxi()
type = 'success' type = 'success'
}) })
else else
print("^1[TAXI DEBUG]^7 Failed to spawn driver") DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn driver")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Taxi ohne Fahrer gespawnt - Du kannst es selbst fahren', description = 'Taxi ohne Fahrer gespawnt - Du kannst es selbst fahren',
@ -106,7 +106,7 @@ function CallTaxi()
end end
function GetImprovedTaxiSpawnPosition(playerCoords) function GetImprovedTaxiSpawnPosition(playerCoords)
print("^2[TAXI DEBUG]^7 Finding improved spawn position...") DebugPrint("^2[TAXI DEBUG]^7 Finding improved spawn position...")
-- Minimale und maximale Entfernung zum Spieler -- Minimale und maximale Entfernung zum Spieler
local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt
@ -127,7 +127,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local nodeDistance = #(playerCoords - nodePos) local nodeDistance = #(playerCoords - nodePos)
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
roadPosition = nodePos roadPosition = nodePos
print("^2[TAXI DEBUG]^7 Found road node for spawn at distance: " .. nodeDistance) DebugPrint("^2[TAXI DEBUG]^7 Found road node for spawn at distance: " .. nodeDistance)
return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0} return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0}
else else
-- Speichern für später, falls wir nichts Besseres finden -- Speichern für später, falls wir nichts Besseres finden
@ -150,7 +150,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
if foundNode then if foundNode then
local nodeDistance = #(playerCoords - nodePos) local nodeDistance = #(playerCoords - nodePos)
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
print("^2[TAXI DEBUG]^7 Found directional node for spawn at distance: " .. nodeDistance .. " in direction " .. angle) DebugPrint("^2[TAXI DEBUG]^7 Found directional node for spawn at distance: " .. nodeDistance .. " in direction " .. angle)
return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} return {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0}
else else
-- Speichern für später, falls wir nichts Besseres finden -- Speichern für später, falls wir nichts Besseres finden
@ -169,7 +169,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local nodeDistance = #(playerCoords - nodePos) local nodeDistance = #(playerCoords - nodePos)
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
roadPosition = nodePos roadPosition = nodePos
print("^2[TAXI DEBUG]^7 Found major road node for spawn at distance: " .. nodeDistance) DebugPrint("^2[TAXI DEBUG]^7 Found major road node for spawn at distance: " .. nodeDistance)
return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0} return {x = roadPosition.x, y = roadPosition.y, z = roadPosition.z, w = 0.0}
else else
-- Speichern für später, falls wir nichts Besseres finden -- Speichern für später, falls wir nichts Besseres finden
@ -228,7 +228,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
-- Wenn Position frei ist, verwenden -- Wenn Position frei ist, verwenden
if clearArea then if clearArea then
print("^2[TAXI DEBUG]^7 Using spawn position from config: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z) .. " (Distance: " .. spawn.distance .. "m)") DebugPrint("^2[TAXI DEBUG]^7 Using spawn position from config: " .. tostring(spawnCoords.x) .. ", " .. tostring(spawnCoords.y) .. ", " .. tostring(spawnCoords.z) .. " (Distance: " .. spawn.distance .. "m)")
return spawnCoords return spawnCoords
end end
@ -239,12 +239,12 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
-- Wenn wir hier sind, haben wir keine ideale Position gefunden -- Wenn wir hier sind, haben wir keine ideale Position gefunden
-- Wenn wir eine "beste" Position haben, die den Mindestabstand einhält, verwenden wir diese -- Wenn wir eine "beste" Position haben, die den Mindestabstand einhält, verwenden wir diese
if bestPosition and bestDistance >= minAcceptableDistance then if bestPosition and bestDistance >= minAcceptableDistance then
print("^3[TAXI DEBUG]^7 Using best available position at " .. bestDistance .. "m") DebugPrint("^3[TAXI DEBUG]^7 Using best available position at " .. bestDistance .. "m")
return bestPosition return bestPosition
end end
-- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers -- Wenn alles fehlschlägt: Generiere eine zufällige Position in der Nähe des Spielers
print("^3[TAXI DEBUG]^7 Generating random position between " .. minAcceptableDistance .. "m and " .. maxAcceptableDistance .. "m of player") DebugPrint("^3[TAXI DEBUG]^7 Generating random position between " .. minAcceptableDistance .. "m and " .. maxAcceptableDistance .. "m of player")
-- Versuche bis zu 15 Mal, eine gültige Position zu finden -- Versuche bis zu 15 Mal, eine gültige Position zu finden
for attempt = 1, 15 do for attempt = 1, 15 do
@ -262,7 +262,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local isOnRoad = IsPointOnRoad(x, y, groundZ) local isOnRoad = IsPointOnRoad(x, y, groundZ)
if isOnRoad then if isOnRoad then
print("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance) DebugPrint("^2[TAXI DEBUG]^7 Found random position on road at distance: " .. distance)
return {x = x, y = y, z = groundZ, w = 0.0} return {x = x, y = y, z = groundZ, w = 0.0}
end end
end end
@ -281,13 +281,13 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
z = groundZ z = groundZ
end end
print("^3[TAXI DEBUG]^7 Using emergency random spawn position at distance: " .. distance) DebugPrint("^3[TAXI DEBUG]^7 Using emergency random spawn position at distance: " .. distance)
return {x = x, y = y, z = z, w = 0.0} return {x = x, y = y, z = z, w = 0.0}
end end
function SpawnTaxi(coords) function SpawnTaxi(coords)
print("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords.x) .. ", " .. tostring(coords.y) .. ", " .. tostring(coords.z)) DebugPrint("^2[TAXI DEBUG]^7 Spawning taxi at: " .. tostring(coords.x) .. ", " .. tostring(coords.y) .. ", " .. tostring(coords.z))
-- Sicherstellen dass wir ein gültiges Taxi-Model haben -- Sicherstellen dass wir ein gültiges Taxi-Model haben
local taxiModel = nil local taxiModel = nil
@ -299,7 +299,7 @@ function SpawnTaxi(coords)
taxiModel = GetHashKey("taxi") -- Fallback taxiModel = GetHashKey("taxi") -- Fallback
end end
print("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel) DebugPrint("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel)
-- Model laden mit Timeout -- Model laden mit Timeout
RequestModel(taxiModel) RequestModel(taxiModel)
@ -309,13 +309,13 @@ function SpawnTaxi(coords)
while not modelLoaded and GetGameTimer() < timeout do while not modelLoaded and GetGameTimer() < timeout do
modelLoaded = HasModelLoaded(taxiModel) modelLoaded = HasModelLoaded(taxiModel)
if not modelLoaded then if not modelLoaded then
print("^3[TAXI DEBUG]^7 Waiting for taxi model to load...") DebugPrint("^3[TAXI DEBUG]^7 Waiting for taxi model to load...")
Wait(100) Wait(100)
end end
end end
if not modelLoaded then if not modelLoaded then
print("^1[TAXI DEBUG]^7 Failed to load taxi model! Trying default model.") DebugPrint("^1[TAXI DEBUG]^7 Failed to load taxi model! Trying default model.")
SetModelAsNoLongerNeeded(taxiModel) SetModelAsNoLongerNeeded(taxiModel)
-- Versuche Standard-Taxi als Fallback -- Versuche Standard-Taxi als Fallback
@ -328,7 +328,7 @@ function SpawnTaxi(coords)
end end
if not HasModelLoaded(taxiModel) then if not HasModelLoaded(taxiModel) then
print("^1[TAXI DEBUG]^7 Failed to load default taxi model!") DebugPrint("^1[TAXI DEBUG]^7 Failed to load default taxi model!")
return nil return nil
end end
end end
@ -337,11 +337,11 @@ function SpawnTaxi(coords)
local taxi = CreateVehicle(taxiModel, coords.x, coords.y, coords.z, coords.w or 0.0, true, false) local taxi = CreateVehicle(taxiModel, coords.x, coords.y, coords.z, coords.w or 0.0, true, false)
if not DoesEntityExist(taxi) then if not DoesEntityExist(taxi) then
print("^1[TAXI DEBUG]^7 Failed to create taxi vehicle!") DebugPrint("^1[TAXI DEBUG]^7 Failed to create taxi vehicle!")
return nil return nil
end end
print("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi) DebugPrint("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi)
-- Fahrzeug konfigurieren -- Fahrzeug konfigurieren
SetEntityAsMissionEntity(taxi, true, true) SetEntityAsMissionEntity(taxi, true, true)
@ -361,7 +361,7 @@ function SpawnTaxi(coords)
local liveryCount = GetVehicleLiveryCount(taxi) local liveryCount = GetVehicleLiveryCount(taxi)
if liveryCount > 0 then if liveryCount > 0 then
SetVehicleLivery(taxi, 0) -- Erste Livery verwenden SetVehicleLivery(taxi, 0) -- Erste Livery verwenden
print("^2[TAXI DEBUG]^7 Taxi livery set") DebugPrint("^2[TAXI DEBUG]^7 Taxi livery set")
end end
-- Fahrzeug-Extras aktivieren falls vorhanden -- Fahrzeug-Extras aktivieren falls vorhanden
@ -382,7 +382,7 @@ end
function InitializeTaxiDriverAI(driver, vehicle) function InitializeTaxiDriverAI(driver, vehicle)
if not driver or not DoesEntityExist(driver) then return end if not driver or not DoesEntityExist(driver) then return end
print("^2[TAXI DEBUG]^7 Initializing advanced taxi driver AI") DebugPrint("^2[TAXI DEBUG]^7 Initializing advanced taxi driver AI")
-- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen -- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen
local driverData = { local driverData = {
@ -465,14 +465,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Gerade an Ampel angekommen -- Gerade an Ampel angekommen
driverData.state.isWaitingAtTrafficLight = true driverData.state.isWaitingAtTrafficLight = true
driverData.state.trafficLightWaitStart = currentTime driverData.state.trafficLightWaitStart = currentTime
print("^3[TAXI DEBUG]^7 Taxi waiting at traffic light") DebugPrint("^3[TAXI DEBUG]^7 Taxi waiting at traffic light")
elseif isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then elseif isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Immer noch an Ampel -- Immer noch an Ampel
local waitTime = currentTime - driverData.state.trafficLightWaitStart local waitTime = currentTime - driverData.state.trafficLightWaitStart
-- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen) -- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen)
if waitTime > driverData.settings.trafficLightMaxWait then if waitTime > driverData.settings.trafficLightMaxWait then
print("^3[TAXI DEBUG]^7 Taxi waited too long at traffic light, trying to continue") DebugPrint("^3[TAXI DEBUG]^7 Taxi waited too long at traffic light, trying to continue")
-- Kurz vorwärts fahren um Ampel zu überwinden -- Kurz vorwärts fahren um Ampel zu überwinden
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000) Wait(2000)
@ -483,7 +483,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Ampel verlassen -- Ampel verlassen
driverData.state.isWaitingAtTrafficLight = false driverData.state.isWaitingAtTrafficLight = false
print("^2[TAXI DEBUG]^7 Taxi continued after traffic light") DebugPrint("^2[TAXI DEBUG]^7 Taxi continued after traffic light")
end end
-- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung) -- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung)
@ -492,14 +492,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Nur alle 5 Zähler-Erhöhungen loggen -- Nur alle 5 Zähler-Erhöhungen loggen
if driverData.state.stuckCounter % 5 == 0 then if driverData.state.stuckCounter % 5 == 0 then
print("^3[TAXI DEBUG]^7 Taxi might be stuck: " .. driverData.state.stuckCounter .. "/" .. driverData.settings.maxStuckCounter) DebugPrint("^3[TAXI DEBUG]^7 Taxi might be stuck: " .. driverData.state.stuckCounter .. "/" .. driverData.settings.maxStuckCounter)
end end
-- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch -- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch
if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and
(currentTime - driverData.state.lastStuckRecovery) > driverData.settings.minRecoveryInterval then (currentTime - driverData.state.lastStuckRecovery) > driverData.settings.minRecoveryInterval then
print("^1[TAXI DEBUG]^7 Taxi is stuck, attempting intelligent recovery") DebugPrint("^1[TAXI DEBUG]^7 Taxi is stuck, attempting intelligent recovery")
driverData.state.lastStuckRecovery = currentTime driverData.state.lastStuckRecovery = currentTime
driverData.state.currentBehavior = "recovery" driverData.state.currentBehavior = "recovery"
@ -522,7 +522,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and
(currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then (currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then
print("^3[TAXI DEBUG]^7 Taxi moving too slow, recalculating route") DebugPrint("^3[TAXI DEBUG]^7 Taxi moving too slow, recalculating route")
driverData.state.lastRouteRecalculation = currentTime driverData.state.lastRouteRecalculation = currentTime
-- Route neu berechnen -- Route neu berechnen
@ -570,17 +570,17 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
if backwardClear then if backwardClear then
-- Rückwärts fahren wenn hinten frei -- Rückwärts fahren wenn hinten frei
print("^3[TAXI DEBUG]^7 Recovery: Backing up") DebugPrint("^3[TAXI DEBUG]^7 Recovery: Backing up")
TaskVehicleTempAction(driver, vehicle, 8, 2000) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 2000) -- Reverse
Wait(2000) Wait(2000)
if forwardClear then if forwardClear then
-- Wenn vorne auch frei, einfach weiterfahren -- Wenn vorne auch frei, einfach weiterfahren
print("^3[TAXI DEBUG]^7 Recovery: Path clear, continuing") DebugPrint("^3[TAXI DEBUG]^7 Recovery: Path clear, continuing")
TaxiDriverContinueRoute(driver, vehicle) TaxiDriverContinueRoute(driver, vehicle)
else else
-- Sonst versuchen zu wenden -- Sonst versuchen zu wenden
print("^3[TAXI DEBUG]^7 Recovery: Turning around") DebugPrint("^3[TAXI DEBUG]^7 Recovery: Turning around")
TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left
Wait(1000) Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse
@ -591,13 +591,13 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
end end
elseif forwardClear then elseif forwardClear then
-- Wenn nur vorne frei, vorwärts fahren -- Wenn nur vorne frei, vorwärts fahren
print("^3[TAXI DEBUG]^7 Recovery: Moving forward") DebugPrint("^3[TAXI DEBUG]^7 Recovery: Moving forward")
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000) Wait(2000)
TaxiDriverContinueRoute(driver, vehicle) TaxiDriverContinueRoute(driver, vehicle)
else else
-- Wenn komplett eingeklemmt, versuche zu rütteln -- Wenn komplett eingeklemmt, versuche zu rütteln
print("^3[TAXI DEBUG]^7 Recovery: Trying to wiggle free") DebugPrint("^3[TAXI DEBUG]^7 Recovery: Trying to wiggle free")
TaskVehicleTempAction(driver, vehicle, 7, 1000) -- Turn left TaskVehicleTempAction(driver, vehicle, 7, 1000) -- Turn left
Wait(1000) Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse
@ -619,7 +619,7 @@ function TaxiDriverRecalculateRoute(driver, vehicle)
if destination then if destination then
-- Versuche einen alternativen Weg zu finden -- Versuche einen alternativen Weg zu finden
print("^3[TAXI DEBUG]^7 Recalculating route to destination") DebugPrint("^3[TAXI DEBUG]^7 Recalculating route to destination")
-- Kurz anhalten -- Kurz anhalten
TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop
@ -714,7 +714,7 @@ function norm(vector)
end end
function SpawnTaxiDriver(vehicle) function SpawnTaxiDriver(vehicle)
print("^2[TAXI DEBUG]^7 Spawning taxi driver...") DebugPrint("^2[TAXI DEBUG]^7 Spawning taxi driver...")
-- Bessere Fahrer-Models mit Fallbacks -- Bessere Fahrer-Models mit Fallbacks
local driverModels = { local driverModels = {
@ -733,7 +733,7 @@ function SpawnTaxiDriver(vehicle)
-- Versuche verschiedene Models -- Versuche verschiedene Models
for i, modelName in ipairs(driverModels) do for i, modelName in ipairs(driverModels) do
print("^2[TAXI DEBUG]^7 Trying driver model " .. i .. ": " .. modelName) DebugPrint("^2[TAXI DEBUG]^7 Trying driver model " .. i .. ": " .. modelName)
driverHash = GetHashKey(modelName) driverHash = GetHashKey(modelName)
-- Model laden -- Model laden
@ -744,38 +744,38 @@ function SpawnTaxiDriver(vehicle)
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
attempts = attempts + 1 attempts = attempts + 1
if attempts % 10 == 0 then -- Alle 1 Sekunde loggen if attempts % 10 == 0 then -- Alle 1 Sekunde loggen
print("^3[TAXI DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")") DebugPrint("^3[TAXI DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")")
end end
Wait(100) Wait(100)
end end
if HasModelLoaded(driverHash) then if HasModelLoaded(driverHash) then
print("^2[TAXI DEBUG]^7 Model " .. modelName .. " loaded successfully after " .. attempts .. " attempts") DebugPrint("^2[TAXI DEBUG]^7 Model " .. modelName .. " loaded successfully after " .. attempts .. " attempts")
-- Fahrer erstellen -- Fahrer erstellen
driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false)
if DoesEntityExist(driver) then if DoesEntityExist(driver) then
print("^2[TAXI DEBUG]^7 Driver created successfully with model: " .. modelName .. " (ID: " .. driver .. ")") DebugPrint("^2[TAXI DEBUG]^7 Driver created successfully with model: " .. modelName .. " (ID: " .. driver .. ")")
break break
else else
print("^1[TAXI DEBUG]^7 Failed to create driver with loaded model: " .. modelName) DebugPrint("^1[TAXI DEBUG]^7 Failed to create driver with loaded model: " .. modelName)
SetModelAsNoLongerNeeded(driverHash) SetModelAsNoLongerNeeded(driverHash)
end end
else else
print("^1[TAXI DEBUG]^7 Failed to load driver model: " .. modelName) DebugPrint("^1[TAXI DEBUG]^7 Failed to load driver model: " .. modelName)
SetModelAsNoLongerNeeded(driverHash) SetModelAsNoLongerNeeded(driverHash)
end end
end end
-- Wenn immer noch kein Fahrer erstellt wurde -- Wenn immer noch kein Fahrer erstellt wurde
if not driver or not DoesEntityExist(driver) then if not driver or not DoesEntityExist(driver) then
print("^1[TAXI DEBUG]^7 Could not create any driver! Continuing without driver...") DebugPrint("^1[TAXI DEBUG]^7 Could not create any driver! Continuing without driver...")
return nil return nil
end end
-- Fahrer konfigurieren -- Fahrer konfigurieren
print("^2[TAXI DEBUG]^7 Configuring driver...") DebugPrint("^2[TAXI DEBUG]^7 Configuring driver...")
SetEntityAsMissionEntity(driver, true, true) SetEntityAsMissionEntity(driver, true, true)
SetBlockingOfNonTemporaryEvents(driver, true) SetBlockingOfNonTemporaryEvents(driver, true)
@ -799,7 +799,7 @@ function SpawnTaxiDriver(vehicle)
-- Fahrer-Outfit (nur wenn es ein anpassbarer Ped ist) -- Fahrer-Outfit (nur wenn es ein anpassbarer Ped ist)
if driverHash == GetHashKey("mp_m_freemode_01") then if driverHash == GetHashKey("mp_m_freemode_01") then
print("^2[TAXI DEBUG]^7 Setting driver outfit...") DebugPrint("^2[TAXI DEBUG]^7 Setting driver outfit...")
-- Basis-Outfit für Taxi-Fahrer -- Basis-Outfit für Taxi-Fahrer
SetPedComponentVariation(driver, 0, 0, 0, 0) -- Face SetPedComponentVariation(driver, 0, 0, 0, 0) -- Face
@ -824,7 +824,7 @@ function SpawnTaxiDriver(vehicle)
SetModelAsNoLongerNeeded(driverHash) SetModelAsNoLongerNeeded(driverHash)
end end
print("^2[TAXI DEBUG]^7 Driver spawn completed successfully") DebugPrint("^2[TAXI DEBUG]^7 Driver spawn completed successfully")
return driver return driver
end end
@ -869,7 +869,7 @@ function CreateTaxiBlips(taxi)
end end
function NavigateToPlayer(driver, taxi, playerCoords) function NavigateToPlayer(driver, taxi, playerCoords)
print("^2[TAXI DEBUG]^7 Navigating taxi to player...") DebugPrint("^2[TAXI DEBUG]^7 Navigating taxi to player...")
-- Ziel im Fahrzeug-State speichern für die KI-Logik -- Ziel im Fahrzeug-State speichern für die KI-Logik
Entity(taxi).state.currentDestination = playerCoords Entity(taxi).state.currentDestination = playerCoords
@ -878,18 +878,18 @@ function NavigateToPlayer(driver, taxi, playerCoords)
local success, nodePos = GetClosestVehicleNodeWithHeading(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0) local success, nodePos = GetClosestVehicleNodeWithHeading(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0)
if success then if success then
print("^2[TAXI DEBUG]^7 Found good vehicle node near player") DebugPrint("^2[TAXI DEBUG]^7 Found good vehicle node near player")
-- Zum Wegpunkt fahren -- Zum Wegpunkt fahren
TaskVehicleDriveToCoordLongrange(driver, taxi, nodePos.x, nodePos.y, nodePos.z, 20.0, 786603, 10.0) TaskVehicleDriveToCoordLongrange(driver, taxi, nodePos.x, nodePos.y, nodePos.z, 20.0, 786603, 10.0)
else else
print("^3[TAXI DEBUG]^7 No good vehicle node found, driving directly to player") DebugPrint("^3[TAXI DEBUG]^7 No good vehicle node found, driving directly to player")
-- Direkt zum Spieler fahren -- Direkt zum Spieler fahren
TaskVehicleDriveToCoordLongrange(driver, taxi, playerCoords.x, playerCoords.y, playerCoords.z, 20.0, 786603, 10.0) TaskVehicleDriveToCoordLongrange(driver, taxi, playerCoords.x, playerCoords.y, playerCoords.z, 20.0, 786603, 10.0)
end end
end end
function MonitorTaxiArrival(taxi, driver, playerCoords) function MonitorTaxiArrival(taxi, driver, playerCoords)
print("^2[TAXI DEBUG]^7 Monitoring taxi arrival...") DebugPrint("^2[TAXI DEBUG]^7 Monitoring taxi arrival...")
local arrivalTimeout = GetGameTimer() + (120 * 1000) -- 2 minute timeout local arrivalTimeout = GetGameTimer() + (120 * 1000) -- 2 minute timeout
@ -901,7 +901,7 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
-- Check if taxi is close to player -- Check if taxi is close to player
if distance < 15.0 then if distance < 15.0 then
print("^2[TAXI DEBUG]^7 Taxi arrived!") DebugPrint("^2[TAXI DEBUG]^7 Taxi arrived!")
-- Taxi stoppen -- Taxi stoppen
if driver and DoesEntityExist(driver) then if driver and DoesEntityExist(driver) then
@ -934,7 +934,7 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
-- Check for timeout -- Check for timeout
if GetGameTimer() > arrivalTimeout then if GetGameTimer() > arrivalTimeout then
print("^1[TAXI DEBUG]^7 Taxi arrival timed out!") DebugPrint("^1[TAXI DEBUG]^7 Taxi arrival timed out!")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Dein Taxi steckt fest. Ein neues wird gerufen!', description = 'Dein Taxi steckt fest. Ein neues wird gerufen!',
@ -955,10 +955,10 @@ end
-- Event für Einsteigen ins Taxi -- Event für Einsteigen ins Taxi
RegisterNetEvent('taxi:enterTaxi', function() RegisterNetEvent('taxi:enterTaxi', function()
print("^2[TAXI DEBUG]^7 Player entering taxi") DebugPrint("^2[TAXI DEBUG]^7 Player entering taxi")
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
print("^1[TAXI DEBUG]^7 No taxi exists") DebugPrint("^1[TAXI DEBUG]^7 No taxi exists")
return return
end end
@ -983,7 +983,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
while GetGameTimer() < timeout and not entered do while GetGameTimer() < timeout and not entered do
if IsPedInVehicle(playerPed, currentTaxi, false) then if IsPedInVehicle(playerPed, currentTaxi, false) then
entered = true entered = true
print("^2[TAXI DEBUG]^7 Player entered taxi successfully") DebugPrint("^2[TAXI DEBUG]^7 Player entered taxi successfully")
-- qb-target entfernen -- qb-target entfernen
exports['qb-target']:RemoveTargetEntity(currentTaxi) exports['qb-target']:RemoveTargetEntity(currentTaxi)
@ -1002,7 +1002,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
end end
if not entered then if not entered then
print("^1[TAXI DEBUG]^7 Player failed to enter taxi") DebugPrint("^1[TAXI DEBUG]^7 Player failed to enter taxi")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Einsteigen fehlgeschlagen', description = 'Einsteigen fehlgeschlagen',
@ -1013,7 +1013,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
end) end)
function OpenDestinationMenu() function OpenDestinationMenu()
print("^2[TAXI DEBUG]^7 Opening destination menu") DebugPrint("^2[TAXI DEBUG]^7 Opening destination menu")
local options = {} local options = {}
@ -1087,10 +1087,10 @@ function OpenDestinationMenu()
end end
function StartTaxiRide(destination, price) function StartTaxiRide(destination, price)
print("^2[TAXI DEBUG]^7 Starting taxi ride to: " .. tostring(destination.x) .. ", " .. tostring(destination.y) .. ", " .. tostring(destination.z)) DebugPrint("^2[TAXI DEBUG]^7 Starting taxi ride to: " .. tostring(destination.x) .. ", " .. tostring(destination.y) .. ", " .. tostring(destination.z))
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
print("^1[TAXI DEBUG]^7 No taxi exists for ride") DebugPrint("^1[TAXI DEBUG]^7 No taxi exists for ride")
return return
end end
@ -1164,7 +1164,7 @@ function StartTaxiRide(destination, price)
end end
function MonitorTaxiRide(destination, price) function MonitorTaxiRide(destination, price)
print("^2[TAXI DEBUG]^7 Monitoring taxi ride...") DebugPrint("^2[TAXI DEBUG]^7 Monitoring taxi ride...")
local rideTimeout = GetGameTimer() + (10 * 60 * 1000) -- 10 Minuten Timeout local rideTimeout = GetGameTimer() + (10 * 60 * 1000) -- 10 Minuten Timeout
@ -1178,7 +1178,7 @@ function MonitorTaxiRide(destination, price)
-- Angekommen -- Angekommen
TaskVehicleTempAction(currentDriver, currentTaxi, 27, 3000) TaskVehicleTempAction(currentDriver, currentTaxi, 27, 3000)
print("^2[TAXI DEBUG]^7 Arrived at destination") DebugPrint("^2[TAXI DEBUG]^7 Arrived at destination")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Du bist angekommen! Preis: $' .. price, description = 'Du bist angekommen! Preis: $' .. price,
@ -1222,7 +1222,7 @@ function MonitorTaxiRide(destination, price)
-- Überprüfen ob die Fahrt zu lange dauert -- Überprüfen ob die Fahrt zu lange dauert
if GetGameTimer() > rideTimeout then if GetGameTimer() > rideTimeout then
print("^1[TAXI DEBUG]^7 Taxi ride timed out!") DebugPrint("^1[TAXI DEBUG]^7 Taxi ride timed out!")
-- Berechne verbleibende Distanz -- Berechne verbleibende Distanz
local taxiCoords = GetEntityCoords(currentTaxi) local taxiCoords = GetEntityCoords(currentTaxi)
@ -1268,7 +1268,7 @@ function MonitorTaxiRide(destination, price)
end end
function SelfDriveTaxi() function SelfDriveTaxi()
print("^2[TAXI DEBUG]^7 Player driving taxi themselves") DebugPrint("^2[TAXI DEBUG]^7 Player driving taxi themselves")
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
return return
@ -1293,7 +1293,7 @@ function SelfDriveTaxi()
end end
function ExitTaxi() function ExitTaxi()
print("^2[TAXI DEBUG]^7 Player exiting taxi") DebugPrint("^2[TAXI DEBUG]^7 Player exiting taxi")
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
return return
@ -1315,7 +1315,7 @@ function ExitTaxi()
end end
function DespawnTaxi() function DespawnTaxi()
print("^2[TAXI DEBUG]^7 Despawning taxi") DebugPrint("^2[TAXI DEBUG]^7 Despawning taxi")
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
return return
@ -1323,7 +1323,7 @@ function DespawnTaxi()
-- Taxi wegfahren lassen, wenn ein Fahrer existiert -- Taxi wegfahren lassen, wenn ein Fahrer existiert
if currentDriver and DoesEntityExist(currentDriver) then if currentDriver and DoesEntityExist(currentDriver) then
print("^2[TAXI DEBUG]^7 Making taxi drive away before despawn") DebugPrint("^2[TAXI DEBUG]^7 Making taxi drive away before despawn")
-- Zufällige Position in der Nähe finden -- Zufällige Position in der Nähe finden
local taxiCoords = GetEntityCoords(currentTaxi) local taxiCoords = GetEntityCoords(currentTaxi)
@ -1357,7 +1357,7 @@ function DespawnTaxi()
if currentDriver and DoesEntityExist(currentDriver) then if currentDriver and DoesEntityExist(currentDriver) then
DeleteEntity(currentDriver) DeleteEntity(currentDriver)
currentDriver = nil currentDriver = nil
print("^2[TAXI DEBUG]^7 Driver deleted") DebugPrint("^2[TAXI DEBUG]^7 Driver deleted")
end end
-- Taxi löschen -- Taxi löschen
@ -1365,9 +1365,9 @@ function DespawnTaxi()
exports['qb-target']:RemoveTargetEntity(currentTaxi) exports['qb-target']:RemoveTargetEntity(currentTaxi)
DeleteEntity(currentTaxi) DeleteEntity(currentTaxi)
currentTaxi = nil currentTaxi = nil
print("^2[TAXI DEBUG]^7 Taxi deleted") DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted")
end end
print("^2[TAXI DEBUG]^7 Taxi despawn completed") DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed")
end) end)
else else
-- Sofort löschen wenn kein Fahrer da ist -- Sofort löschen wenn kein Fahrer da ist
@ -1391,10 +1391,10 @@ function DespawnTaxi()
exports['qb-target']:RemoveTargetEntity(currentTaxi) exports['qb-target']:RemoveTargetEntity(currentTaxi)
DeleteEntity(currentTaxi) DeleteEntity(currentTaxi)
currentTaxi = nil currentTaxi = nil
print("^2[TAXI DEBUG]^7 Taxi deleted") DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted")
end end
print("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)") DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)")
end end
end end
@ -1464,7 +1464,7 @@ end)
-- Funktion zum Beenden der Fahrt -- Funktion zum Beenden der Fahrt
function EndTaxiRide() function EndTaxiRide()
print("^2[TAXI DEBUG]^7 Ending taxi ride") DebugPrint("^2[TAXI DEBUG]^7 Ending taxi ride")
if not currentTaxi or not DoesEntityExist(currentTaxi) then if not currentTaxi or not DoesEntityExist(currentTaxi) then
return return
@ -1562,7 +1562,7 @@ 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
print("^2[TAXI DEBUG]^7 Cleaning up main script...") DebugPrint("^2[TAXI DEBUG]^7 Cleaning up main script...")
-- UI ausblenden -- UI ausblenden
lib.hideTextUI() lib.hideTextUI()
@ -1570,9 +1570,20 @@ AddEventHandler('onResourceStop', function(resourceName)
-- Taxi despawnen -- Taxi despawnen
DespawnTaxi() DespawnTaxi()
print("^2[TAXI DEBUG]^7 Main cleanup completed") DebugPrint("^2[TAXI DEBUG]^7 Main cleanup completed")
end end
end) end)
function DebugPrint(type, message)
if Config.Debug then
if type == "error" then
print("^1[TAXI DEBUG]^7 " .. message)
elseif type == "warning" then
print("^3[TAXI DEBUG]^7 " .. message)
else -- success/info
print("^2[TAXI DEBUG]^7 " .. message)
end
end
end

View file

@ -2,12 +2,12 @@ local QBCore = exports['qb-core']:GetCoreObject()
local stationVehicles = {} local stationVehicles = {}
local stationBlips = {} local stationBlips = {}
print("^2[TAXI STATIONS DEBUG]^7 Stations script loaded") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Stations script loaded")
-- Taxi Stationen initialisieren -- Taxi Stationen initialisieren
CreateThread(function() CreateThread(function()
Wait(5000) -- Längere Wartezeit, um sicherzustellen, dass alle Ressourcen geladen sind Wait(5000) -- Längere Wartezeit, um sicherzustellen, dass alle Ressourcen geladen sind
print("^2[TAXI STATIONS DEBUG]^7 Initializing taxi stations...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Initializing taxi stations...")
InitializeTaxiStations() InitializeTaxiStations()
-- Regelmäßige Überprüfung und Wiederherstellung der Stationen -- Regelmäßige Überprüfung und Wiederherstellung der Stationen
@ -20,21 +20,21 @@ CreateThread(function()
end) end)
function InitializeTaxiStations() function InitializeTaxiStations()
print("^2[TAXI STATIONS DEBUG]^7 InitializeTaxiStations started") DebugPrint("^2[TAXI STATIONS DEBUG]^7 InitializeTaxiStations started")
if not Config.TaxiStations then if not Config.TaxiStations then
print("^1[TAXI STATIONS DEBUG]^7 Config.TaxiStations not found!") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Config.TaxiStations not found!")
return return
end end
print("^2[TAXI STATIONS DEBUG]^7 Found " .. #Config.TaxiStations .. " stations") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Found " .. #Config.TaxiStations .. " stations")
-- Zuerst alle bestehenden Fahrzeuge und Blips entfernen -- Zuerst alle bestehenden Fahrzeuge und Blips entfernen
CleanupExistingStations() CleanupExistingStations()
-- Dann neue erstellen -- Dann neue erstellen
for stationId, station in pairs(Config.TaxiStations) do for stationId, station in pairs(Config.TaxiStations) do
print("^2[TAXI STATIONS DEBUG]^7 Processing station " .. stationId .. ": " .. station.name) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Processing station " .. stationId .. ": " .. station.name)
-- Blip für Station erstellen -- Blip für Station erstellen
local blip = AddBlipForCoord(station.blipCoords.x, station.blipCoords.y, station.blipCoords.z) local blip = AddBlipForCoord(station.blipCoords.x, station.blipCoords.y, station.blipCoords.z)
@ -46,7 +46,7 @@ function InitializeTaxiStations()
AddTextComponentString(station.name) AddTextComponentString(station.name)
EndTextCommandSetBlipName(blip) EndTextCommandSetBlipName(blip)
stationBlips[stationId] = blip stationBlips[stationId] = blip
print("^2[TAXI STATIONS DEBUG]^7 Blip created for station " .. stationId) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Blip created for station " .. stationId)
-- Fahrzeuge an Station spawnen -- Fahrzeuge an Station spawnen
stationVehicles[stationId] = {} stationVehicles[stationId] = {}
@ -56,17 +56,17 @@ function InitializeTaxiStations()
for vehicleId, vehicleData in pairs(station.vehicles) do for vehicleId, vehicleData in pairs(station.vehicles) do
-- Kleine Verzögerung zwischen jedem Fahrzeug -- Kleine Verzögerung zwischen jedem Fahrzeug
Wait(500) Wait(500)
print("^2[TAXI STATIONS DEBUG]^7 Spawning vehicle " .. vehicleId .. " (" .. vehicleData.model .. ") at station " .. stationId) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Spawning vehicle " .. vehicleId .. " (" .. vehicleData.model .. ") at station " .. stationId)
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
end end
end) end)
end end
print("^2[TAXI STATIONS DEBUG]^7 All stations initialization started") DebugPrint("^2[TAXI STATIONS DEBUG]^7 All stations initialization started")
end end
function CleanupExistingStations() function CleanupExistingStations()
print("^2[TAXI STATIONS DEBUG]^7 Cleaning up existing stations...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleaning up existing stations...")
-- Alle bestehenden Fahrzeuge löschen -- Alle bestehenden Fahrzeuge löschen
for stationId, vehicles in pairs(stationVehicles) do for stationId, vehicles in pairs(stationVehicles) do
@ -90,17 +90,17 @@ function CleanupExistingStations()
stationVehicles = {} stationVehicles = {}
stationBlips = {} stationBlips = {}
print("^2[TAXI STATIONS DEBUG]^7 Cleanup completed") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
end end
function SpawnStationVehicle(stationId, vehicleId, vehicleData) function SpawnStationVehicle(stationId, vehicleId, vehicleData)
print("^2[TAXI STATIONS DEBUG]^7 SpawnStationVehicle: " .. stationId .. "/" .. vehicleId) DebugPrint("^2[TAXI STATIONS DEBUG]^7 SpawnStationVehicle: " .. stationId .. "/" .. vehicleId)
-- Prüfen ob bereits ein Fahrzeug für diese Position existiert -- Prüfen ob bereits ein Fahrzeug für diese Position existiert
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] and if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] and
stationVehicles[stationId][vehicleId].entity and stationVehicles[stationId][vehicleId].entity and
DoesEntityExist(stationVehicles[stationId][vehicleId].entity) then DoesEntityExist(stationVehicles[stationId][vehicleId].entity) then
print("^3[TAXI STATIONS DEBUG]^7 Vehicle already exists for this position, removing it first") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle already exists for this position, removing it first")
exports['qb-target']:RemoveTargetEntity(stationVehicles[stationId][vehicleId].entity) exports['qb-target']:RemoveTargetEntity(stationVehicles[stationId][vehicleId].entity)
DeleteEntity(stationVehicles[stationId][vehicleId].entity) DeleteEntity(stationVehicles[stationId][vehicleId].entity)
end end
@ -112,7 +112,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
local vehCoords = GetEntityCoords(vehicle) local vehCoords = GetEntityCoords(vehicle)
if #(vector3(vehicleData.coords.x, vehicleData.coords.y, vehicleData.coords.z) - vehCoords) < 3.0 then if #(vector3(vehicleData.coords.x, vehicleData.coords.y, vehicleData.coords.z) - vehCoords) < 3.0 then
clearArea = false clearArea = false
print("^3[TAXI STATIONS DEBUG]^7 Position blocked by another vehicle, will retry later") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Position blocked by another vehicle, will retry later")
-- Nach 30 Sekunden erneut versuchen -- Nach 30 Sekunden erneut versuchen
SetTimeout(30000, function() SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -123,17 +123,17 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
CreateThread(function() CreateThread(function()
local vehicleHash = GetHashKey(vehicleData.model) local vehicleHash = GetHashKey(vehicleData.model)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle hash: " .. vehicleHash) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle hash: " .. vehicleHash)
RequestModel(vehicleHash) RequestModel(vehicleHash)
local timeout = GetGameTimer() + 10000 local timeout = GetGameTimer() + 10000
while not HasModelLoaded(vehicleHash) and GetGameTimer() < timeout do while not HasModelLoaded(vehicleHash) and GetGameTimer() < timeout do
print("^3[TAXI STATIONS DEBUG]^7 Waiting for model " .. vehicleData.model .. " to load...") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Waiting for model " .. vehicleData.model .. " to load...")
Wait(100) Wait(100)
end end
if not HasModelLoaded(vehicleHash) then if not HasModelLoaded(vehicleHash) then
print("^1[TAXI STATIONS DEBUG]^7 Failed to load model: " .. vehicleData.model) DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to load model: " .. vehicleData.model)
-- Nach 30 Sekunden erneut versuchen -- Nach 30 Sekunden erneut versuchen
SetTimeout(30000, function() SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -152,7 +152,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
) )
if not DoesEntityExist(vehicle) then if not DoesEntityExist(vehicle) then
print("^1[TAXI STATIONS DEBUG]^7 Failed to create vehicle!") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to create vehicle!")
-- Nach 30 Sekunden erneut versuchen -- Nach 30 Sekunden erneut versuchen
SetTimeout(30000, function() SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -160,7 +160,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
return return
end end
print("^2[TAXI STATIONS DEBUG]^7 Vehicle created: " .. vehicle) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle created: " .. vehicle)
-- Fahrzeug konfigurieren -- Fahrzeug konfigurieren
SetEntityAsMissionEntity(vehicle, true, true) SetEntityAsMissionEntity(vehicle, true, true)
@ -187,7 +187,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
occupied = false occupied = false
} }
print("^2[TAXI STATIONS DEBUG]^7 Adding qb-target for vehicle " .. vehicle) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Adding qb-target for vehicle " .. vehicle)
-- qb-target für Fahrzeug hinzufügen -- qb-target für Fahrzeug hinzufügen
exports['qb-target']:AddTargetEntity(vehicle, { exports['qb-target']:AddTargetEntity(vehicle, {
@ -204,14 +204,14 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
distance = 3.0 distance = 3.0
}) })
print("^2[TAXI STATIONS DEBUG]^7 qb-target added for vehicle " .. vehicle) DebugPrint("^2[TAXI STATIONS DEBUG]^7 qb-target added for vehicle " .. vehicle)
SetModelAsNoLongerNeeded(vehicleHash) SetModelAsNoLongerNeeded(vehicleHash)
end) end)
end end
function CheckAndRestoreStationVehicles() function CheckAndRestoreStationVehicles()
print("^2[TAXI STATIONS DEBUG]^7 Checking station vehicles...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Checking station vehicles...")
local restoredCount = 0 local restoredCount = 0
@ -225,22 +225,22 @@ function CheckAndRestoreStationVehicles()
-- Prüfen ob das Fahrzeug existiert -- Prüfen ob das Fahrzeug existiert
if not stationVehicles[stationId][vehicleId] then if not stationVehicles[stationId][vehicleId] then
print("^3[TAXI STATIONS DEBUG]^7 Vehicle data missing for station " .. stationId .. ", vehicle " .. vehicleId) DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle data missing for station " .. stationId .. ", vehicle " .. vehicleId)
shouldSpawn = true shouldSpawn = true
elseif not stationVehicles[stationId][vehicleId].entity then elseif not stationVehicles[stationId][vehicleId].entity then
print("^3[TAXI STATIONS DEBUG]^7 Vehicle entity missing for station " .. stationId .. ", vehicle " .. vehicleId) DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle entity missing for station " .. stationId .. ", vehicle " .. vehicleId)
shouldSpawn = true shouldSpawn = true
elseif not DoesEntityExist(stationVehicles[stationId][vehicleId].entity) then elseif not DoesEntityExist(stationVehicles[stationId][vehicleId].entity) then
print("^3[TAXI STATIONS DEBUG]^7 Vehicle entity doesn't exist for station " .. stationId .. ", vehicle " .. vehicleId) DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle entity doesn't exist for station " .. stationId .. ", vehicle " .. vehicleId)
shouldSpawn = true shouldSpawn = true
elseif stationVehicles[stationId][vehicleId].occupied then elseif stationVehicles[stationId][vehicleId].occupied then
-- Fahrzeug ist besetzt, nicht neu spawnen -- Fahrzeug ist besetzt, nicht neu spawnen
print("^2[TAXI STATIONS DEBUG]^7 Vehicle at station " .. stationId .. ", vehicle " .. vehicleId .. " is occupied") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle at station " .. stationId .. ", vehicle " .. vehicleId .. " is occupied")
shouldSpawn = false shouldSpawn = false
end end
if shouldSpawn then if shouldSpawn then
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station " .. stationId .. ", vehicle " .. vehicleId) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station " .. stationId .. ", vehicle " .. vehicleId)
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
restoredCount = restoredCount + 1 restoredCount = restoredCount + 1
@ -251,9 +251,9 @@ function CheckAndRestoreStationVehicles()
end end
if restoredCount > 0 then if restoredCount > 0 then
print("^2[TAXI STATIONS DEBUG]^7 Restored " .. restoredCount .. " station vehicles") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Restored " .. restoredCount .. " station vehicles")
else else
print("^2[TAXI STATIONS DEBUG]^7 All station vehicles are present") DebugPrint("^2[TAXI STATIONS DEBUG]^7 All station vehicles are present")
end end
end end
@ -261,7 +261,7 @@ end
function InitializeTaxiDriverAI(driver, vehicle) function InitializeTaxiDriverAI(driver, vehicle)
if not driver or not DoesEntityExist(driver) then return end if not driver or not DoesEntityExist(driver) then return end
print("^2[TAXI STATIONS DEBUG]^7 Initializing advanced taxi driver AI") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Initializing advanced taxi driver AI")
-- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen -- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen
local driverData = { local driverData = {
@ -344,14 +344,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Gerade an Ampel angekommen -- Gerade an Ampel angekommen
driverData.state.isWaitingAtTrafficLight = true driverData.state.isWaitingAtTrafficLight = true
driverData.state.trafficLightWaitStart = currentTime driverData.state.trafficLightWaitStart = currentTime
print("^3[TAXI STATIONS DEBUG]^7 Taxi waiting at traffic light") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Taxi waiting at traffic light")
elseif isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then elseif isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Immer noch an Ampel -- Immer noch an Ampel
local waitTime = currentTime - driverData.state.trafficLightWaitStart local waitTime = currentTime - driverData.state.trafficLightWaitStart
-- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen) -- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen)
if waitTime > driverData.settings.trafficLightMaxWait then if waitTime > driverData.settings.trafficLightMaxWait then
print("^3[TAXI STATIONS DEBUG]^7 Taxi waited too long at traffic light, trying to continue") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Taxi waited too long at traffic light, trying to continue")
-- Kurz vorwärts fahren um Ampel zu überwinden -- Kurz vorwärts fahren um Ampel zu überwinden
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000) Wait(2000)
@ -362,7 +362,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Ampel verlassen -- Ampel verlassen
driverData.state.isWaitingAtTrafficLight = false driverData.state.isWaitingAtTrafficLight = false
print("^2[TAXI STATIONS DEBUG]^7 Taxi continued after traffic light") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Taxi continued after traffic light")
end end
-- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung) -- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung)
@ -371,14 +371,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Nur alle 5 Zähler-Erhöhungen loggen -- Nur alle 5 Zähler-Erhöhungen loggen
if driverData.state.stuckCounter % 5 == 0 then if driverData.state.stuckCounter % 5 == 0 then
print("^3[TAXI STATIONS DEBUG]^7 Taxi might be stuck: " .. driverData.state.stuckCounter .. "/" .. driverData.settings.maxStuckCounter) DebugPrint("^3[TAXI STATIONS DEBUG]^7 Taxi might be stuck: " .. driverData.state.stuckCounter .. "/" .. driverData.settings.maxStuckCounter)
end end
-- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch -- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch
if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and
(currentTime - driverData.state.lastStuckRecovery) > driverData.settings.minRecoveryInterval then (currentTime - driverData.state.lastStuckRecovery) > driverData.settings.minRecoveryInterval then
print("^1[TAXI STATIONS DEBUG]^7 Taxi is stuck, attempting intelligent recovery") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Taxi is stuck, attempting intelligent recovery")
driverData.state.lastStuckRecovery = currentTime driverData.state.lastStuckRecovery = currentTime
driverData.state.currentBehavior = "recovery" driverData.state.currentBehavior = "recovery"
@ -401,7 +401,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and
(currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then (currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then
print("^3[TAXI STATIONS DEBUG]^7 Taxi moving too slow, recalculating route") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Taxi moving too slow, recalculating route")
driverData.state.lastRouteRecalculation = currentTime driverData.state.lastRouteRecalculation = currentTime
-- Route neu berechnen -- Route neu berechnen
@ -449,17 +449,17 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
if backwardClear then if backwardClear then
-- Rückwärts fahren wenn hinten frei -- Rückwärts fahren wenn hinten frei
print("^3[TAXI STATIONS DEBUG]^7 Recovery: Backing up") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Backing up")
TaskVehicleTempAction(driver, vehicle, 8, 2000) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 2000) -- Reverse
Wait(2000) Wait(2000)
if forwardClear then if forwardClear then
-- Wenn vorne auch frei, einfach weiterfahren -- Wenn vorne auch frei, einfach weiterfahren
print("^3[TAXI STATIONS DEBUG]^7 Recovery: Path clear, continuing") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Path clear, continuing")
TaxiDriverContinueRoute(driver, vehicle) TaxiDriverContinueRoute(driver, vehicle)
else else
-- Sonst versuchen zu wenden -- Sonst versuchen zu wenden
print("^3[TAXI STATIONS DEBUG]^7 Recovery: Turning around") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Turning around")
TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left
Wait(1000) Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse
@ -470,13 +470,13 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
end end
elseif forwardClear then elseif forwardClear then
-- Wenn nur vorne frei, vorwärts fahren -- Wenn nur vorne frei, vorwärts fahren
print("^3[TAXI STATIONS DEBUG]^7 Recovery: Moving forward") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Moving forward")
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000) Wait(2000)
TaxiDriverContinueRoute(driver, vehicle) TaxiDriverContinueRoute(driver, vehicle)
else else
-- Wenn komplett eingeklemmt, versuche zu rütteln -- Wenn komplett eingeklemmt, versuche zu rütteln
print("^3[TAXI STATIONS DEBUG]^7 Recovery: Trying to wiggle free") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Trying to wiggle free")
TaskVehicleTempAction(driver, vehicle, 7, 1000) -- Turn left TaskVehicleTempAction(driver, vehicle, 7, 1000) -- Turn left
Wait(1000) Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse
@ -499,7 +499,7 @@ function TaxiDriverRecalculateRoute(driver, vehicle)
if destination then if destination then
-- Versuche einen alternativen Weg zu finden -- Versuche einen alternativen Weg zu finden
print("^3[TAXI STATIONS DEBUG]^7 Recalculating route to destination") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recalculating route to destination")
-- Kurz anhalten -- Kurz anhalten
TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop
@ -602,14 +602,14 @@ end
-- Event für Einsteigen in Station-Taxi -- Event für Einsteigen in Station-Taxi
RegisterNetEvent('taxi:enterStationVehicle', function(data) RegisterNetEvent('taxi:enterStationVehicle', function(data)
print("^2[TAXI STATIONS DEBUG]^7 Player trying to enter station vehicle") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player trying to enter station vehicle")
print("^2[TAXI STATIONS DEBUG]^7 Data: " .. json.encode(data)) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Data: " .. json.encode(data))
local stationId = data.stationId local stationId = data.stationId
local vehicleId = data.vehicleId local vehicleId = data.vehicleId
if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then
print("^1[TAXI STATIONS DEBUG]^7 Vehicle not found in data") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle not found in data")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Dieses Taxi ist nicht verfügbar', description = 'Dieses Taxi ist nicht verfügbar',
@ -621,7 +621,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
local vehicleInfo = stationVehicles[stationId][vehicleId] local vehicleInfo = stationVehicles[stationId][vehicleId]
if vehicleInfo.occupied then if vehicleInfo.occupied then
print("^1[TAXI STATIONS DEBUG]^7 Vehicle already occupied") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle already occupied")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Dieses Taxi ist bereits besetzt', description = 'Dieses Taxi ist bereits besetzt',
@ -630,7 +630,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
return return
end end
print("^2[TAXI STATIONS DEBUG]^7 Entering vehicle...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Entering vehicle...")
-- Spieler ins Fahrzeug setzen -- Spieler ins Fahrzeug setzen
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
@ -639,7 +639,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Türen entsperren -- Türen entsperren
SetVehicleDoorsLocked(vehicle, 1) SetVehicleDoorsLocked(vehicle, 1)
-- Info-Text anzeigen während Fahrer geladen wird -- Info-Text anzeigen während Fahrer geladen wird
print("^2[TAXI STATIONS DEBUG]^7 Showing driver loading text...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Showing driver loading text...")
lib.showTextUI('🚕 Warte an der Station - Fahrer wird geladen...', { lib.showTextUI('🚕 Warte an der Station - Fahrer wird geladen...', {
position = "top-center", position = "top-center",
icon = 'taxi', icon = 'taxi',
@ -669,7 +669,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
local driverHash = nil local driverHash = nil
for i, modelName in pairs(driverModels) do for i, modelName in pairs(driverModels) do
print("^2[TAXI STATIONS DEBUG]^7 Trying driver model " .. i .. ": " .. modelName) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Trying driver model " .. i .. ": " .. modelName)
driverHash = GetHashKey(modelName) driverHash = GetHashKey(modelName)
-- Text während Model-Loading aktualisieren -- Text während Model-Loading aktualisieren
@ -690,13 +690,13 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
attempts = attempts + 1 attempts = attempts + 1
if attempts % 10 == 0 then if attempts % 10 == 0 then
print("^3[TAXI STATIONS DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")")
end end
Wait(100) Wait(100)
end end
if HasModelLoaded(driverHash) then if HasModelLoaded(driverHash) then
print("^2[TAXI STATIONS DEBUG]^7 Driver model " .. modelName .. " loaded successfully") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver model " .. modelName .. " loaded successfully")
-- Text aktualisieren -- Text aktualisieren
lib.showTextUI('🚕 Erstelle Fahrer...', { lib.showTextUI('🚕 Erstelle Fahrer...', {
@ -712,14 +712,14 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false)
if DoesEntityExist(driver) then if DoesEntityExist(driver) then
print("^2[TAXI STATIONS DEBUG]^7 Driver created successfully: " .. driver) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver created successfully: " .. driver)
break break
else else
print("^1[TAXI STATIONS DEBUG]^7 Failed to create driver with model: " .. modelName) DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to create driver with model: " .. modelName)
SetModelAsNoLongerNeeded(driverHash) SetModelAsNoLongerNeeded(driverHash)
end end
else else
print("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model: " .. modelName) DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model: " .. modelName)
SetModelAsNoLongerNeeded(driverHash) SetModelAsNoLongerNeeded(driverHash)
end end
@ -728,7 +728,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Fallback: Notfall-Fahrer erstellen -- Fallback: Notfall-Fahrer erstellen
if not driver or not DoesEntityExist(driver) then if not driver or not DoesEntityExist(driver) then
print("^3[TAXI STATIONS DEBUG]^7 Using emergency fallback driver creation...") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Using emergency fallback driver creation...")
lib.showTextUI('🚕 Erstelle Notfall-Fahrer...', { lib.showTextUI('🚕 Erstelle Notfall-Fahrer...', {
position = "top-center", position = "top-center",
@ -758,7 +758,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
if HasModelLoaded(hash) then if HasModelLoaded(hash) then
driver = CreatePedInsideVehicle(vehicle, 26, hash, -1, true, false) driver = CreatePedInsideVehicle(vehicle, 26, hash, -1, true, false)
if DoesEntityExist(driver) then if DoesEntityExist(driver) then
print("^2[TAXI STATIONS DEBUG]^7 Emergency driver created") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Emergency driver created")
driverHash = hash driverHash = hash
break break
end end
@ -771,7 +771,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren -- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren
if not driver or not DoesEntityExist(driver) then if not driver or not DoesEntityExist(driver) then
print("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver")
lib.showTextUI('❌ Kein Fahrer verfügbar - Du kannst selbst fahren', { lib.showTextUI('❌ Kein Fahrer verfügbar - Du kannst selbst fahren', {
position = "top-center", position = "top-center",
@ -849,11 +849,11 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Ersten verfügbaren Hintersitz wählen -- Ersten verfügbaren Hintersitz wählen
if #availableSeats > 0 then if #availableSeats > 0 then
seatIndex = availableSeats[1] seatIndex = availableSeats[1]
print("^2[TAXI STATIONS DEBUG]^7 Using rear seat: " .. seatIndex) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Using rear seat: " .. seatIndex)
else else
-- Fallback: Beifahrersitz -- Fallback: Beifahrersitz
seatIndex = 0 seatIndex = 0
print("^3[TAXI STATIONS DEBUG]^7 No rear seats available, using passenger seat") DebugPrint("^3[TAXI STATIONS DEBUG]^7 No rear seats available, using passenger seat")
end end
-- Spieler in den gewählten Sitz einsteigen lassen -- Spieler in den gewählten Sitz einsteigen lassen
@ -884,14 +884,14 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Info-Text verstecken -- Info-Text verstecken
lib.hideTextUI() lib.hideTextUI()
print("^2[TAXI STATIONS DEBUG]^7 Player entered successfully") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player entered successfully")
-- Prüfen ob Spieler wirklich hinten sitzt -- Prüfen ob Spieler wirklich hinten sitzt
local playerSeat = GetPlayerVehicleSeat(playerPed, vehicle) local playerSeat = GetPlayerVehicleSeat(playerPed, vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Player is in seat: " .. tostring(playerSeat)) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player is in seat: " .. tostring(playerSeat))
if playerSeat == -1 then -- Fahrersitz if playerSeat == -1 then -- Fahrersitz
print("^3[TAXI STATIONS DEBUG]^7 Player is in driver seat, moving to passenger area") DebugPrint("^3[TAXI STATIONS DEBUG]^7 Player is in driver seat, moving to passenger area")
if driver and DoesEntityExist(driver) then if driver and DoesEntityExist(driver) then
-- Spieler zum nächsten verfügbaren Sitz bewegen -- Spieler zum nächsten verfügbaren Sitz bewegen
@ -916,7 +916,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
end end
if not hasEntered then if not hasEntered then
print("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle")
-- Info-Text verstecken -- Info-Text verstecken
lib.hideTextUI() lib.hideTextUI()
@ -938,7 +938,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
end) end)
function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm)
print("^2[TAXI STATIONS DEBUG]^7 Opening station taxi menu") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Opening station taxi menu")
local options = {} local options = {}
@ -1020,7 +1020,7 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm)
end end
function SelfDriveStationTaxi(stationId, vehicleId, vehicle) function SelfDriveStationTaxi(stationId, vehicleId, vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Player driving taxi themselves") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player driving taxi themselves")
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
@ -1040,7 +1040,7 @@ function SelfDriveStationTaxi(stationId, vehicleId, vehicle)
-- Prüfen ob Spieler noch im Fahrzeug ist -- Prüfen ob Spieler noch im Fahrzeug ist
if not IsPedInVehicle(playerPed, vehicle, false) then if not IsPedInVehicle(playerPed, vehicle, false) then
print("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi")
-- Nach 30 Sekunden Taxi zurück zur Station -- Nach 30 Sekunden Taxi zurück zur Station
SetTimeout(30000, function() SetTimeout(30000, function()
@ -1055,7 +1055,7 @@ function SelfDriveStationTaxi(stationId, vehicleId, vehicle)
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") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Opening station selection menu")
local options = {} local options = {}
@ -1095,7 +1095,7 @@ function OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePe
end 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.x) .. ", " .. tostring(destination.y) .. ", " .. tostring(destination.z)) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Starting station taxi ride to: " .. tostring(destination.x) .. ", " .. tostring(destination.y) .. ", " .. tostring(destination.z))
-- Wenn kein Fahrer, Spieler selbst fahren lassen -- Wenn kein Fahrer, Spieler selbst fahren lassen
if not driver or not DoesEntityExist(driver) then if not driver or not DoesEntityExist(driver) then
@ -1179,7 +1179,7 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
-- Angekommen -- Angekommen
TaskVehicleTempAction(driver, vehicle, 27, 3000) TaskVehicleTempAction(driver, vehicle, 27, 3000)
print("^2[TAXI STATIONS DEBUG]^7 Arrived at destination") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Arrived at destination")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Du bist angekommen! Preis: $' .. price, description = 'Du bist angekommen! Preis: $' .. price,
@ -1220,7 +1220,7 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
-- Überprüfen ob die Fahrt zu lange dauert -- Überprüfen ob die Fahrt zu lange dauert
if GetGameTimer() > rideTimeout then if GetGameTimer() > rideTimeout then
print("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Taxi ride timed out!")
lib.notify({ lib.notify({
title = 'Taxi Service', title = 'Taxi Service',
description = 'Die Fahrt dauert zu lange. Wir sind fast da!', description = 'Die Fahrt dauert zu lange. Wir sind fast da!',
@ -1254,7 +1254,7 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
end end
function ExitStationTaxi(stationId, vehicleId, vehicle, driver) function ExitStationTaxi(stationId, vehicleId, vehicle, driver)
print("^2[TAXI STATIONS DEBUG]^7 Player exiting station taxi") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player exiting station taxi")
local playerPed = PlayerPedId() local playerPed = PlayerPedId()
TaskLeaveVehicle(playerPed, vehicle, 0) TaskLeaveVehicle(playerPed, vehicle, 0)
@ -1272,26 +1272,26 @@ function ExitStationTaxi(stationId, vehicleId, vehicle, driver)
end end
function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
print("^2[TAXI STATIONS DEBUG]^7 Returning taxi to station: " .. stationId .. "/" .. vehicleId) DebugPrint("^2[TAXI STATIONS DEBUG]^7 Returning taxi to station: " .. stationId .. "/" .. vehicleId)
if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then
print("^1[TAXI STATIONS DEBUG]^7 Station vehicle data not found for return") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Station vehicle data not found for return")
return return
end end
if not DoesEntityExist(vehicle) then if not DoesEntityExist(vehicle) then
print("^1[TAXI STATIONS DEBUG]^7 Vehicle doesn't exist anymore") DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle doesn't exist anymore")
-- Fahrzeug als nicht besetzt markieren -- Fahrzeug als nicht besetzt markieren
stationVehicles[stationId][vehicleId].occupied = false stationVehicles[stationId][vehicleId].occupied = false
stationVehicles[stationId][vehicleId].driver = nil stationVehicles[stationId][vehicleId].driver = nil
stationVehicles[stationId][vehicleId].entity = nil stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen -- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function() SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
end end
end) end)
@ -1300,7 +1300,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
-- Wenn Fahrer existiert, Taxi zur Station zurückfahren lassen -- Wenn Fahrer existiert, Taxi zur Station zurückfahren lassen
if driver and DoesEntityExist(driver) then if driver and DoesEntityExist(driver) then
print("^2[TAXI STATIONS DEBUG]^7 Making taxi drive back to station") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Making taxi drive back to station")
-- Zufällige Position in der Nähe der Station finden -- Zufällige Position in der Nähe der Station finden
local stationCoords = Config.TaxiStations[stationId].coords local stationCoords = Config.TaxiStations[stationId].coords
@ -1317,13 +1317,13 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
-- Fahrer löschen -- Fahrer löschen
if driver and DoesEntityExist(driver) then if driver and DoesEntityExist(driver) then
DeleteEntity(driver) DeleteEntity(driver)
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end end
-- Fahrzeug löschen -- Fahrzeug löschen
if DoesEntityExist(vehicle) then if DoesEntityExist(vehicle) then
DeleteEntity(vehicle) DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end end
-- Fahrzeug als nicht besetzt markieren -- Fahrzeug als nicht besetzt markieren
@ -1332,11 +1332,11 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
stationVehicles[stationId][vehicleId].entity = nil stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen -- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function() SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
end end
end) end)
@ -1347,7 +1347,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
if DoesEntityExist(vehicle) then if DoesEntityExist(vehicle) then
exports['qb-target']:RemoveTargetEntity(vehicle) exports['qb-target']:RemoveTargetEntity(vehicle)
DeleteEntity(vehicle) DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end end
-- Fahrzeug als nicht besetzt markieren -- Fahrzeug als nicht besetzt markieren
@ -1356,11 +1356,11 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
stationVehicles[stationId][vehicleId].entity = nil stationVehicles[stationId][vehicleId].entity = nil
-- Nach Respawn-Zeit neues Fahrzeug spawnen -- Nach Respawn-Zeit neues Fahrzeug spawnen
print("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Scheduling respawn in " .. Config.StationTaxiRespawnTime .. " seconds")
SetTimeout(Config.StationTaxiRespawnTime * 1000, function() SetTimeout(Config.StationTaxiRespawnTime * 1000, function()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
local vehicleData = stationVehicles[stationId][vehicleId].data local vehicleData = stationVehicles[stationId][vehicleId].data
print("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData) SpawnStationVehicle(stationId, vehicleId, vehicleData)
end end
end) end)
@ -1406,7 +1406,7 @@ end)
-- Event für Admin Respawn -- Event für Admin Respawn
RegisterNetEvent('taxi:respawnAllStations', function() RegisterNetEvent('taxi:respawnAllStations', function()
print("^2[TAXI STATIONS DEBUG]^7 Respawning all stations...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning all stations...")
-- Alle bestehenden Fahrzeuge löschen -- Alle bestehenden Fahrzeuge löschen
for stationId, vehicles in pairs(stationVehicles) do for stationId, vehicles in pairs(stationVehicles) do
@ -1505,7 +1505,7 @@ end)
-- Funktion zum Beenden der Stations-Taxi Fahrt -- Funktion zum Beenden der Stations-Taxi Fahrt
function EndStationTaxiRide(stationId, vehicleId, vehicle, driver) function EndStationTaxiRide(stationId, vehicleId, vehicle, driver)
print("^2[TAXI STATIONS DEBUG]^7 Ending station taxi ride") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Ending station taxi ride")
if not vehicle or not DoesEntityExist(vehicle) then if not vehicle or not DoesEntityExist(vehicle) then
return return
@ -1544,7 +1544,7 @@ 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
print("^2[TAXI STATIONS DEBUG]^7 Cleaning up stations...") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleaning up stations...")
-- TextUI verstecken falls noch angezeigt -- TextUI verstecken falls noch angezeigt
lib.hideTextUI() lib.hideTextUI()
@ -1567,10 +1567,21 @@ AddEventHandler('onResourceStop', function(resourceName)
RemoveBlip(blip) RemoveBlip(blip)
end end
print("^2[TAXI STATIONS DEBUG]^7 Cleanup completed") DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
end end
end) end)
function DebugPrint(type, message)
if Config.Debug then
if type == "error" then
print("^1[TAXI DEBUG]^7 " .. message)
elseif type == "warning" then
print("^3[TAXI DEBUG]^7 " .. message)
else -- success/info
orint("^2[TAXI DEBUG]^7 " .. message)
end
end
end

View file

@ -1,5 +1,8 @@
Config = {} Config = {}
Config.Debug = false -- Set to true to enable debug prints, false to disable
-- Taxi Fahrzeuge und Preise -- Taxi Fahrzeuge und Preise
Config.TaxiVehicles = { Config.TaxiVehicles = {
{ {