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
}
print("^2[TAXI DEBUG]^7 Main script loaded")
DebugPrint("^2[TAXI DEBUG]^7 Main script loaded")
-- Taxi rufen Command
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
print("^1[TAXI DEBUG]^7 Taxi already exists")
DebugPrint("^1[TAXI DEBUG]^7 Taxi already exists")
lib.notify({
title = 'Taxi Service',
description = 'Du hast bereits ein Taxi gerufen',
@ -31,7 +31,7 @@ RegisterCommand('taxi', function()
end)
function CallTaxi()
print("^2[TAXI DEBUG]^7 CallTaxi function started")
DebugPrint("^2[TAXI DEBUG]^7 CallTaxi function started")
lib.notify({
title = 'Taxi Service',
@ -43,12 +43,12 @@ function CallTaxi()
local playerPed = PlayerPedId()
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
local spawnCoords = GetImprovedTaxiSpawnPosition(playerCoords)
if not spawnCoords then
print("^1[TAXI DEBUG]^7 No spawn position found")
DebugPrint("^1[TAXI DEBUG]^7 No spawn position found")
lib.notify({
title = 'Taxi Service',
description = 'Kein geeigneter Spawn-Punkt gefunden',
@ -57,12 +57,12 @@ function CallTaxi()
return
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
local taxi = SpawnTaxi(spawnCoords)
if not taxi then
print("^1[TAXI DEBUG]^7 Failed to spawn taxi")
DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn taxi")
lib.notify({
title = 'Taxi Service',
description = 'Taxi konnte nicht gespawnt werden',
@ -71,14 +71,14 @@ function CallTaxi()
return
end
print("^2[TAXI DEBUG]^7 Taxi spawned: " .. taxi)
DebugPrint("^2[TAXI DEBUG]^7 Taxi spawned: " .. taxi)
currentTaxi = taxi
-- Fahrer spawnen
local driver = SpawnTaxiDriver(taxi)
if driver then
currentDriver = driver
print("^2[TAXI DEBUG]^7 Driver spawned: " .. driver)
DebugPrint("^2[TAXI DEBUG]^7 Driver spawned: " .. driver)
-- Verbesserte Navigation zum Spieler
NavigateToPlayer(driver, taxi, playerCoords)
@ -95,7 +95,7 @@ function CallTaxi()
type = 'success'
})
else
print("^1[TAXI DEBUG]^7 Failed to spawn driver")
DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn driver")
lib.notify({
title = 'Taxi Service',
description = 'Taxi ohne Fahrer gespawnt - Du kannst es selbst fahren',
@ -106,7 +106,7 @@ function CallTaxi()
end
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
local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt
@ -127,7 +127,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local nodeDistance = #(playerCoords - nodePos)
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
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}
else
-- Speichern für später, falls wir nichts Besseres finden
@ -150,7 +150,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
if foundNode then
local nodeDistance = #(playerCoords - nodePos)
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}
else
-- Speichern für später, falls wir nichts Besseres finden
@ -169,7 +169,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local nodeDistance = #(playerCoords - nodePos)
if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then
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}
else
-- Speichern für später, falls wir nichts Besseres finden
@ -228,7 +228,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
-- Wenn Position frei ist, verwenden
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
end
@ -239,12 +239,12 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
-- Wenn wir hier sind, haben wir keine ideale Position gefunden
-- Wenn wir eine "beste" Position haben, die den Mindestabstand einhält, verwenden wir diese
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
end
-- 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
for attempt = 1, 15 do
@ -262,7 +262,7 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
local isOnRoad = IsPointOnRoad(x, y, groundZ)
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}
end
end
@ -281,13 +281,13 @@ function GetImprovedTaxiSpawnPosition(playerCoords)
z = groundZ
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}
end
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
local taxiModel = nil
@ -299,7 +299,7 @@ function SpawnTaxi(coords)
taxiModel = GetHashKey("taxi") -- Fallback
end
print("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel)
DebugPrint("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel)
-- Model laden mit Timeout
RequestModel(taxiModel)
@ -309,13 +309,13 @@ function SpawnTaxi(coords)
while not modelLoaded and GetGameTimer() < timeout do
modelLoaded = HasModelLoaded(taxiModel)
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)
end
end
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)
-- Versuche Standard-Taxi als Fallback
@ -328,7 +328,7 @@ function SpawnTaxi(coords)
end
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
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)
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
end
print("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi)
DebugPrint("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi)
-- Fahrzeug konfigurieren
SetEntityAsMissionEntity(taxi, true, true)
@ -361,7 +361,7 @@ function SpawnTaxi(coords)
local liveryCount = GetVehicleLiveryCount(taxi)
if liveryCount > 0 then
SetVehicleLivery(taxi, 0) -- Erste Livery verwenden
print("^2[TAXI DEBUG]^7 Taxi livery set")
DebugPrint("^2[TAXI DEBUG]^7 Taxi livery set")
end
-- Fahrzeug-Extras aktivieren falls vorhanden
@ -382,7 +382,7 @@ end
function InitializeTaxiDriverAI(driver, vehicle)
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
local driverData = {
@ -465,14 +465,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Gerade an Ampel angekommen
driverData.state.isWaitingAtTrafficLight = true
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
-- Immer noch an Ampel
local waitTime = currentTime - driverData.state.trafficLightWaitStart
-- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen)
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
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000)
@ -483,7 +483,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Ampel verlassen
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
-- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung)
@ -492,14 +492,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Nur alle 5 Zähler-Erhöhungen loggen
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
-- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch
if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and
(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.currentBehavior = "recovery"
@ -522,7 +522,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and
(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
-- Route neu berechnen
@ -570,17 +570,17 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
if backwardClear then
-- 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
Wait(2000)
if forwardClear then
-- 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)
else
-- 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
Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse
@ -591,13 +591,13 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
end
elseif forwardClear then
-- 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
Wait(2000)
TaxiDriverContinueRoute(driver, vehicle)
else
-- 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
Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse
@ -619,7 +619,7 @@ function TaxiDriverRecalculateRoute(driver, vehicle)
if destination then
-- 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
TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop
@ -714,7 +714,7 @@ function norm(vector)
end
function SpawnTaxiDriver(vehicle)
print("^2[TAXI DEBUG]^7 Spawning taxi driver...")
DebugPrint("^2[TAXI DEBUG]^7 Spawning taxi driver...")
-- Bessere Fahrer-Models mit Fallbacks
local driverModels = {
@ -733,7 +733,7 @@ function SpawnTaxiDriver(vehicle)
-- Versuche verschiedene Models
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)
-- Model laden
@ -744,38 +744,38 @@ function SpawnTaxiDriver(vehicle)
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
attempts = attempts + 1
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
Wait(100)
end
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
driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false)
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
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)
end
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)
end
end
-- Wenn immer noch kein Fahrer erstellt wurde
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
end
-- Fahrer konfigurieren
print("^2[TAXI DEBUG]^7 Configuring driver...")
DebugPrint("^2[TAXI DEBUG]^7 Configuring driver...")
SetEntityAsMissionEntity(driver, true, true)
SetBlockingOfNonTemporaryEvents(driver, true)
@ -799,7 +799,7 @@ function SpawnTaxiDriver(vehicle)
-- Fahrer-Outfit (nur wenn es ein anpassbarer Ped ist)
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
SetPedComponentVariation(driver, 0, 0, 0, 0) -- Face
@ -824,7 +824,7 @@ function SpawnTaxiDriver(vehicle)
SetModelAsNoLongerNeeded(driverHash)
end
print("^2[TAXI DEBUG]^7 Driver spawn completed successfully")
DebugPrint("^2[TAXI DEBUG]^7 Driver spawn completed successfully")
return driver
end
@ -869,7 +869,7 @@ function CreateTaxiBlips(taxi)
end
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
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)
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
TaskVehicleDriveToCoordLongrange(driver, taxi, nodePos.x, nodePos.y, nodePos.z, 20.0, 786603, 10.0)
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
TaskVehicleDriveToCoordLongrange(driver, taxi, playerCoords.x, playerCoords.y, playerCoords.z, 20.0, 786603, 10.0)
end
end
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
@ -901,7 +901,7 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
-- Check if taxi is close to player
if distance < 15.0 then
print("^2[TAXI DEBUG]^7 Taxi arrived!")
DebugPrint("^2[TAXI DEBUG]^7 Taxi arrived!")
-- Taxi stoppen
if driver and DoesEntityExist(driver) then
@ -934,7 +934,7 @@ function MonitorTaxiArrival(taxi, driver, playerCoords)
-- Check for timeout
if GetGameTimer() > arrivalTimeout then
print("^1[TAXI DEBUG]^7 Taxi arrival timed out!")
DebugPrint("^1[TAXI DEBUG]^7 Taxi arrival timed out!")
lib.notify({
title = 'Taxi Service',
description = 'Dein Taxi steckt fest. Ein neues wird gerufen!',
@ -955,10 +955,10 @@ end
-- Event für Einsteigen ins Taxi
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
print("^1[TAXI DEBUG]^7 No taxi exists")
DebugPrint("^1[TAXI DEBUG]^7 No taxi exists")
return
end
@ -983,7 +983,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
while GetGameTimer() < timeout and not entered do
if IsPedInVehicle(playerPed, currentTaxi, false) then
entered = true
print("^2[TAXI DEBUG]^7 Player entered taxi successfully")
DebugPrint("^2[TAXI DEBUG]^7 Player entered taxi successfully")
-- qb-target entfernen
exports['qb-target']:RemoveTargetEntity(currentTaxi)
@ -1002,7 +1002,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
end
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({
title = 'Taxi Service',
description = 'Einsteigen fehlgeschlagen',
@ -1013,7 +1013,7 @@ RegisterNetEvent('taxi:enterTaxi', function()
end)
function OpenDestinationMenu()
print("^2[TAXI DEBUG]^7 Opening destination menu")
DebugPrint("^2[TAXI DEBUG]^7 Opening destination menu")
local options = {}
@ -1087,10 +1087,10 @@ function OpenDestinationMenu()
end
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
print("^1[TAXI DEBUG]^7 No taxi exists for ride")
DebugPrint("^1[TAXI DEBUG]^7 No taxi exists for ride")
return
end
@ -1164,7 +1164,7 @@ function StartTaxiRide(destination, price)
end
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
@ -1178,7 +1178,7 @@ function MonitorTaxiRide(destination, price)
-- Angekommen
TaskVehicleTempAction(currentDriver, currentTaxi, 27, 3000)
print("^2[TAXI DEBUG]^7 Arrived at destination")
DebugPrint("^2[TAXI DEBUG]^7 Arrived at destination")
lib.notify({
title = 'Taxi Service',
description = 'Du bist angekommen! Preis: $' .. price,
@ -1222,7 +1222,7 @@ function MonitorTaxiRide(destination, price)
-- Überprüfen ob die Fahrt zu lange dauert
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
local taxiCoords = GetEntityCoords(currentTaxi)
@ -1268,7 +1268,7 @@ function MonitorTaxiRide(destination, price)
end
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
return
@ -1293,7 +1293,7 @@ function SelfDriveTaxi()
end
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
return
@ -1315,7 +1315,7 @@ function ExitTaxi()
end
function DespawnTaxi()
print("^2[TAXI DEBUG]^7 Despawning taxi")
DebugPrint("^2[TAXI DEBUG]^7 Despawning taxi")
if not currentTaxi or not DoesEntityExist(currentTaxi) then
return
@ -1323,7 +1323,7 @@ function DespawnTaxi()
-- Taxi wegfahren lassen, wenn ein Fahrer existiert
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
local taxiCoords = GetEntityCoords(currentTaxi)
@ -1357,7 +1357,7 @@ function DespawnTaxi()
if currentDriver and DoesEntityExist(currentDriver) then
DeleteEntity(currentDriver)
currentDriver = nil
print("^2[TAXI DEBUG]^7 Driver deleted")
DebugPrint("^2[TAXI DEBUG]^7 Driver deleted")
end
-- Taxi löschen
@ -1365,9 +1365,9 @@ function DespawnTaxi()
exports['qb-target']:RemoveTargetEntity(currentTaxi)
DeleteEntity(currentTaxi)
currentTaxi = nil
print("^2[TAXI DEBUG]^7 Taxi deleted")
DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted")
end
print("^2[TAXI DEBUG]^7 Taxi despawn completed")
DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed")
end)
else
-- Sofort löschen wenn kein Fahrer da ist
@ -1391,10 +1391,10 @@ function DespawnTaxi()
exports['qb-target']:RemoveTargetEntity(currentTaxi)
DeleteEntity(currentTaxi)
currentTaxi = nil
print("^2[TAXI DEBUG]^7 Taxi deleted")
DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted")
end
print("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)")
DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)")
end
end
@ -1464,7 +1464,7 @@ end)
-- Funktion zum Beenden der Fahrt
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
return
@ -1562,7 +1562,7 @@ end)
-- Cleanup beim Resource Stop
AddEventHandler('onResourceStop', function(resourceName)
if GetCurrentResourceName() == resourceName then
print("^2[TAXI DEBUG]^7 Cleaning up main script...")
DebugPrint("^2[TAXI DEBUG]^7 Cleaning up main script...")
-- UI ausblenden
lib.hideTextUI()
@ -1570,9 +1570,20 @@ AddEventHandler('onResourceStop', function(resourceName)
-- Taxi despawnen
DespawnTaxi()
print("^2[TAXI DEBUG]^7 Main cleanup completed")
DebugPrint("^2[TAXI DEBUG]^7 Main cleanup completed")
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 stationBlips = {}
print("^2[TAXI STATIONS DEBUG]^7 Stations script loaded")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Stations script loaded")
-- Taxi Stationen initialisieren
CreateThread(function()
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()
-- Regelmäßige Überprüfung und Wiederherstellung der Stationen
@ -20,21 +20,21 @@ CreateThread(function()
end)
function InitializeTaxiStations()
print("^2[TAXI STATIONS DEBUG]^7 InitializeTaxiStations started")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 InitializeTaxiStations started")
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
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
CleanupExistingStations()
-- Dann neue erstellen
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
local blip = AddBlipForCoord(station.blipCoords.x, station.blipCoords.y, station.blipCoords.z)
@ -46,7 +46,7 @@ function InitializeTaxiStations()
AddTextComponentString(station.name)
EndTextCommandSetBlipName(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
stationVehicles[stationId] = {}
@ -56,17 +56,17 @@ function InitializeTaxiStations()
for vehicleId, vehicleData in pairs(station.vehicles) do
-- Kleine Verzögerung zwischen jedem Fahrzeug
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)
end
end)
end
print("^2[TAXI STATIONS DEBUG]^7 All stations initialization started")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 All stations initialization started")
end
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
for stationId, vehicles in pairs(stationVehicles) do
@ -90,17 +90,17 @@ function CleanupExistingStations()
stationVehicles = {}
stationBlips = {}
print("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
end
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
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] and
stationVehicles[stationId][vehicleId].entity and
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)
DeleteEntity(stationVehicles[stationId][vehicleId].entity)
end
@ -112,7 +112,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
local vehCoords = GetEntityCoords(vehicle)
if #(vector3(vehicleData.coords.x, vehicleData.coords.y, vehicleData.coords.z) - vehCoords) < 3.0 then
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
SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -123,17 +123,17 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
CreateThread(function()
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)
local timeout = GetGameTimer() + 10000
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)
end
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
SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -152,7 +152,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
)
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
SetTimeout(30000, function()
SpawnStationVehicle(stationId, vehicleId, vehicleData)
@ -160,7 +160,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
return
end
print("^2[TAXI STATIONS DEBUG]^7 Vehicle created: " .. vehicle)
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle created: " .. vehicle)
-- Fahrzeug konfigurieren
SetEntityAsMissionEntity(vehicle, true, true)
@ -187,7 +187,7 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
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
exports['qb-target']:AddTargetEntity(vehicle, {
@ -204,14 +204,14 @@ function SpawnStationVehicle(stationId, vehicleId, vehicleData)
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)
end)
end
function CheckAndRestoreStationVehicles()
print("^2[TAXI STATIONS DEBUG]^7 Checking station vehicles...")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Checking station vehicles...")
local restoredCount = 0
@ -225,22 +225,22 @@ function CheckAndRestoreStationVehicles()
-- Prüfen ob das Fahrzeug existiert
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
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
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
elseif stationVehicles[stationId][vehicleId].occupied then
-- 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
end
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)
restoredCount = restoredCount + 1
@ -251,9 +251,9 @@ function CheckAndRestoreStationVehicles()
end
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
print("^2[TAXI STATIONS DEBUG]^7 All station vehicles are present")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 All station vehicles are present")
end
end
@ -261,7 +261,7 @@ end
function InitializeTaxiDriverAI(driver, vehicle)
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
local driverData = {
@ -344,14 +344,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Gerade an Ampel angekommen
driverData.state.isWaitingAtTrafficLight = true
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
-- Immer noch an Ampel
local waitTime = currentTime - driverData.state.trafficLightWaitStart
-- Wenn zu lange an Ampel, versuche weiterzufahren (Ampel könnte hängen)
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
TaskVehicleTempAction(driver, vehicle, 1, 2000) -- Forward
Wait(2000)
@ -362,7 +362,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then
-- Ampel verlassen
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
-- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung)
@ -371,14 +371,14 @@ function InitializeTaxiDriverAI(driver, vehicle)
-- Nur alle 5 Zähler-Erhöhungen loggen
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
-- Wenn lange genug steckengeblieben und genug Zeit seit letztem Versuch
if driverData.state.stuckCounter >= driverData.settings.maxStuckCounter and
(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.currentBehavior = "recovery"
@ -401,7 +401,7 @@ function InitializeTaxiDriverAI(driver, vehicle)
if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and
(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
-- Route neu berechnen
@ -449,17 +449,17 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
if backwardClear then
-- 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
Wait(2000)
if forwardClear then
-- 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)
else
-- 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
Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse
@ -470,13 +470,13 @@ function TaxiDriverIntelligentRecovery(driver, vehicle)
end
elseif forwardClear then
-- 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
Wait(2000)
TaxiDriverContinueRoute(driver, vehicle)
else
-- 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
Wait(1000)
TaskVehicleTempAction(driver, vehicle, 8, 800) -- Reverse
@ -499,7 +499,7 @@ function TaxiDriverRecalculateRoute(driver, vehicle)
if destination then
-- 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
TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop
@ -602,14 +602,14 @@ end
-- Event für Einsteigen in Station-Taxi
RegisterNetEvent('taxi:enterStationVehicle', function(data)
print("^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 Player trying to enter station vehicle")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Data: " .. json.encode(data))
local stationId = data.stationId
local vehicleId = data.vehicleId
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({
title = 'Taxi Service',
description = 'Dieses Taxi ist nicht verfügbar',
@ -621,7 +621,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
local vehicleInfo = stationVehicles[stationId][vehicleId]
if vehicleInfo.occupied then
print("^1[TAXI STATIONS DEBUG]^7 Vehicle already occupied")
DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle already occupied")
lib.notify({
title = 'Taxi Service',
description = 'Dieses Taxi ist bereits besetzt',
@ -630,7 +630,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
return
end
print("^2[TAXI STATIONS DEBUG]^7 Entering vehicle...")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Entering vehicle...")
-- Spieler ins Fahrzeug setzen
local playerPed = PlayerPedId()
@ -639,7 +639,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Türen entsperren
SetVehicleDoorsLocked(vehicle, 1)
-- 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...', {
position = "top-center",
icon = 'taxi',
@ -669,7 +669,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
local driverHash = nil
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)
-- Text während Model-Loading aktualisieren
@ -690,13 +690,13 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do
attempts = attempts + 1
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
Wait(100)
end
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
lib.showTextUI('🚕 Erstelle Fahrer...', {
@ -712,14 +712,14 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false)
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
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)
end
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)
end
@ -728,7 +728,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Fallback: Notfall-Fahrer erstellen
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...', {
position = "top-center",
@ -758,7 +758,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
if HasModelLoaded(hash) then
driver = CreatePedInsideVehicle(vehicle, 26, hash, -1, true, false)
if DoesEntityExist(driver) then
print("^2[TAXI STATIONS DEBUG]^7 Emergency driver created")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Emergency driver created")
driverHash = hash
break
end
@ -771,7 +771,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren
if not driver or not DoesEntityExist(driver) then
print("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver")
DebugPrint("^1[TAXI STATIONS DEBUG]^7 Could not create any driver, continuing without driver")
lib.showTextUI('❌ Kein Fahrer verfügbar - Du kannst selbst fahren', {
position = "top-center",
@ -849,11 +849,11 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Ersten verfügbaren Hintersitz wählen
if #availableSeats > 0 then
seatIndex = availableSeats[1]
print("^2[TAXI STATIONS DEBUG]^7 Using rear seat: " .. seatIndex)
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Using rear seat: " .. seatIndex)
else
-- Fallback: Beifahrersitz
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
-- Spieler in den gewählten Sitz einsteigen lassen
@ -884,14 +884,14 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
-- Info-Text verstecken
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
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
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
-- Spieler zum nächsten verfügbaren Sitz bewegen
@ -916,7 +916,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
end
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
lib.hideTextUI()
@ -938,7 +938,7 @@ RegisterNetEvent('taxi:enterStationVehicle', function(data)
end)
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 = {}
@ -1020,7 +1020,7 @@ function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm)
end
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()
@ -1040,7 +1040,7 @@ function SelfDriveStationTaxi(stationId, vehicleId, vehicle)
-- Prüfen ob Spieler noch im Fahrzeug ist
if not IsPedInVehicle(playerPed, vehicle, false) then
print("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi")
-- Nach 30 Sekunden Taxi zurück zur Station
SetTimeout(30000, function()
@ -1055,7 +1055,7 @@ function SelfDriveStationTaxi(stationId, vehicleId, vehicle)
end
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 = {}
@ -1095,7 +1095,7 @@ function OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePe
end
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
if not driver or not DoesEntityExist(driver) then
@ -1179,7 +1179,7 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
-- Angekommen
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({
title = 'Taxi Service',
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
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({
title = 'Taxi Service',
description = 'Die Fahrt dauert zu lange. Wir sind fast da!',
@ -1254,7 +1254,7 @@ function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination
end
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()
TaskLeaveVehicle(playerPed, vehicle, 0)
@ -1272,26 +1272,26 @@ function ExitStationTaxi(stationId, vehicleId, vehicle, driver)
end
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
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
end
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
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")
DebugPrint("^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")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station")
SpawnStationVehicle(stationId, vehicleId, vehicleData)
end
end)
@ -1300,7 +1300,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
-- Wenn Fahrer existiert, Taxi zur Station zurückfahren lassen
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
local stationCoords = Config.TaxiStations[stationId].coords
@ -1317,13 +1317,13 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
-- Fahrer löschen
if driver and DoesEntityExist(driver) then
DeleteEntity(driver)
print("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver deleted")
end
-- Fahrzeug löschen
if DoesEntityExist(vehicle) then
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
-- Fahrzeug als nicht besetzt markieren
@ -1332,11 +1332,11 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
stationVehicles[stationId][vehicleId].entity = nil
-- 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()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
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)
end
end)
@ -1347,7 +1347,7 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
if DoesEntityExist(vehicle) then
exports['qb-target']:RemoveTargetEntity(vehicle)
DeleteEntity(vehicle)
print("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted")
end
-- Fahrzeug als nicht besetzt markieren
@ -1356,11 +1356,11 @@ function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver)
stationVehicles[stationId][vehicleId].entity = nil
-- 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()
if stationVehicles[stationId] and stationVehicles[stationId][vehicleId] then
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)
end
end)
@ -1406,7 +1406,7 @@ end)
-- Event für Admin Respawn
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
for stationId, vehicles in pairs(stationVehicles) do
@ -1505,7 +1505,7 @@ end)
-- Funktion zum Beenden der Stations-Taxi Fahrt
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
return
@ -1544,7 +1544,7 @@ end
-- Cleanup beim Resource Stop
AddEventHandler('onResourceStop', function(resourceName)
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
lib.hideTextUI()
@ -1567,10 +1567,21 @@ AddEventHandler('onResourceStop', function(resourceName)
RemoveBlip(blip)
end
print("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed")
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.Debug = false -- Set to true to enable debug prints, false to disable
-- Taxi Fahrzeuge und Preise
Config.TaxiVehicles = {
{