diff --git a/resources/[carscripts]/nordi_taxi/client/main.lua b/resources/[carscripts]/nordi_taxi/client/main.lua new file mode 100644 index 000000000..be3c0ad4c --- /dev/null +++ b/resources/[carscripts]/nordi_taxi/client/main.lua @@ -0,0 +1,1595 @@ + +local currentTaxi = nil +local currentDriver = nil +local taxiBlip = nil +local mapBlip = nil +local destinationBlip = nil +local taxiMeter = { + isRunning = false, + startCoords = nil, + currentFare = 0, + pricePerKm = 0 +} + + +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 + +local QBCore = exports['qb-core']:GetCoreObject() +local currentTaxi = nil + +DebugPrint("^2[TAXI DEBUG]^7 Main script loaded") + +-- Taxi rufen Command +RegisterCommand('taxi', function() + DebugPrint("^2[TAXI DEBUG]^7 Taxi command executed") + + if currentTaxi and DoesEntityExist(currentTaxi) then + DebugPrint("^1[TAXI DEBUG]^7 Taxi already exists") + lib.notify({ + title = 'Taxi Service', + description = 'Du hast bereits ein Taxi gerufen', + type = 'error' + }) + return + end + + CallTaxi() +end) + +function CallTaxi() + DebugPrint("^2[TAXI DEBUG]^7 CallTaxi function started") + + lib.notify({ + title = 'Taxi Service', + description = 'Taxi wird gerufen...', + type = 'info' + }) + + CreateThread(function() + local playerPed = PlayerPedId() + local playerCoords = GetEntityCoords(playerPed) + + DebugPrint("^2[TAXI DEBUG]^7 Player coords: " .. tostring(playerCoords)) + + -- Verbesserte Spawn-Position für Taxi finden + local spawnCoords = GetImprovedTaxiSpawnPosition(playerCoords) + if not spawnCoords then + DebugPrint("^1[TAXI DEBUG]^7 No spawn position found") + lib.notify({ + title = 'Taxi Service', + description = 'Kein geeigneter Spawn-Punkt gefunden', + type = 'error' + }) + return + end + + 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 + DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn taxi") + lib.notify({ + title = 'Taxi Service', + description = 'Taxi konnte nicht gespawnt werden', + type = 'error' + }) + return + end + + DebugPrint("^2[TAXI DEBUG]^7 Taxi spawned: " .. taxi) + currentTaxi = taxi + + -- Fahrer spawnen + local driver = SpawnTaxiDriver(taxi) + if driver then + currentDriver = driver + DebugPrint("^2[TAXI DEBUG]^7 Driver spawned: " .. driver) + + -- Verbesserte Navigation zum Spieler + NavigateToPlayer(driver, taxi, playerCoords) + + -- Blip für Taxi erstellen (Entity-Blip) + CreateTaxiBlips(taxi) + + -- Überwachung der Ankunft + MonitorTaxiArrival(taxi, driver, playerCoords) + + lib.notify({ + title = 'Taxi Service', + description = 'Taxi ist unterwegs zu dir! Verfolge es auf der Karte.', + type = 'success' + }) + else + DebugPrint("^1[TAXI DEBUG]^7 Failed to spawn driver") + lib.notify({ + title = 'Taxi Service', + description = 'Taxi ohne Fahrer gespawnt - Du kannst es selbst fahren', + type = 'warning' + }) + end + end) +end + +function GetImprovedTaxiSpawnPosition(playerCoords) + DebugPrint("^2[TAXI DEBUG]^7 Finding improved spawn position...") + + -- Minimale und maximale Entfernung zum Spieler + local minAcceptableDistance = 50.0 -- Mindestens 50 Meter entfernt + local maxAcceptableDistance = 150.0 -- Maximal 150 Meter entfernt + local bestPosition = nil + local bestDistance = 999999.0 + + -- Versuche zuerst einen Straßenknotenpunkt zu finden + local roadPosition = nil + local foundNode = false + local nodePos = vector3(0.0, 0.0, 0.0) + + -- Versuche einen Straßenknotenpunkt in optimaler Entfernung zu finden + -- Suche in einem größeren Radius, um mehr Optionen zu haben + foundNode, nodePos = GetClosestVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0) + + if foundNode then + local nodeDistance = #(playerCoords - nodePos) + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then + roadPosition = nodePos + 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 + if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then + bestDistance = nodeDistance + bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} + end + end + end + + -- Versuche mehrere Knotenpunkte in verschiedenen Richtungen zu finden + for i = 1, 8 do + local angle = (i - 1) * 45.0 -- 8 Richtungen (0, 45, 90, 135, 180, 225, 270, 315 Grad) + local searchDistance = (minAcceptableDistance + maxAcceptableDistance) / 2 + local searchX = playerCoords.x + math.cos(math.rad(angle)) * searchDistance + local searchY = playerCoords.y + math.sin(math.rad(angle)) * searchDistance + + foundNode, nodePos = GetClosestVehicleNodeWithHeading(searchX, searchY, playerCoords.z, 1, 3.0, 0) + + if foundNode then + local nodeDistance = #(playerCoords - nodePos) + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then + 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 + if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then + bestDistance = nodeDistance + bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} + end + end + end + end + + -- Versuche einen weiteren Knotenpunkt mit größerem Radius + foundNode, nodePos = GetClosestMajorVehicleNode(playerCoords.x, playerCoords.y, playerCoords.z, 100.0, 0) + + if foundNode then + local nodeDistance = #(playerCoords - nodePos) + if nodeDistance >= minAcceptableDistance and nodeDistance <= maxAcceptableDistance then + roadPosition = nodePos + 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 + if nodeDistance < bestDistance and nodeDistance >= minAcceptableDistance then + bestDistance = nodeDistance + bestPosition = {x = nodePos.x, y = nodePos.y, z = nodePos.z, w = 0.0} + end + end + end + + -- Fallback auf Config-Positionen + if Config.MobileTaxiSpawns and #Config.MobileTaxiSpawns > 0 then + -- Alle Spawn-Positionen nach Entfernung sortieren + local sortedSpawns = {} + for i, spawnPos in ipairs(Config.MobileTaxiSpawns) do + local distance = #(playerCoords - vector3(spawnPos.x, spawnPos.y, spawnPos.z)) + if distance >= minAcceptableDistance then + table.insert(sortedSpawns, { + coords = spawnPos, + distance = distance + }) + end + end + + -- Nach Entfernung sortieren (nächste zuerst, aber mindestens minAcceptableDistance entfernt) + table.sort(sortedSpawns, function(a, b) + return a.distance < b.distance + end) + + -- Prüfen ob die nächsten Positionen frei und nah genug sind + for i, spawn in ipairs(sortedSpawns) do + local spawnCoords = spawn.coords + + -- Wenn Position zu weit weg ist, überspringen + if spawn.distance > maxAcceptableDistance then + -- Speichern für später, falls wir nichts Besseres finden + if spawn.distance < bestDistance then + bestDistance = spawn.distance + bestPosition = spawnCoords + end + goto continue + end + + -- Prüfen ob Position frei ist + local clearArea = true + local vehicles = GetGamePool('CVehicle') + + -- Prüfen ob andere Fahrzeuge in der Nähe sind + for _, vehicle in ipairs(vehicles) do + local vehCoords = GetEntityCoords(vehicle) + if #(vector3(spawnCoords.x, spawnCoords.y, spawnCoords.z) - vehCoords) < 5.0 then + clearArea = false + break + end + end + + -- Wenn Position frei ist, verwenden + if clearArea then + 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 + + ::continue:: + end + end + + -- 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 + 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 + 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 + -- Zufällige Position im Umkreis, aber mindestens minAcceptableDistance entfernt + local angle = math.random() * 2 * math.pi + local distance = math.random(minAcceptableDistance, maxAcceptableDistance) + local x = playerCoords.x + math.cos(angle) * distance + local y = playerCoords.y + math.sin(angle) * distance + local z = playerCoords.z + + -- Versuche eine gültige Z-Koordinate zu bekommen + local success, groundZ = GetGroundZFor_3dCoord(x, y, z, true) + if success then + -- Prüfe ob die Position auf einer Straße ist + local isOnRoad = IsPointOnRoad(x, y, groundZ) + + if isOnRoad then + 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 + end + + -- Absolute Notfall-Fallback: Einfach irgendwo in der Nähe, aber mindestens minAcceptableDistance entfernt + local angle = math.random() * 2 * math.pi + local distance = math.random(minAcceptableDistance, maxAcceptableDistance) + local x = playerCoords.x + math.cos(angle) * distance + local y = playerCoords.y + math.sin(angle) * distance + local z = playerCoords.z + + -- Versuche eine gültige Z-Koordinate zu bekommen + local success, groundZ = GetGroundZFor_3dCoord(x, y, z, true) + if success then + z = groundZ + end + + 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) + 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 + if Config.TaxiVehicles and #Config.TaxiVehicles > 0 then + -- Zufälliges Taxi-Model aus Config wählen + local randomIndex = math.random(1, #Config.TaxiVehicles) + taxiModel = GetHashKey(Config.TaxiVehicles[randomIndex].model) + else + taxiModel = GetHashKey("taxi") -- Fallback + end + + DebugPrint("^2[TAXI DEBUG]^7 Taxi model hash: " .. taxiModel) + + -- Model laden mit Timeout + RequestModel(taxiModel) + local modelLoaded = false + local timeout = GetGameTimer() + 10000 + + while not modelLoaded and GetGameTimer() < timeout do + modelLoaded = HasModelLoaded(taxiModel) + if not modelLoaded then + DebugPrint("^3[TAXI DEBUG]^7 Waiting for taxi model to load...") + Wait(100) + end + end + + if not modelLoaded then + DebugPrint("^1[TAXI DEBUG]^7 Failed to load taxi model! Trying default model.") + SetModelAsNoLongerNeeded(taxiModel) + + -- Versuche Standard-Taxi als Fallback + taxiModel = GetHashKey("taxi") + RequestModel(taxiModel) + + timeout = GetGameTimer() + 5000 + while not HasModelLoaded(taxiModel) and GetGameTimer() < timeout do + Wait(100) + end + + if not HasModelLoaded(taxiModel) then + DebugPrint("^1[TAXI DEBUG]^7 Failed to load default taxi model!") + return nil + end + end + + -- Fahrzeug erstellen + local taxi = CreateVehicle(taxiModel, coords.x, coords.y, coords.z, coords.w or 0.0, true, false) + + if not DoesEntityExist(taxi) then + DebugPrint("^1[TAXI DEBUG]^7 Failed to create taxi vehicle!") + return nil + end + + DebugPrint("^2[TAXI DEBUG]^7 Taxi created successfully: " .. taxi) + + -- Fahrzeug konfigurieren + SetEntityAsMissionEntity(taxi, true, true) + SetVehicleOnGroundProperly(taxi) + SetVehicleEngineOn(taxi, true, true, false) + SetVehicleDoorsLocked(taxi, 2) -- Locked initially + + -- Verbesserte Persistenz + SetEntityInvincible(taxi, true) + SetVehicleCanBeVisiblyDamaged(taxi, false) + SetEntityProofs(taxi, true, true, true, true, true, true, true, true) + SetVehicleExplodesOnHighExplosionDamage(taxi, false) + SetVehicleHasBeenOwnedByPlayer(taxi, true) + SetVehicleIsConsideredByPlayer(taxi, true) + + -- Taxi-Livery setzen falls verfügbar + local liveryCount = GetVehicleLiveryCount(taxi) + if liveryCount > 0 then + SetVehicleLivery(taxi, 0) -- Erste Livery verwenden + DebugPrint("^2[TAXI DEBUG]^7 Taxi livery set") + end + + -- Fahrzeug-Extras aktivieren falls vorhanden + for i = 1, 14 do + if DoesExtraExist(taxi, i) then + SetVehicleExtra(taxi, i, false) -- Extra aktivieren + end + end + + -- Fahrzeug-Farbe setzen (Gelb für Taxis) + SetVehicleColours(taxi, 88, 88) -- Taxi Yellow + + SetModelAsNoLongerNeeded(taxiModel) + return taxi +end + +-- Fortgeschrittenes Taxi-Fahrer-Verhaltenssystem +function InitializeTaxiDriverAI(driver, vehicle) + if not driver or not DoesEntityExist(driver) then return end + + DebugPrint("^2[TAXI DEBUG]^7 Initializing advanced taxi driver AI") + + -- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen + local driverData = { + personality = { + patience = math.random(7, 10) / 10, -- 0.7-1.0: Wie geduldig ist der Fahrer + caution = math.random(6, 10) / 10, -- 0.6-1.0: Wie vorsichtig fährt er + speedPreference = math.random(15, 60), -- 15-25: Bevorzugte Geschwindigkeit + trafficRuleCompliance = math.random(8, 10)/10 -- 0.8-1.0: Wie genau hält er Verkehrsregeln ein + }, + state = { + stuckCounter = 0, + lastStuckRecovery = 0, + lastRouteRecalculation = 0, + currentBehavior = "normal", -- normal, cautious, stuck, recovery + lastSpeedCheck = 0, + speedHistory = {}, + lastPositions = {}, + trafficLightWaitStart = 0, + isWaitingAtTrafficLight = false + }, + settings = { + maxStuckCounter = math.random(15, 25), -- Wie lange warten bis Befreiungsversuch + stuckThreshold = 0.5, -- Bewegungsschwelle für Steckenbleiben + checkInterval = 2000, -- Überprüfungsintervall in ms + positionHistorySize = 5, -- Anzahl der zu speichernden Positionen + minRecoveryInterval = 25000, -- Min. Zeit zwischen Befreiungsversuchen + minRouteRecalcInterval = 30000, -- Min. Zeit zwischen Routenneuberechnungen + trafficLightMaxWait = 45000 -- Max. Wartezeit an Ampeln + } + } + + -- Fahrer-Verhalten basierend auf Persönlichkeit einstellen + SetDriverAbility(driver, driverData.personality.caution) + SetDriverAggressiveness(driver, 1.0 - driverData.personality.caution) + + -- Fahrer-Daten im Entity speichern + Entity(vehicle).state.driverData = driverData + + -- Fahrer-Verhalten-Thread starten + CreateThread(function() + local lastPos = GetEntityCoords(vehicle) + local lastCheck = GetGameTimer() + + while DoesEntityExist(vehicle) and DoesEntityExist(driver) do + Wait(driverData.settings.checkInterval) + + local currentTime = GetGameTimer() + local timeDelta = currentTime - lastCheck + lastCheck = currentTime + + -- Aktuelle Position und Geschwindigkeit + local currentPos = GetEntityCoords(vehicle) + local speed = GetEntitySpeed(vehicle) + local distanceMoved = #(lastPos - currentPos) + + -- Position für Historie speichern + table.insert(driverData.state.lastPositions, 1, currentPos) + if #driverData.state.lastPositions > driverData.settings.positionHistorySize then + table.remove(driverData.state.lastPositions) + end + + -- Geschwindigkeit für Historie speichern + table.insert(driverData.state.speedHistory, 1, speed) + if #driverData.state.speedHistory > 5 then + table.remove(driverData.state.speedHistory) + end + + -- Durchschnittsgeschwindigkeit berechnen + local avgSpeed = 0 + for _, s in ipairs(driverData.state.speedHistory) do + avgSpeed = avgSpeed + s + end + avgSpeed = avgSpeed / #driverData.state.speedHistory + + -- Ampel-Erkennung + local isAtTrafficLight = IsVehicleStoppedAtTrafficLights(vehicle) + + -- Ampel-Wartezustand aktualisieren + if isAtTrafficLight and not driverData.state.isWaitingAtTrafficLight then + -- Gerade an Ampel angekommen + driverData.state.isWaitingAtTrafficLight = true + driverData.state.trafficLightWaitStart = currentTime + 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 + 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) + -- Dann normale Fahrt fortsetzen + TaxiDriverContinueRoute(driver, vehicle) + driverData.state.isWaitingAtTrafficLight = false + end + elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then + -- Ampel verlassen + driverData.state.isWaitingAtTrafficLight = false + DebugPrint("^2[TAXI DEBUG]^7 Taxi continued after traffic light") + end + + -- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung) + if not isAtTrafficLight and distanceMoved < driverData.settings.stuckThreshold and speed < 0.5 then + driverData.state.stuckCounter = driverData.state.stuckCounter + 1 + + -- Nur alle 5 Zähler-Erhöhungen loggen + if driverData.state.stuckCounter % 5 == 0 then + 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 + + DebugPrint("^1[TAXI DEBUG]^7 Taxi is stuck, attempting intelligent recovery") + driverData.state.lastStuckRecovery = currentTime + driverData.state.currentBehavior = "recovery" + + -- Intelligente Befreiung basierend auf Umgebung + TaxiDriverIntelligentRecovery(driver, vehicle) + + -- Steckenbleiben-Zähler teilweise zurücksetzen + driverData.state.stuckCounter = math.floor(driverData.settings.maxStuckCounter * 0.4) + end + else + -- Wenn sich das Fahrzeug bewegt oder an einer Ampel steht + if isAtTrafficLight then + -- An Ampel: Zähler langsamer reduzieren + driverData.state.stuckCounter = math.max(0, driverData.state.stuckCounter - 0.2) + else + -- In Bewegung: Zähler reduzieren + driverData.state.stuckCounter = math.max(0, driverData.state.stuckCounter - 1) + + -- Wenn Fahrzeug sich bewegt, aber sehr langsam über längere Zeit + if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and + (currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then + + DebugPrint("^3[TAXI DEBUG]^7 Taxi moving too slow, recalculating route") + driverData.state.lastRouteRecalculation = currentTime + + -- Route neu berechnen + TaxiDriverRecalculateRoute(driver, vehicle) + end + end + end + + -- Verhalten basierend auf Umgebung anpassen + TaxiDriverAdaptBehavior(driver, vehicle, driverData) + + lastPos = currentPos + end + end) + + return driverData +end + +-- Intelligente Befreiung bei Steckenbleiben +function TaxiDriverIntelligentRecovery(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Position und Umgebung analysieren + local vehicleCoords = GetEntityCoords(vehicle) + local vehicleHeading = GetEntityHeading(vehicle) + local vehicleForwardVector = GetEntityForwardVector(vehicle) + + -- Prüfen ob Hindernisse vorne, hinten, links, rechts + local forwardClear = not IsPositionOccupied( + vehicleCoords.x + vehicleForwardVector.x * 4.0, + vehicleCoords.y + vehicleForwardVector.y * 4.0, + vehicleCoords.z, + 1.0, false, true, false, false, false, 0, false + ) + + local backwardClear = not IsPositionOccupied( + vehicleCoords.x - vehicleForwardVector.x * 4.0, + vehicleCoords.y - vehicleForwardVector.y * 4.0, + vehicleCoords.z, + 1.0, false, true, false, false, false, 0, false + ) + + -- Befreiungsstrategie basierend auf Umgebung + ClearPedTasks(driver) + + if backwardClear then + -- Rückwärts fahren wenn hinten frei + 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 + DebugPrint("^3[TAXI DEBUG]^7 Recovery: Path clear, continuing") + TaxiDriverContinueRoute(driver, vehicle) + else + -- Sonst versuchen zu wenden + DebugPrint("^3[TAXI DEBUG]^7 Recovery: Turning around") + TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 6, 2000) -- Turn right + Wait(1000) + TaxiDriverContinueRoute(driver, vehicle) + end + elseif forwardClear then + -- Wenn nur vorne frei, vorwärts fahren + 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 + 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 + Wait(800) + TaskVehicleTempAction(driver, vehicle, 6, 1000) -- Turn right + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 1, 800) -- Forward + Wait(800) + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Route neu berechnen +function TaxiDriverRecalculateRoute(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Zielposition aus dem Fahrzeug-State ermitteln + local destination = Entity(vehicle).state.currentDestination + + if destination then + -- Versuche einen alternativen Weg zu finden + DebugPrint("^3[TAXI DEBUG]^7 Recalculating route to destination") + + -- Kurz anhalten + TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop + Wait(1000) + + -- Neue Route mit leicht geändertem Fahrstil + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + else + -- Wenn kein Ziel bekannt, einfach weiterfahren + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Normale Fahrt fortsetzen +function TaxiDriverContinueRoute(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Ziel aus dem Fahrzeug-State holen + local destination = Entity(vehicle).state.currentDestination + + if destination then + -- Zum Ziel fahren mit angepasster Fahrweise + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + else + -- Wenn kein Ziel bekannt, einfach geradeaus fahren + TaskVehicleDriveWander(driver, vehicle, 15.0, 786603) + end +end + +-- Fahrverhalten an Umgebung anpassen +function TaxiDriverAdaptBehavior(driver, vehicle, driverData) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Geschwindigkeit und Position + local speed = GetEntitySpeed(vehicle) + local vehicleCoords = GetEntityCoords(vehicle) + + -- Verkehrsdichte in der Umgebung prüfen + local vehiclesNearby = 0 + local vehicles = GetGamePool('CVehicle') + for _, otherVehicle in ipairs(vehicles) do + if otherVehicle ~= vehicle then + local otherCoords = GetEntityCoords(otherVehicle) + local distance = #(vehicleCoords - otherCoords) + if distance < 15.0 then + vehiclesNearby = vehiclesNearby + 1 + end + end + end + + -- Verhalten basierend auf Verkehrsdichte anpassen + local targetSpeed = driverData.personality.speedPreference + + if vehiclesNearby > 5 then + -- Viel Verkehr: langsamer und vorsichtiger + targetSpeed = targetSpeed * 0.7 + SetDriverAggressiveness(driver, 0.0) + elseif vehiclesNearby > 2 then + -- Moderater Verkehr: etwas langsamer + targetSpeed = targetSpeed * 0.85 + SetDriverAggressiveness(driver, 0.1) + else + -- Wenig Verkehr: normale Geschwindigkeit + SetDriverAggressiveness(driver, 0.2) + end + + -- Geschwindigkeit anpassen wenn nötig + if math.abs(speed - targetSpeed) > 5.0 then + if speed < targetSpeed then + -- Beschleunigen + TaskVehicleTempAction(driver, vehicle, 23, 500) -- Gentle forward + else + -- Abbremsen + TaskVehicleTempAction(driver, vehicle, 24, 500) -- Gentle brake + end + + -- Nach der Anpassung normale Fahrt fortsetzen + Wait(500) + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Hilfsfunktion zur Normalisierung eines Vektors +function norm(vector) + local length = math.sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z) + if length == 0 then + return vector3(0.0, 0.0, 0.0) + end + return vector3(vector.x / length, vector.y / length, vector.z / length) +end + +function SpawnTaxiDriver(vehicle) + DebugPrint("^2[TAXI DEBUG]^7 Spawning taxi driver...") + + -- Bessere Fahrer-Models mit Fallbacks + local driverModels = { + "A_C_Chimp", -- Taxi Driver (erste Wahl) + "a_m_y_business_01", -- Business Male + "a_m_m_business_01", -- Business Male 2 + "mp_m_freemode_01", -- Male Freemode + "a_m_y_downtown_01", -- Downtown Male + "a_m_m_farmer_01", -- Farmer + "a_m_y_hipster_01", -- Hipster + "a_m_y_beach_01" -- Beach Guy + } + + local driver = nil + local driverHash = nil + + -- Versuche verschiedene Models + for i, modelName in ipairs(driverModels) do + DebugPrint("^2[TAXI DEBUG]^7 Trying driver model " .. i .. ": " .. modelName) + driverHash = GetHashKey(modelName) + + -- Model laden + RequestModel(driverHash) + local timeout = GetGameTimer() + 8000 -- Längere Wartezeit + local attempts = 0 + + while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do + attempts = attempts + 1 + if attempts % 10 == 0 then -- Alle 1 Sekunde loggen + DebugPrint("^3[TAXI DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")") + end + Wait(100) + end + + if HasModelLoaded(driverHash) then + 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 + DebugPrint("^2[TAXI DEBUG]^7 Driver created successfully with model: " .. modelName .. " (ID: " .. driver .. ")") + break + else + DebugPrint("^1[TAXI DEBUG]^7 Failed to create driver with loaded model: " .. modelName) + SetModelAsNoLongerNeeded(driverHash) + end + else + 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 + DebugPrint("^1[TAXI DEBUG]^7 Could not create any driver! Continuing without driver...") + return nil + end + + -- Fahrer konfigurieren + DebugPrint("^2[TAXI DEBUG]^7 Configuring driver...") + + SetEntityAsMissionEntity(driver, true, true) + SetBlockingOfNonTemporaryEvents(driver, true) + SetPedFleeAttributes(driver, 0, 0) + SetPedCombatAttributes(driver, 17, 1) + SetPedSeeingRange(driver, 0.0) + SetPedHearingRange(driver, 0.0) + SetPedAlertness(driver, 0) + SetPedKeepTask(driver, true) + + -- Fortgeschrittene KI-ähnliche Fahrer-Logik initialisieren + local driverData = InitializeTaxiDriverAI(driver, vehicle) + + -- Zufälligen Fahrer-Namen generieren + local firstNames = {"Max", "Thomas", "Ali", "Mehmet", "Hans", "Peter", "Klaus", "Michael", "Stefan", "Frank"} + local lastNames = {"Müller", "Schmidt", "Schneider", "Fischer", "Weber", "Meyer", "Wagner", "Becker", "Schulz", "Hoffmann"} + local driverName = firstNames[math.random(#firstNames)] .. " " .. lastNames[math.random(#lastNames)] + + -- Fahrer-Name im Fahrzeug-State speichern + Entity(vehicle).state.driverName = driverName + + -- Fahrer-Outfit (nur wenn es ein anpassbarer Ped ist) + if driverHash == GetHashKey("mp_m_freemode_01") then + DebugPrint("^2[TAXI DEBUG]^7 Setting driver outfit...") + + -- Basis-Outfit für Taxi-Fahrer + SetPedComponentVariation(driver, 0, 0, 0, 0) -- Face + SetPedComponentVariation(driver, 2, 1, 0, 0) -- Hair + SetPedComponentVariation(driver, 8, 15, 0, 0) -- Undershirt + SetPedComponentVariation(driver, 11, 91, 0, 0) -- Jacket + SetPedComponentVariation(driver, 4, 10, 0, 0) -- Pants + SetPedComponentVariation(driver, 6, 10, 0, 0) -- Shoes + SetPedComponentVariation(driver, 1, 0, 0, 0) -- Mask + SetPedComponentVariation(driver, 3, 0, 0, 0) -- Arms + SetPedComponentVariation(driver, 5, 0, 0, 0) -- Bag + SetPedComponentVariation(driver, 7, 0, 0, 0) -- Tie + SetPedComponentVariation(driver, 9, 0, 0, 0) -- Body Armor + SetPedComponentVariation(driver, 10, 0, 0, 0) -- Decals + + -- Zufällige Gesichtsmerkmale + SetPedHeadBlendData(driver, math.random(0, 20), math.random(0, 20), 0, math.random(0, 20), math.random(0, 20), 0, 0.5, 0.5, 0.0, false) + end + + -- Model nicht mehr benötigt + if driverHash then + SetModelAsNoLongerNeeded(driverHash) + end + + DebugPrint("^2[TAXI DEBUG]^7 Driver spawn completed successfully") + return driver +end + +function CreateTaxiBlips(taxi) + -- Blip für Taxi erstellen (Entity-Blip) + taxiBlip = AddBlipForEntity(taxi) + SetBlipSprite(taxiBlip, 198) + SetBlipColour(taxiBlip, 5) + SetBlipScale(taxiBlip, 0.8) + SetBlipDisplay(taxiBlip, 2) -- Zeigt auf Minimap und großer Karte + SetBlipShowCone(taxiBlip, true) -- Zeigt Sichtkegel + SetBlipAsShortRange(taxiBlip, false) -- Immer sichtbar, egal wie weit entfernt + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Dein Taxi") + EndTextCommandSetBlipName(taxiBlip) + + -- Zusätzlicher Blip auf der Karte für bessere Sichtbarkeit + local taxiCoords = GetEntityCoords(taxi) + mapBlip = AddBlipForCoord(taxiCoords.x, taxiCoords.y, taxiCoords.z) + SetBlipSprite(mapBlip, 198) + SetBlipColour(mapBlip, 5) + SetBlipScale(mapBlip, 1.0) + SetBlipDisplay(mapBlip, 4) -- Nur auf großer Karte + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Dein Taxi") + EndTextCommandSetBlipName(mapBlip) + + -- Blip aktualisieren während Taxi unterwegs ist + CreateThread(function() + while DoesEntityExist(taxi) and mapBlip do + local taxiCoords = GetEntityCoords(taxi) + SetBlipCoords(mapBlip, taxiCoords.x, taxiCoords.y, taxiCoords.z) + Wait(1000) + end + + -- Blip entfernen wenn Thread beendet + if mapBlip then + RemoveBlip(mapBlip) + mapBlip = nil + end + end) +end + +function NavigateToPlayer(driver, taxi, playerCoords) + DebugPrint("^2[TAXI DEBUG]^7 Navigating taxi to player...") + + -- Ziel im Fahrzeug-State speichern für die KI-Logik + Entity(taxi).state.currentDestination = playerCoords + + -- Versuche einen guten Wegpunkt in der Nähe des Spielers zu finden + local success, nodePos = GetClosestVehicleNodeWithHeading(playerCoords.x, playerCoords.y, playerCoords.z, 1, 3.0, 0) + + if success then + 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 + 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) + DebugPrint("^2[TAXI DEBUG]^7 Monitoring taxi arrival...") + + local arrivalTimeout = GetGameTimer() + (120 * 1000) -- 2 minute timeout + + CreateThread(function() + while DoesEntityExist(taxi) and (not driver or DoesEntityExist(driver)) do + local taxiCoords = GetEntityCoords(taxi) + local currentPlayerCoords = GetEntityCoords(PlayerPedId()) + local distance = #(currentPlayerCoords - taxiCoords) + + -- Check if taxi is close to player + if distance < 15.0 then + DebugPrint("^2[TAXI DEBUG]^7 Taxi arrived!") + + -- Taxi stoppen + if driver and DoesEntityExist(driver) then + TaskVehicleTempAction(driver, taxi, 27, 3000) -- Brake + Wait(2000) + SetVehicleDoorsLocked(taxi, 1) -- Unlock doors + end + + lib.notify({ + title = 'Taxi Service', + description = 'Dein Taxi ist angekommen! Steige ein.', + type = 'success' + }) + + -- qb-target für Einsteigen hinzufügen + exports['qb-target']:AddTargetEntity(taxi, { + options = { + { + type = "client", + event = "taxi:enterTaxi", + icon = "fas fa-car-side", + label = "Ins Taxi einsteigen" + } + }, + distance = 3.0 + }) + + break + end + + -- Check for timeout + if GetGameTimer() > arrivalTimeout then + DebugPrint("^1[TAXI DEBUG]^7 Taxi arrival timed out!") + lib.notify({ + title = 'Taxi Service', + description = 'Dein Taxi steckt fest. Ein neues wird gerufen!', + type = 'warning' + }) + + -- Despawn current taxi and call a new one + DespawnTaxi() + Wait(1000) + CallTaxi() + break + end + + Wait(2000) + end + end) +end + +-- Event für Einsteigen ins Taxi +RegisterNetEvent('taxi:enterTaxi', function() + DebugPrint("^2[TAXI DEBUG]^7 Player entering taxi") + + if not currentTaxi or not DoesEntityExist(currentTaxi) then + DebugPrint("^1[TAXI DEBUG]^7 No taxi exists") + return + end + + local playerPed = PlayerPedId() + + -- Spieler hinten einsteigen lassen + local seatIndex = 1 -- Hinten links + if not IsVehicleSeatFree(currentTaxi, 1) then + seatIndex = 2 -- Hinten rechts + end + if not IsVehicleSeatFree(currentTaxi, seatIndex) then + seatIndex = 0 -- Beifahrer als Fallback + end + + TaskEnterVehicle(playerPed, currentTaxi, 10000, seatIndex, 1.0, 1, 0) + + -- Warten bis eingestiegen + CreateThread(function() + local timeout = GetGameTimer() + 10000 + local entered = false + + while GetGameTimer() < timeout and not entered do + if IsPedInVehicle(playerPed, currentTaxi, false) then + entered = true + DebugPrint("^2[TAXI DEBUG]^7 Player entered taxi successfully") + + -- qb-target entfernen + exports['qb-target']:RemoveTargetEntity(currentTaxi) + + lib.notify({ + title = 'Taxi Service', + description = 'Willkommen im Taxi! Wähle dein Ziel.', + type = 'success' + }) + + -- Ziel-Menu öffnen + Wait(1000) + OpenDestinationMenu() + end + Wait(100) + end + + if not entered then + DebugPrint("^1[TAXI DEBUG]^7 Player failed to enter taxi") + lib.notify({ + title = 'Taxi Service', + description = 'Einsteigen fehlgeschlagen', + type = 'error' + }) + end + end) +end) + +function OpenDestinationMenu() + DebugPrint("^2[TAXI DEBUG]^7 Opening destination menu") + + local options = {} + + -- Bekannte Ziele hinzufügen + for _, destination in pairs(Config.KnownDestinations) do + local distance = CalculateDistanceToCoords(destination.coords) / 1000 -- in km + local price = math.max(Config.MinFare, math.ceil(distance * Config.PricePerKm)) + + table.insert(options, { + title = destination.name, + description = 'Preis: $' .. price .. ' | Entfernung: ' .. math.ceil(distance * 100) / 100 .. 'km', + icon = 'map-marker', + onSelect = function() + StartTaxiRide(destination.coords, price) + end + }) + end + + -- Waypoint Option + table.insert(options, { + title = 'Zu meinem Waypoint', + description = 'Fahre zu deinem gesetzten Waypoint', + icon = 'location-dot', + onSelect = function() + local waypoint = GetFirstBlipInfoId(8) + if DoesBlipExist(waypoint) then + local coords = GetBlipInfoIdCoord(waypoint) + local distance = CalculateDistanceToCoords(coords) / 1000 + local price = math.max(Config.MinFare, math.ceil(distance * Config.PricePerKm)) + StartTaxiRide(coords, price) + else + lib.notify({ + title = 'Taxi Service', + description = 'Du hast keinen Waypoint gesetzt', + type = 'error' + }) + OpenDestinationMenu() + end + end + }) + + -- Selbst fahren Option (wenn kein Fahrer) + if not currentDriver or not DoesEntityExist(currentDriver) then + table.insert(options, { + title = '🚗 Selbst fahren', + description = 'Du fährst das Taxi selbst', + icon = 'car', + onSelect = function() + SelfDriveTaxi() + end + }) + end + + -- Aussteigen Option + table.insert(options, { + title = 'Aussteigen', + description = 'Das Taxi verlassen', + icon = 'door-open', + onSelect = function() + ExitTaxi() + end + }) + + lib.registerContext({ + id = 'taxi_destination_menu', + title = 'Taxi - Ziel wählen', + options = options + }) + + lib.showContext('taxi_destination_menu') +end + +function StartTaxiRide(destination, price) + 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 + DebugPrint("^1[TAXI DEBUG]^7 No taxi exists for ride") + return + end + + -- Wenn kein Fahrer, Spieler selbst fahren lassen + if not currentDriver or not DoesEntityExist(currentDriver) then + lib.notify({ + title = 'Taxi Service', + description = 'Kein Fahrer verfügbar. Du musst selbst fahren!', + type = 'warning' + }) + return + end + + lib.notify({ + title = 'Taxi Service', + description = 'Fahrt gestartet - Preis: $' .. price, + type = 'success' + }) + + -- Destination Blip erstellen + if destinationBlip then + RemoveBlip(destinationBlip) + end + + destinationBlip = AddBlipForCoord(destination.x, destination.y, destination.z) + SetBlipSprite(destinationBlip, 1) + SetBlipColour(destinationBlip, 2) + SetBlipScale(destinationBlip, 0.8) + SetBlipRoute(destinationBlip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Taxi Ziel") + EndTextCommandSetBlipName(destinationBlip) + + -- Taximeter starten + taxiMeter.isRunning = true + taxiMeter.startCoords = GetEntityCoords(currentTaxi) + taxiMeter.currentFare = 0 + taxiMeter.pricePerKm = Config.PricePerKm + + -- Ziel im Fahrzeug-State speichern für die KI-Logik + Entity(currentTaxi).state.currentDestination = destination + + -- Zum Ziel fahren mit verbesserter Navigation + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(currentDriver, currentTaxi, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + + -- Fahrer-Dialog anzeigen + local driverName = Entity(currentTaxi).state.driverName or "Taxi-Fahrer" + local dialogOptions = { + "Ich bringe dich sicher ans Ziel.", + "Schönes Wetter heute, oder?", + "Ich kenne eine Abkürzung.", + "Bist du aus der Gegend?", + "Ich fahre schon seit 15 Jahren Taxi.", + "Entspann dich und genieße die Fahrt." + } + + -- Zufälligen Dialog auswählen und anzeigen + Wait(3000) -- Kurz warten bevor der Fahrer spricht + lib.notify({ + title = driverName, + description = dialogOptions[math.random(#dialogOptions)], + type = 'info', + icon = 'comment', + position = 'top-center', + duration = 5000 + }) + + -- Fahrt überwachen + MonitorTaxiRide(destination, price) +end + +function MonitorTaxiRide(destination, price) + DebugPrint("^2[TAXI DEBUG]^7 Monitoring taxi ride...") + + local rideTimeout = GetGameTimer() + (10 * 60 * 1000) -- 10 Minuten Timeout + + CreateThread(function() + while DoesEntityExist(currentTaxi) and DoesEntityExist(currentDriver) do + local taxiCoords = GetEntityCoords(currentTaxi) + local distance = #(vector3(destination.x, destination.y, destination.z) - taxiCoords) + + -- Überprüfen ob wir angekommen sind + if distance < 10.0 then + -- Angekommen + TaskVehicleTempAction(currentDriver, currentTaxi, 27, 3000) + + DebugPrint("^2[TAXI DEBUG]^7 Arrived at destination") + lib.notify({ + title = 'Taxi Service', + description = 'Du bist angekommen! Preis: $' .. price, + type = 'success' + }) + + -- Bezahlung + TriggerServerEvent('taxi:payFare', price) + + -- Blips entfernen + if destinationBlip then + RemoveBlip(destinationBlip) + destinationBlip = nil + end + + -- Fahrer-Dialog anzeigen + local driverName = Entity(currentTaxi).state.driverName or "Taxi-Fahrer" + local arrivalDialogs = { + "Wir sind da! Das macht dann $" .. price .. ".", + "Angekommen! $" .. price .. " bitte.", + "Hier sind wir. $" .. price .. ", bargeldlos ist auch möglich.", + "Ziel erreicht! Das macht $" .. price .. "." + } + + lib.notify({ + title = driverName, + description = arrivalDialogs[math.random(#arrivalDialogs)], + type = 'info', + icon = 'comment', + position = 'top-center', + duration = 5000 + }) + + -- Nach 10 Sekunden Taxi despawnen + SetTimeout(10000, function() + DespawnTaxi() + end) + + break + end + + -- Überprüfen ob die Fahrt zu lange dauert + if GetGameTimer() > rideTimeout then + DebugPrint("^1[TAXI DEBUG]^7 Taxi ride timed out!") + + -- Berechne verbleibende Distanz + local taxiCoords = GetEntityCoords(currentTaxi) + local remainingDistance = #(vector3(destination.x, destination.y, destination.z) - taxiCoords) + + lib.notify({ + title = 'Taxi Service', + description = 'Die Fahrt dauert zu lange. Noch ' .. math.ceil(remainingDistance) .. 'm bis zum Ziel!', + type = 'warning' + }) + + -- Teleportiere Taxi näher ans Ziel (75% des Weges) + local direction = vector3( + destination.x - taxiCoords.x, + destination.y - taxiCoords.y, + destination.z - taxiCoords.z + ) + local normalizedDir = norm(direction) + local teleportDistance = remainingDistance * 0.75 + + local newPos = vector3( + taxiCoords.x + normalizedDir.x * teleportDistance, + taxiCoords.y + normalizedDir.y * teleportDistance, + taxiCoords.z + ) + + -- Finde gültige Z-Koordinate + local success, groundZ = GetGroundZFor_3dCoord(newPos.x, newPos.y, newPos.z, true) + if success then + newPos = vector3(newPos.x, newPos.y, groundZ) + end + + -- Teleportiere Taxi + SetEntityCoords(currentTaxi, newPos.x, newPos.y, newPos.z, false, false, false, false) + + -- Neues Timeout setzen (2 Minuten) + rideTimeout = GetGameTimer() + (2 * 60 * 1000) + end + + Wait(2000) + end + end) +end + +function SelfDriveTaxi() + DebugPrint("^2[TAXI DEBUG]^7 Player driving taxi themselves") + + if not currentTaxi or not DoesEntityExist(currentTaxi) then + return + end + + local playerPed = PlayerPedId() + + -- Fahrer entfernen falls vorhanden + if currentDriver and DoesEntityExist(currentDriver) then + DeleteEntity(currentDriver) + currentDriver = nil + end + + -- Spieler zum Fahrersitz bewegen + TaskShuffleToNextVehicleSeat(playerPed, currentTaxi) + + lib.notify({ + title = 'Taxi Service', + description = 'Du fährst das Taxi jetzt selbst. Nutze /stoptaxi um es zu beenden.', + type = 'info' + }) +end + +function ExitTaxi() + DebugPrint("^2[TAXI DEBUG]^7 Player exiting taxi") + + if not currentTaxi or not DoesEntityExist(currentTaxi) then + return + end + + local playerPed = PlayerPedId() + TaskLeaveVehicle(playerPed, currentTaxi, 0) + + lib.notify({ + title = 'Taxi Service', + description = 'Du bist ausgestiegen', + type = 'info' + }) + + -- Taxi nach 5 Sekunden despawnen + SetTimeout(5000, function() + DespawnTaxi() + end) +end + +function DespawnTaxi() + DebugPrint("^2[TAXI DEBUG]^7 Despawning taxi") + + if not currentTaxi or not DoesEntityExist(currentTaxi) then + return + end + + -- Taxi wegfahren lassen, wenn ein Fahrer existiert + if currentDriver and DoesEntityExist(currentDriver) then + DebugPrint("^2[TAXI DEBUG]^7 Making taxi drive away before despawn") + + -- Zufällige Position in der Nähe finden + local taxiCoords = GetEntityCoords(currentTaxi) + local angle = math.random() * 2 * math.pi + local distance = 150.0 + local driveToX = taxiCoords.x + math.cos(angle) * distance + local driveToY = taxiCoords.y + math.sin(angle) * distance + + -- Taxi wegfahren lassen + TaskVehicleDriveToCoordLongrange(currentDriver, currentTaxi, driveToX, driveToY, taxiCoords.z, 25.0, 786603, 5.0) + + -- Blips entfernen + if taxiBlip then + RemoveBlip(taxiBlip) + taxiBlip = nil + end + + if mapBlip then + RemoveBlip(mapBlip) + mapBlip = nil + end + + if destinationBlip then + RemoveBlip(destinationBlip) + destinationBlip = nil + end + + -- Nach 10 Sekunden tatsächlich löschen + SetTimeout(10000, function() + -- Fahrer löschen + if currentDriver and DoesEntityExist(currentDriver) then + DeleteEntity(currentDriver) + currentDriver = nil + DebugPrint("^2[TAXI DEBUG]^7 Driver deleted") + end + + -- Taxi löschen + if currentTaxi and DoesEntityExist(currentTaxi) then + exports['qb-target']:RemoveTargetEntity(currentTaxi) + DeleteEntity(currentTaxi) + currentTaxi = nil + DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted") + end + DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed") + end) + else + -- Sofort löschen wenn kein Fahrer da ist + if taxiBlip then + RemoveBlip(taxiBlip) + taxiBlip = nil + end + + if mapBlip then + RemoveBlip(mapBlip) + mapBlip = nil + end + + if destinationBlip then + RemoveBlip(destinationBlip) + destinationBlip = nil + end + + -- Taxi löschen + if currentTaxi and DoesEntityExist(currentTaxi) then + exports['qb-target']:RemoveTargetEntity(currentTaxi) + DeleteEntity(currentTaxi) + currentTaxi = nil + DebugPrint("^2[TAXI DEBUG]^7 Taxi deleted") + end + + DebugPrint("^2[TAXI DEBUG]^7 Taxi despawn completed (no driver)") + end +end + +function CalculateDistanceToCoords(coords) + local playerCoords = GetEntityCoords(PlayerPedId()) + return #(playerCoords - coords) +end + +-- Command um Taxi zu stoppen +RegisterCommand('stoptaxi', function() + if currentTaxi and DoesEntityExist(currentTaxi) then + DespawnTaxi() + lib.notify({ + title = 'Taxi Service', + description = 'Taxi-Service beendet', + type = 'info' + }) + else + lib.notify({ + title = 'Taxi Service', + description = 'Du hast kein aktives Taxi', + type = 'error' + }) + end +end) + +-- Thread zum Überwachen der Tasten im Taxi +CreateThread(function() + while true do + Wait(0) + + if currentTaxi and DoesEntityExist(currentTaxi) then + local playerPed = PlayerPedId() + + if IsPedInVehicle(playerPed, currentTaxi, false) then + -- Zeige Hinweise an + local helpText = '[E] - Ziel wählen [F] - Fahrt beenden' + lib.showTextUI(helpText, { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + -- Wenn E gedrückt wird, öffne Menü + if IsControlJustReleased(0, 38) then -- E Taste + OpenDestinationMenu() + end + + -- Wenn F gedrückt wird, beende Fahrt + if IsControlJustReleased(0, 23) then -- F Taste + lib.hideTextUI() + EndTaxiRide() + end + else + lib.hideTextUI() + end + else + lib.hideTextUI() + Wait(1000) -- Längere Wartezeit wenn kein Taxi existiert + end + end +end) + +-- Funktion zum Beenden der Fahrt +function EndTaxiRide() + DebugPrint("^2[TAXI DEBUG]^7 Ending taxi ride") + + if not currentTaxi or not DoesEntityExist(currentTaxi) then + return + end + + local playerPed = PlayerPedId() + + -- Fahrt beenden Benachrichtigung + lib.notify({ + title = 'Taxi Service', + description = 'Fahrt beendet. Du steigst aus.', + type = 'info' + }) + + -- Spieler aussteigen lassen + TaskLeaveVehicle(playerPed, currentTaxi, 0) + + -- Warten bis ausgestiegen + CreateThread(function() + local timeout = GetGameTimer() + 5000 + while GetGameTimer() < timeout do + if not IsPedInVehicle(playerPed, currentTaxi, false) then + -- Spieler ist ausgestiegen + break + end + Wait(100) + end + + -- Taxi nach 5 Sekunden despawnen + SetTimeout(5000, function() + DespawnTaxi() + end) + end) +end + +-- Thread zum Überwachen des Einsteigens ins Taxi (ohne qb-target) +CreateThread(function() + while true do + Wait(1000) + + if currentTaxi and DoesEntityExist(currentTaxi) and not IsPedInVehicle(PlayerPedId(), currentTaxi, false) then + -- Spieler ist nicht im Taxi, aber Taxi existiert + local playerPed = PlayerPedId() + local playerCoords = GetEntityCoords(playerPed) + local taxiCoords = GetEntityCoords(currentTaxi) + + if #(playerCoords - taxiCoords) < 5.0 then + -- Spieler ist in der Nähe des Taxis + lib.showTextUI('[E] - Ins Taxi einsteigen', { + position = "top-center", + icon = 'car-side', + style = { + borderRadius = 10, + backgroundColor = '#4299E1', + color = 'white' + } + }) + + -- Prüfen ob E gedrückt wird + if IsControlJustReleased(0, 38) then -- E Taste + -- Spieler will einsteigen + lib.hideTextUI() + -- Spieler hinten einsteigen lassen + local seatIndex = 1 -- Hinten links + if not IsVehicleSeatFree(currentTaxi, 1) then + seatIndex = 2 -- Hinten rechts + end + if not IsVehicleSeatFree(currentTaxi, seatIndex) then + seatIndex = 0 -- Beifahrer als Fallback + end + + TaskEnterVehicle(playerPed, currentTaxi, 10000, seatIndex, 1.0, 1, 0) + + -- Warten bis eingestiegen + local entryTimeout = GetGameTimer() + 10000 + CreateThread(function() + while GetGameTimer() < entryTimeout do + if IsPedInVehicle(playerPed, currentTaxi, false) then + -- Spieler ist eingestiegen + Wait(1000) + OpenDestinationMenu() + break + end + Wait(100) + end + end) + end + else + lib.hideTextUI() + end + end + end +end) + +-- Cleanup beim Resource Stop +AddEventHandler('onResourceStop', function(resourceName) + if GetCurrentResourceName() == resourceName then + DebugPrint("^2[TAXI DEBUG]^7 Cleaning up main script...") + + -- UI ausblenden + lib.hideTextUI() + + -- Taxi despawnen + DespawnTaxi() + + DebugPrint("^2[TAXI DEBUG]^7 Main cleanup completed") + end +end) + + + + diff --git a/resources/[carscripts]/nordi_taxi/client/stations.lua b/resources/[carscripts]/nordi_taxi/client/stations.lua new file mode 100644 index 000000000..1c5008d13 --- /dev/null +++ b/resources/[carscripts]/nordi_taxi/client/stations.lua @@ -0,0 +1,1594 @@ +local QBCore = exports['qb-core']:GetCoreObject() +local stationVehicles = {} +local stationBlips = {} + +function DebugPrint(type, message) + if Config.Debug then + if type == "error" then + print("^1[TAXI STATIONS DEBUG]^7 " .. message) + elseif type == "warning" then + print("^3[TAXI STATIONS DEBUG]^7 " .. message) + else -- success/info + print("^2[TAXI STATIONS DEBUG]^7 " .. message) + end + end +end + +local QBCore = exports['qb-core']:GetCoreObject() +local stationVehicles = {} + + + +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 + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Initializing taxi stations...") + InitializeTaxiStations() + + -- Regelmäßige Überprüfung und Wiederherstellung der Stationen + CreateThread(function() + while true do + Wait(60000) -- Alle 60 Sekunden prüfen + CheckAndRestoreStationVehicles() + end + end) +end) + +function InitializeTaxiStations() + DebugPrint("^2[TAXI STATIONS DEBUG]^7 InitializeTaxiStations started") + + if not Config.TaxiStations then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Config.TaxiStations not found!") + return + end + + 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 + 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) + SetBlipSprite(blip, 198) + SetBlipColour(blip, 5) + SetBlipScale(blip, 0.8) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(station.name) + EndTextCommandSetBlipName(blip) + stationBlips[stationId] = blip + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Blip created for station " .. stationId) + + -- Fahrzeuge an Station spawnen + stationVehicles[stationId] = {} + + -- Verzögertes Spawnen der Fahrzeuge, um Ressourcenkonflikte zu vermeiden + CreateThread(function() + for vehicleId, vehicleData in pairs(station.vehicles) do + -- Kleine Verzögerung zwischen jedem Fahrzeug + Wait(500) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Spawning vehicle " .. vehicleId .. " (" .. vehicleData.model .. ") at station " .. stationId) + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end + end) + end + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 All stations initialization started") +end + +function CleanupExistingStations() + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleaning up existing stations...") + + -- Alle bestehenden Fahrzeuge löschen + for stationId, vehicles in pairs(stationVehicles) do + for vehicleId, vehicleInfo in pairs(vehicles) do + if vehicleInfo.entity and DoesEntityExist(vehicleInfo.entity) then + exports['qb-target']:RemoveTargetEntity(vehicleInfo.entity) + DeleteEntity(vehicleInfo.entity) + end + if vehicleInfo.driver and DoesEntityExist(vehicleInfo.driver) then + DeleteEntity(vehicleInfo.driver) + end + end + end + + -- Alle Blips entfernen + for _, blip in pairs(stationBlips) do + RemoveBlip(blip) + end + + -- Variablen zurücksetzen + stationVehicles = {} + stationBlips = {} + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed") +end + +function SpawnStationVehicle(stationId, vehicleId, vehicleData) + 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 + 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 + + -- Prüfen ob die Position frei ist + local clearArea = true + local vehicles = GetGamePool('CVehicle') + for _, vehicle in ipairs(vehicles) do + local vehCoords = GetEntityCoords(vehicle) + if #(vector3(vehicleData.coords.x, vehicleData.coords.y, vehicleData.coords.z) - vehCoords) < 3.0 then + clearArea = false + 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) + end) + return + end + end + + CreateThread(function() + local vehicleHash = GetHashKey(vehicleData.model) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle hash: " .. vehicleHash) + + RequestModel(vehicleHash) + local timeout = GetGameTimer() + 10000 + while not HasModelLoaded(vehicleHash) and GetGameTimer() < timeout do + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Waiting for model " .. vehicleData.model .. " to load...") + Wait(100) + end + + if not HasModelLoaded(vehicleHash) then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to load model: " .. vehicleData.model) + -- Nach 30 Sekunden erneut versuchen + SetTimeout(30000, function() + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end) + return + end + + local vehicle = CreateVehicle( + vehicleHash, + vehicleData.coords.x, + vehicleData.coords.y, + vehicleData.coords.z, + vehicleData.coords.w, + false, + false + ) + + if not DoesEntityExist(vehicle) then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to create vehicle!") + -- Nach 30 Sekunden erneut versuchen + SetTimeout(30000, function() + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end) + return + end + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle created: " .. vehicle) + + -- Fahrzeug konfigurieren + SetEntityAsMissionEntity(vehicle, true, true) + SetVehicleOnGroundProperly(vehicle) + SetVehicleDoorsLocked(vehicle, 2) -- Locked + SetVehicleEngineOn(vehicle, false, true, false) + + -- Verbesserte Persistenz + SetEntityInvincible(vehicle, true) + SetVehicleCanBeVisiblyDamaged(vehicle, false) + SetEntityProofs(vehicle, true, true, true, true, true, true, true, true) + SetVehicleExplodesOnHighExplosionDamage(vehicle, false) + SetVehicleHasBeenOwnedByPlayer(vehicle, true) + SetVehicleIsConsideredByPlayer(vehicle, true) + + -- Fahrzeug-Info speichern + if not stationVehicles[stationId] then + stationVehicles[stationId] = {} + end + + stationVehicles[stationId][vehicleId] = { + entity = vehicle, + data = vehicleData, + occupied = false + } + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Adding qb-target for vehicle " .. vehicle) + + -- qb-target für Fahrzeug hinzufügen + exports['qb-target']:AddTargetEntity(vehicle, { + options = { + { + type = "client", + event = "taxi:enterStationVehicle", + icon = "fas fa-taxi", + label = "Taxi nehmen ($" .. vehicleData.pricePerKm .. "/km)", + stationId = stationId, + vehicleId = vehicleId + } + }, + distance = 3.0 + }) + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 qb-target added for vehicle " .. vehicle) + + SetModelAsNoLongerNeeded(vehicleHash) + end) +end + +function CheckAndRestoreStationVehicles() + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Checking station vehicles...") + + local restoredCount = 0 + + for stationId, station in pairs(Config.TaxiStations) do + if not stationVehicles[stationId] then + stationVehicles[stationId] = {} + end + + for vehicleId, vehicleData in pairs(station.vehicles) do + local shouldSpawn = false + + -- Prüfen ob das Fahrzeug existiert + if not stationVehicles[stationId][vehicleId] then + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle data missing for station " .. stationId .. ", vehicle " .. vehicleId) + shouldSpawn = true + elseif not stationVehicles[stationId][vehicleId].entity then + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Vehicle entity missing for station " .. stationId .. ", vehicle " .. vehicleId) + shouldSpawn = true + elseif not DoesEntityExist(stationVehicles[stationId][vehicleId].entity) then + 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 + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle at station " .. stationId .. ", vehicle " .. vehicleId .. " is occupied") + shouldSpawn = false + end + + if shouldSpawn then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station " .. stationId .. ", vehicle " .. vehicleId) + SpawnStationVehicle(stationId, vehicleId, vehicleData) + restoredCount = restoredCount + 1 + + -- Kleine Verzögerung zwischen Spawns + Wait(500) + end + end + end + + if restoredCount > 0 then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Restored " .. restoredCount .. " station vehicles") + else + DebugPrint("^2[TAXI STATIONS DEBUG]^7 All station vehicles are present") + end +end + +-- Fortgeschrittenes Taxi-Fahrer-Verhaltenssystem +function InitializeTaxiDriverAI(driver, vehicle) + if not driver or not DoesEntityExist(driver) then return end + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Initializing advanced taxi driver AI") + + -- Fahrer-Persönlichkeit und Fähigkeiten zufällig festlegen + local driverData = { + personality = { + patience = math.random(7, 10) / 10, -- 0.7-1.0: Wie geduldig ist der Fahrer + caution = math.random(6, 10) / 10, -- 0.6-1.0: Wie vorsichtig fährt er + speedPreference = math.random(15, 25), -- 15-25: Bevorzugte Geschwindigkeit + trafficRuleCompliance = math.random(8, 10)/10 -- 0.8-1.0: Wie genau hält er Verkehrsregeln ein + }, + state = { + stuckCounter = 0, + lastStuckRecovery = 0, + lastRouteRecalculation = 0, + currentBehavior = "normal", -- normal, cautious, stuck, recovery + lastSpeedCheck = 0, + speedHistory = {}, + lastPositions = {}, + trafficLightWaitStart = 0, + isWaitingAtTrafficLight = false + }, + settings = { + maxStuckCounter = math.random(15, 25), -- Wie lange warten bis Befreiungsversuch + stuckThreshold = 0.5, -- Bewegungsschwelle für Steckenbleiben + checkInterval = 2000, -- Überprüfungsintervall in ms + positionHistorySize = 5, -- Anzahl der zu speichernden Positionen + minRecoveryInterval = 25000, -- Min. Zeit zwischen Befreiungsversuchen + minRouteRecalcInterval = 30000, -- Min. Zeit zwischen Routenneuberechnungen + trafficLightMaxWait = 45000 -- Max. Wartezeit an Ampeln + } + } + + -- Fahrer-Verhalten basierend auf Persönlichkeit einstellen + SetDriverAbility(driver, driverData.personality.caution) + SetDriverAggressiveness(driver, 1.0 - driverData.personality.caution) + + -- Fahrer-Daten im Entity speichern + Entity(vehicle).state.driverData = driverData + + -- Fahrer-Verhalten-Thread starten + CreateThread(function() + local lastPos = GetEntityCoords(vehicle) + local lastCheck = GetGameTimer() + + while DoesEntityExist(vehicle) and DoesEntityExist(driver) do + Wait(driverData.settings.checkInterval) + + local currentTime = GetGameTimer() + local timeDelta = currentTime - lastCheck + lastCheck = currentTime + + -- Aktuelle Position und Geschwindigkeit + local currentPos = GetEntityCoords(vehicle) + local speed = GetEntitySpeed(vehicle) + local distanceMoved = #(lastPos - currentPos) + + -- Position für Historie speichern + table.insert(driverData.state.lastPositions, 1, currentPos) + if #driverData.state.lastPositions > driverData.settings.positionHistorySize then + table.remove(driverData.state.lastPositions) + end + + -- Geschwindigkeit für Historie speichern + table.insert(driverData.state.speedHistory, 1, speed) + if #driverData.state.speedHistory > 5 then + table.remove(driverData.state.speedHistory) + end + + -- Durchschnittsgeschwindigkeit berechnen + local avgSpeed = 0 + for _, s in ipairs(driverData.state.speedHistory) do + avgSpeed = avgSpeed + s + end + avgSpeed = avgSpeed / #driverData.state.speedHistory + + -- Ampel-Erkennung + local isAtTrafficLight = IsVehicleStoppedAtTrafficLights(vehicle) + + -- Ampel-Wartezustand aktualisieren + if isAtTrafficLight and not driverData.state.isWaitingAtTrafficLight then + -- Gerade an Ampel angekommen + driverData.state.isWaitingAtTrafficLight = true + driverData.state.trafficLightWaitStart = currentTime + 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 + 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) + -- Dann normale Fahrt fortsetzen + TaxiDriverContinueRoute(driver, vehicle) + driverData.state.isWaitingAtTrafficLight = false + end + elseif not isAtTrafficLight and driverData.state.isWaitingAtTrafficLight then + -- Ampel verlassen + driverData.state.isWaitingAtTrafficLight = false + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Taxi continued after traffic light") + end + + -- Steckenbleiben-Erkennung (nicht an Ampel und kaum Bewegung) + if not isAtTrafficLight and distanceMoved < driverData.settings.stuckThreshold and speed < 0.5 then + driverData.state.stuckCounter = driverData.state.stuckCounter + 1 + + -- Nur alle 5 Zähler-Erhöhungen loggen + if driverData.state.stuckCounter % 5 == 0 then + 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 + + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Taxi is stuck, attempting intelligent recovery") + driverData.state.lastStuckRecovery = currentTime + driverData.state.currentBehavior = "recovery" + + -- Intelligente Befreiung basierend auf Umgebung + TaxiDriverIntelligentRecovery(driver, vehicle) + + -- Steckenbleiben-Zähler teilweise zurücksetzen + driverData.state.stuckCounter = math.floor(driverData.settings.maxStuckCounter * 0.4) + end + else + -- Wenn sich das Fahrzeug bewegt oder an einer Ampel steht + if isAtTrafficLight then + -- An Ampel: Zähler langsamer reduzieren + driverData.state.stuckCounter = math.max(0, driverData.state.stuckCounter - 0.2) + else + -- In Bewegung: Zähler reduzieren + driverData.state.stuckCounter = math.max(0, driverData.state.stuckCounter - 1) + + -- Wenn Fahrzeug sich bewegt, aber sehr langsam über längere Zeit + if avgSpeed < 2.0 and driverData.state.stuckCounter > driverData.settings.maxStuckCounter * 0.5 and + (currentTime - driverData.state.lastRouteRecalculation) > driverData.settings.minRouteRecalcInterval then + + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Taxi moving too slow, recalculating route") + driverData.state.lastRouteRecalculation = currentTime + + -- Route neu berechnen + TaxiDriverRecalculateRoute(driver, vehicle) + end + end + end + + -- Verhalten basierend auf Umgebung anpassen + TaxiDriverAdaptBehavior(driver, vehicle, driverData) + + lastPos = currentPos + end + end) + + return driverData +end + +-- Intelligente Befreiung bei Steckenbleiben +function TaxiDriverIntelligentRecovery(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Position und Umgebung analysieren + local vehicleCoords = GetEntityCoords(vehicle) + local vehicleHeading = GetEntityHeading(vehicle) + local vehicleForwardVector = GetEntityForwardVector(vehicle) + + -- Prüfen ob Hindernisse vorne, hinten, links, rechts + local forwardClear = not IsPositionOccupied( + vehicleCoords.x + vehicleForwardVector.x * 4.0, + vehicleCoords.y + vehicleForwardVector.y * 4.0, + vehicleCoords.z, + 1.0, false, true, false, false, false, 0, false + ) + + local backwardClear = not IsPositionOccupied( + vehicleCoords.x - vehicleForwardVector.x * 4.0, + vehicleCoords.y - vehicleForwardVector.y * 4.0, + vehicleCoords.z, + 1.0, false, true, false, false, false, 0, false + ) + + -- Befreiungsstrategie basierend auf Umgebung + ClearPedTasks(driver) + + if backwardClear then + -- Rückwärts fahren wenn hinten frei + 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 + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Path clear, continuing") + TaxiDriverContinueRoute(driver, vehicle) + else + -- Sonst versuchen zu wenden + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recovery: Turning around") + TaskVehicleTempAction(driver, vehicle, 7, 2000) -- Turn left + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 8, 1000) -- Reverse + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 6, 2000) -- Turn right + Wait(1000) + TaxiDriverContinueRoute(driver, vehicle) + end + elseif forwardClear then + -- Wenn nur vorne frei, vorwärts fahren + 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 + 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 + Wait(800) + TaskVehicleTempAction(driver, vehicle, 6, 1000) -- Turn right + Wait(1000) + TaskVehicleTempAction(driver, vehicle, 1, 800) -- Forward + Wait(800) + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Route neu berechnen +function TaxiDriverRecalculateRoute(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Zielposition aus dem Fahrzeug-State ermitteln + -- Da wir die nicht direkt auslesen können, nehmen wir an, dass es das aktuelle Ziel ist + local destination = Entity(vehicle).state.currentDestination + + if destination then + -- Versuche einen alternativen Weg zu finden + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Recalculating route to destination") + + -- Kurz anhalten + TaskVehicleTempAction(driver, vehicle, 27, 1000) -- Stop + Wait(1000) + + -- Neue Route mit leicht geändertem Fahrstil + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + else + -- Wenn kein Ziel bekannt, einfach weiterfahren + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Normale Fahrt fortsetzen +function TaxiDriverContinueRoute(driver, vehicle) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Ziel aus dem Fahrzeug-State holen + local destination = Entity(vehicle).state.currentDestination + + if destination then + -- Zum Ziel fahren mit angepasster Fahrweise + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + else + -- Wenn kein Ziel bekannt, einfach geradeaus fahren + TaskVehicleDriveWander(driver, vehicle, 15.0, 786603) + end +end + +-- Fahrverhalten an Umgebung anpassen +function TaxiDriverAdaptBehavior(driver, vehicle, driverData) + if not DoesEntityExist(vehicle) or not DoesEntityExist(driver) then return end + + -- Aktuelle Geschwindigkeit und Position + local speed = GetEntitySpeed(vehicle) + local vehicleCoords = GetEntityCoords(vehicle) + + -- Verkehrsdichte in der Umgebung prüfen + local vehiclesNearby = 0 + local vehicles = GetGamePool('CVehicle') + for _, otherVehicle in ipairs(vehicles) do + if otherVehicle ~= vehicle then + local otherCoords = GetEntityCoords(otherVehicle) + local distance = #(vehicleCoords - otherCoords) + if distance < 15.0 then + vehiclesNearby = vehiclesNearby + 1 + end + end + end + + -- Verhalten basierend auf Verkehrsdichte anpassen + local targetSpeed = driverData.personality.speedPreference + + if vehiclesNearby > 5 then + -- Viel Verkehr: langsamer und vorsichtiger + targetSpeed = targetSpeed * 0.7 + SetDriverAggressiveness(driver, 0.0) + elseif vehiclesNearby > 2 then + -- Moderater Verkehr: etwas langsamer + targetSpeed = targetSpeed * 0.85 + SetDriverAggressiveness(driver, 0.1) + else + -- Wenig Verkehr: normale Geschwindigkeit + SetDriverAggressiveness(driver, 0.2) + end + + -- Geschwindigkeit anpassen wenn nötig + if math.abs(speed - targetSpeed) > 5.0 then + if speed < targetSpeed then + -- Beschleunigen + TaskVehicleTempAction(driver, vehicle, 23, 500) -- Gentle forward + else + -- Abbremsen + TaskVehicleTempAction(driver, vehicle, 24, 500) -- Gentle brake + end + + -- Nach der Anpassung normale Fahrt fortsetzen + Wait(500) + TaxiDriverContinueRoute(driver, vehicle) + end +end + +-- Hilfsfunktion um Spieler-Sitz zu ermitteln +function GetPlayerVehicleSeat(ped, vehicle) + if not IsPedInVehicle(ped, vehicle, false) then + return nil + end + + -- Alle möglichen Sitze prüfen + for seat = -1, 7 do -- -1 = Fahrer, 0 = Beifahrer, 1+ = Hintersitze + if GetPedInVehicleSeat(vehicle, seat) == ped then + return seat + end + end + + return nil +end + +-- Event für Einsteigen in Station-Taxi +RegisterNetEvent('taxi:enterStationVehicle', function(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 + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle not found in data") + lib.notify({ + title = 'Taxi Service', + description = 'Dieses Taxi ist nicht verfügbar', + type = 'error' + }) + return + end + + local vehicleInfo = stationVehicles[stationId][vehicleId] + + if vehicleInfo.occupied then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Vehicle already occupied") + lib.notify({ + title = 'Taxi Service', + description = 'Dieses Taxi ist bereits besetzt', + type = 'error' + }) + return + end + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Entering vehicle...") + + -- Spieler ins Fahrzeug setzen + local playerPed = PlayerPedId() + local vehicle = vehicleInfo.entity + + -- Türen entsperren + SetVehicleDoorsLocked(vehicle, 1) + -- Info-Text anzeigen während Fahrer geladen wird + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Showing driver loading text...") + lib.showTextUI('🚕 Warte an der Station - Fahrer wird geladen...', { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + -- Kurz warten damit der Text sichtbar wird + Wait(1000) + + -- Verschiedene Fahrer-Models versuchen + local driverModels = { + "A_C_Chimp", -- Taxi Driver (erste Wahl) + "a_m_y_business_01", -- Business Male + "a_m_m_business_01", -- Business Male 2 + "mp_m_freemode_01", -- Male Freemode + "a_m_y_downtown_01", -- Downtown Male + "a_m_m_farmer_01", -- Farmer + "a_m_y_hipster_01", -- Hipster + "a_m_y_beach_01" -- Beach Guy + } + + local driver = nil + local driverHash = nil + + for i, modelName in pairs(driverModels) do + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Trying driver model " .. i .. ": " .. modelName) + driverHash = GetHashKey(modelName) + + -- Text während Model-Loading aktualisieren + lib.showTextUI('🚕 Lade Fahrer-Model (' .. i .. '/' .. #driverModels .. '): ' .. modelName .. '...', { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + RequestModel(driverHash) + local timeout = GetGameTimer() + 8000 -- Längere Wartezeit + local attempts = 0 + + while not HasModelLoaded(driverHash) and GetGameTimer() < timeout do + attempts = attempts + 1 + if attempts % 10 == 0 then + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Still waiting for model " .. modelName .. " (attempt " .. attempts .. ")") + end + Wait(100) + end + + if HasModelLoaded(driverHash) then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver model " .. modelName .. " loaded successfully") + + -- Text aktualisieren + lib.showTextUI('🚕 Erstelle Fahrer...', { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + driver = CreatePedInsideVehicle(vehicle, 26, driverHash, -1, true, false) + + if DoesEntityExist(driver) then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver created successfully: " .. driver) + break + else + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to create driver with model: " .. modelName) + SetModelAsNoLongerNeeded(driverHash) + end + else + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Failed to load driver model: " .. modelName) + SetModelAsNoLongerNeeded(driverHash) + end + + Wait(500) -- Kurze Pause zwischen Versuchen + end + + -- Fallback: Notfall-Fahrer erstellen + if not driver or not DoesEntityExist(driver) then + DebugPrint("^3[TAXI STATIONS DEBUG]^7 Using emergency fallback driver creation...") + + lib.showTextUI('🚕 Erstelle Notfall-Fahrer...', { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#FFA500', + color = 'white' + } + }) + + -- Notfall-Fallback mit Hash-Werten + local emergencyModels = { + `mp_m_freemode_01`, + `a_m_y_hipster_01`, + `a_m_m_farmer_01`, + `a_m_y_beach_01` + } + + for _, hash in pairs(emergencyModels) do + RequestModel(hash) + local timeout = GetGameTimer() + 5000 + while not HasModelLoaded(hash) and GetGameTimer() < timeout do + Wait(50) + end + + if HasModelLoaded(hash) then + driver = CreatePedInsideVehicle(vehicle, 26, hash, -1, true, false) + if DoesEntityExist(driver) then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Emergency driver created") + driverHash = hash + break + end + SetModelAsNoLongerNeeded(hash) + end + end + + Wait(1000) + end + + -- Wenn immer noch kein Fahrer, ohne Fahrer fortfahren + if not driver or not DoesEntityExist(driver) then + 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", + icon = 'exclamation-triangle', + style = { + borderRadius = 10, + backgroundColor = '#FF6B6B', + color = 'white' + } + }) + + Wait(3000) -- 3 Sekunden anzeigen + lib.hideTextUI() + + driver = nil + + lib.notify({ + title = 'Taxi Service', + description = 'Kein Fahrer verfügbar - Du kannst das Taxi selbst fahren', + type = 'warning' + }) + else + -- Fahrer erfolgreich erstellt + lib.showTextUI('✅ Fahrer bereit - Steige hinten ein!', { + position = "top-center", + icon = 'check-circle', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + Wait(2000) -- 2 Sekunden anzeigen + + -- Fahrer konfigurieren + SetEntityAsMissionEntity(driver, true, true) + SetPedFleeAttributes(driver, 0, 0) + SetPedCombatAttributes(driver, 17, 1) + SetPedSeeingRange(driver, 0.0) + SetPedHearingRange(driver, 0.0) + SetPedAlertness(driver, 0) + SetPedKeepTask(driver, true) + SetBlockingOfNonTemporaryEvents(driver, true) + + -- Fortgeschrittene KI-ähnliche Fahrer-Logik initialisieren + local driverData = InitializeTaxiDriverAI(driver, vehicle) + + -- Zufälligen Fahrer-Namen generieren + local firstNames = {"Max", "Thomas", "Ali", "Mehmet", "Hans", "Peter", "Klaus", "Michael", "Stefan", "Frank"} + local lastNames = {"Müller", "Schmidt", "Schneider", "Fischer", "Weber", "Meyer", "Wagner", "Becker", "Schulz", "Hoffmann"} + local driverName = firstNames[math.random(#firstNames)] .. " " .. lastNames[math.random(#lastNames)] + + -- Fahrer-Name im Fahrzeug-State speichern + Entity(vehicle).state.driverName = driverName + + lib.notify({ + title = 'Taxi Service', + description = 'Dein Fahrer ' .. driverName .. ' ist bereit - Steige hinten ein', + type = 'success' + }) + end + + -- Spieler HINTEN einsteigen lassen + local seatIndex = 1 -- Hinten links als Standard + + -- Prüfen welche Hintersitze verfügbar sind + local availableSeats = {} + for i = 1, 3 do -- Sitze 1, 2, 3 (hinten links, hinten mitte, hinten rechts) + if IsVehicleSeatFree(vehicle, i) then + table.insert(availableSeats, i) + end + end + + -- Ersten verfügbaren Hintersitz wählen + if #availableSeats > 0 then + seatIndex = availableSeats[1] + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Using rear seat: " .. seatIndex) + else + -- Fallback: Beifahrersitz + seatIndex = 0 + DebugPrint("^3[TAXI STATIONS DEBUG]^7 No rear seats available, using passenger seat") + end + + -- Spieler in den gewählten Sitz einsteigen lassen + TaskEnterVehicle(playerPed, vehicle, 10000, seatIndex, 1.0, 1, 0) + + -- Info-Text während Einsteigen + lib.showTextUI('🚕 Steige ins Taxi ein...', { + position = "top-center", + icon = 'car-side', + style = { + borderRadius = 10, + backgroundColor = '#4299E1', + color = 'white' + } + }) + + -- Warten bis Spieler eingestiegen ist + CreateThread(function() + local enterTimeout = GetGameTimer() + 15000 -- Längere Zeit für Einsteigen + local hasEntered = false + + while GetGameTimer() < enterTimeout and not hasEntered do + if IsPedInVehicle(playerPed, vehicle, false) then + hasEntered = true + vehicleInfo.occupied = true + vehicleInfo.driver = driver + + -- Info-Text verstecken + lib.hideTextUI() + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player entered successfully") + + -- Prüfen ob Spieler wirklich hinten sitzt + local playerSeat = GetPlayerVehicleSeat(playerPed, vehicle) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player is in seat: " .. tostring(playerSeat)) + + if playerSeat == -1 then -- Fahrersitz + 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 + Wait(1000) + TaskShuffleToNextVehicleSeat(playerPed, vehicle) + Wait(2000) + end + end + + lib.notify({ + title = 'Taxi Service', + description = 'Willkommen im Taxi! Wähle dein Ziel.', + type = 'success' + }) + + -- Ziel-Menu öffnen + Wait(1000) -- Kurz warten damit Einsteigen abgeschlossen ist + OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, vehicleInfo.data.pricePerKm) + break + end + Wait(100) + end + + if not hasEntered then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Player failed to enter vehicle") + + -- Info-Text verstecken + lib.hideTextUI() + + lib.notify({ + title = 'Taxi Service', + description = 'Einsteigen fehlgeschlagen', + type = 'error' + }) + + -- Cleanup + if driver and DoesEntityExist(driver) then + DeleteEntity(driver) + end + SetVehicleDoorsLocked(vehicle, 2) + vehicleInfo.occupied = false + end + end) +end) + +function OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Opening station taxi menu") + + local options = {} + + -- Bekannte Ziele hinzufügen + for _, destination in pairs(Config.KnownDestinations) do + local customPrice = math.max(Config.MinFare, math.ceil((CalculateDistanceToCoords(destination.coords) / 1000) * pricePerKm)) + table.insert(options, { + title = destination.name, + description = 'Preis: $' .. customPrice .. ' | Entfernung: ' .. math.ceil(CalculateDistanceToCoords(destination.coords) / 1000 * 100) / 100 .. 'km', + icon = 'map-marker', + onSelect = function() + StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination.coords, customPrice) + end + }) + end + + -- Andere Taxi-Stationen als Ziele + table.insert(options, { + title = '📍 Andere Taxi-Stationen', + description = 'Fahre zu einer anderen Taxi-Station', + icon = 'taxi', + onSelect = function() + OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePerKm) + end + }) + + -- Waypoint Option + table.insert(options, { + title = 'Zu meinem Waypoint', + description = 'Fahre zu deinem gesetzten Waypoint', + icon = 'location-dot', + onSelect = function() + local waypoint = GetFirstBlipInfoId(8) + if DoesBlipExist(waypoint) then + local coords = GetBlipInfoIdCoord(waypoint) + local distance = CalculateDistanceToCoords(coords) / 1000 + local price = math.max(Config.MinFare, math.ceil(distance * pricePerKm)) + StartStationTaxiRide(stationId, vehicleId, vehicle, driver, coords, price) + else + lib.notify({ + title = 'Taxi Service', + description = 'Du hast keinen Waypoint gesetzt', + type = 'error' + }) + OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) + end + end + }) + + -- Selbst fahren Option (wenn kein Fahrer) + if not driver or not DoesEntityExist(driver) then + table.insert(options, { + title = '🚗 Selbst fahren', + description = 'Du fährst das Taxi selbst (kostenlos)', + icon = 'car', + onSelect = function() + SelfDriveStationTaxi(stationId, vehicleId, vehicle) + end + }) + end + + -- Aussteigen Option + table.insert(options, { + title = 'Aussteigen', + description = 'Das Taxi verlassen', + icon = 'door-open', + onSelect = function() + ExitStationTaxi(stationId, vehicleId, vehicle, driver) + end + }) + + lib.registerContext({ + id = 'station_taxi_menu', + title = 'Taxi - Ziel wählen (' .. Config.TaxiStations[stationId].name .. ')', + options = options + }) + + lib.showContext('station_taxi_menu') +end + +function SelfDriveStationTaxi(stationId, vehicleId, vehicle) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player driving taxi themselves") + + local playerPed = PlayerPedId() + + -- Spieler zum Fahrersitz bewegen + TaskShuffleToNextVehicleSeat(playerPed, vehicle) + + lib.notify({ + title = 'Taxi Service', + description = 'Du fährst das Taxi jetzt selbst. Bringe es zur Station zurück wenn du fertig bist.', + type = 'info' + }) + + -- Überwachung für Rückgabe + CreateThread(function() + while DoesEntityExist(vehicle) do + local playerPed = PlayerPedId() + + -- Prüfen ob Spieler noch im Fahrzeug ist + if not IsPedInVehicle(playerPed, vehicle, false) then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player left self-drive taxi") + + -- Nach 30 Sekunden Taxi zurück zur Station + SetTimeout(30000, function() + ReturnTaxiToStation(stationId, vehicleId, vehicle, nil) + end) + break + end + + Wait(5000) + end + end) +end + +function OpenStationSelectionMenu(stationId, vehicleId, vehicle, driver, pricePerKm) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Opening station selection menu") + + local options = {} + + for otherStationId, station in pairs(Config.TaxiStations) do + if otherStationId ~= stationId then + local distance = CalculateDistanceToCoords(station.blipCoords) / 1000 + local price = math.max(Config.MinFare, math.ceil(distance * pricePerKm)) + + table.insert(options, { + title = station.name, + description = 'Preis: $' .. price .. ' | Entfernung: ' .. math.ceil(distance * 100) / 100 .. 'km', + icon = 'building', + onSelect = function() + StartStationTaxiRide(stationId, vehicleId, vehicle, driver, station.blipCoords, price) + end + }) + end + end + + -- Zurück Option + table.insert(options, { + title = '← Zurück', + description = 'Zurück zum Hauptmenü', + icon = 'arrow-left', + onSelect = function() + OpenStationTaxiMenu(stationId, vehicleId, vehicle, driver, pricePerKm) + end + }) + + lib.registerContext({ + id = 'station_selection_menu', + title = 'Taxi-Stationen', + options = options + }) + + lib.showContext('station_selection_menu') +end + +function StartStationTaxiRide(stationId, vehicleId, vehicle, driver, destination, price) + 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 + lib.notify({ + title = 'Taxi Service', + description = 'Kein Fahrer verfügbar. Fahre selbst zum Ziel! (Kostenlos)', + type = 'info' + }) + + -- Destination Blip erstellen + local destinationBlip = AddBlipForCoord(destination.x, destination.y, destination.z) + SetBlipSprite(destinationBlip, 1) + SetBlipColour(destinationBlip, 2) + SetBlipScale(destinationBlip, 0.8) + SetBlipRoute(destinationBlip, true) -- Route zum Ziel anzeigen + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Taxi Ziel") + EndTextCommandSetBlipName(destinationBlip) + + -- Route setzen + SetNewWaypoint(destination.x, destination.y) + + return + end + + lib.notify({ + title = 'Taxi Service', + description = 'Fahrt gestartet - Preis: $' .. price, + type = 'success' + }) + + -- Destination Blip erstellen + local destinationBlip = AddBlipForCoord(destination.x, destination.y, destination.z) + SetBlipSprite(destinationBlip, 1) + SetBlipColour(destinationBlip, 2) + SetBlipScale(destinationBlip, 0.8) + SetBlipRoute(destinationBlip, true) -- Route zum Ziel anzeigen + BeginTextCommandSetBlipName("STRING") + AddTextComponentString("Taxi Ziel") + EndTextCommandSetBlipName(destinationBlip) + + -- Ziel im Fahrzeug-State speichern für die KI-Logik + Entity(vehicle).state.currentDestination = destination + + -- Zum Ziel fahren mit verbesserter Navigation + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, destination.x, destination.y, destination.z, 20.0, drivingStyle, 10.0) + + -- Fahrer-Dialog anzeigen + local driverName = Entity(vehicle).state.driverName or "Taxi-Fahrer" + local dialogOptions = { + "Ich bringe dich sicher ans Ziel.", + "Schönes Wetter heute, oder?", + "Ich kenne eine Abkürzung.", + "Bist du aus der Gegend?", + "Ich fahre schon seit 15 Jahren Taxi.", + "Entspann dich und genieße die Fahrt." + } + + -- Zufälligen Dialog auswählen und anzeigen + Wait(3000) -- Kurz warten bevor der Fahrer spricht + lib.notify({ + title = driverName, + description = dialogOptions[math.random(#dialogOptions)], + type = 'info', + icon = 'comment', + position = 'top-center', + duration = 5000 + }) + + -- Fahrt überwachen (vereinfacht, da KI-Logik die meiste Arbeit übernimmt) + CreateThread(function() + local rideTimeout = GetGameTimer() + (8 * 60 * 1000) -- 8 Minuten Timeout + + while DoesEntityExist(vehicle) and DoesEntityExist(driver) do + local vehicleCoords = GetEntityCoords(vehicle) + local distance = #(vector3(destination.x, destination.y, destination.z) - vehicleCoords) + + -- Überprüfen ob wir angekommen sind + if distance < 10.0 then + -- Angekommen + TaskVehicleTempAction(driver, vehicle, 27, 3000) + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Arrived at destination") + lib.notify({ + title = 'Taxi Service', + description = 'Du bist angekommen! Preis: $' .. price, + type = 'success' + }) + + -- Bezahlung + TriggerServerEvent('taxi:payFare', price) + + -- Blip entfernen + RemoveBlip(destinationBlip) + + -- Fahrer-Dialog anzeigen + local driverName = Entity(vehicle).state.driverName or "Taxi-Fahrer" + local arrivalDialogs = { + "Wir sind da! Das macht dann $" .. price .. ".", + "Angekommen! $" .. price .. " bitte.", + "Hier sind wir. $" .. price .. ", bargeldlos ist auch möglich.", + "Ziel erreicht! Das macht $" .. price .. "." + } + + lib.notify({ + title = driverName, + description = arrivalDialogs[math.random(#arrivalDialogs)], + type = 'info', + icon = 'comment', + position = 'top-center', + duration = 5000 + }) + + -- Nach 10 Sekunden Taxi zurück zur Station + SetTimeout(10000, function() + ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) + end) + + break + end + + -- Überprüfen ob die Fahrt zu lange dauert + if GetGameTimer() > rideTimeout then + 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!', + type = 'warning' + }) + + -- Teleportiere Taxi in die Nähe des Ziels + local offset = vector3( + math.random(-20, 20), + math.random(-20, 20), + 0 + ) + local nearDestination = vector3(destination.x, destination.y, destination.z) + offset + + -- Finde gültige Z-Koordinate + local success, groundZ = GetGroundZFor_3dCoord(nearDestination.x, nearDestination.y, nearDestination.z, true) + if success then + nearDestination = vector3(nearDestination.x, nearDestination.y, groundZ) + end + + -- Teleportiere Taxi + SetEntityCoords(vehicle, nearDestination.x, nearDestination.y, nearDestination.z, false, false, false, false) + + -- Neues Timeout setzen (1 Minute) + rideTimeout = GetGameTimer() + (60 * 1000) + end + + Wait(2000) + end + end) +end + +function ExitStationTaxi(stationId, vehicleId, vehicle, driver) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Player exiting station taxi") + + local playerPed = PlayerPedId() + TaskLeaveVehicle(playerPed, vehicle, 0) + + lib.notify({ + title = 'Taxi Service', + description = 'Du bist ausgestiegen', + type = 'info' + }) + + -- Taxi zurück zur Station nach 5 Sekunden + SetTimeout(5000, function() + ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) + end) +end + +function ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Returning taxi to station: " .. stationId .. "/" .. vehicleId) + + if not stationVehicles[stationId] or not stationVehicles[stationId][vehicleId] then + DebugPrint("^1[TAXI STATIONS DEBUG]^7 Station vehicle data not found for return") + return + end + + if not DoesEntityExist(vehicle) then + 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 + 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 + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end + end) + return + end + + -- Wenn Fahrer existiert, Taxi zur Station zurückfahren lassen + if driver and DoesEntityExist(driver) then + 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 + + -- Taxi zur Station zurückfahren lassen mit geduldiger Fahrweise + local drivingStyle = 786603 -- Normal/Vorsichtig + TaskVehicleDriveToCoordLongrange(driver, vehicle, stationCoords.x, stationCoords.y, stationCoords.z, 20.0, drivingStyle, 10.0) + + -- qb-target entfernen während der Fahrt + exports['qb-target']:RemoveTargetEntity(vehicle) + + -- Nach 10 Sekunden tatsächlich löschen + SetTimeout(10000, function() + -- Fahrer löschen + if driver and DoesEntityExist(driver) then + DeleteEntity(driver) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Driver deleted") + end + + -- Fahrzeug löschen + if DoesEntityExist(vehicle) then + DeleteEntity(vehicle) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted") + end + + -- Fahrzeug als nicht besetzt markieren + stationVehicles[stationId][vehicleId].occupied = false + stationVehicles[stationId][vehicleId].driver = nil + stationVehicles[stationId][vehicleId].entity = nil + + -- Nach Respawn-Zeit neues Fahrzeug spawnen + 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 + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end + end) + end) + else + -- Sofort löschen wenn kein Fahrer da ist + -- qb-target entfernen + if DoesEntityExist(vehicle) then + exports['qb-target']:RemoveTargetEntity(vehicle) + DeleteEntity(vehicle) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Vehicle deleted") + end + + -- Fahrzeug als nicht besetzt markieren + stationVehicles[stationId][vehicleId].occupied = false + stationVehicles[stationId][vehicleId].driver = nil + stationVehicles[stationId][vehicleId].entity = nil + + -- Nach Respawn-Zeit neues Fahrzeug spawnen + 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 + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning vehicle at station") + SpawnStationVehicle(stationId, vehicleId, vehicleData) + end + end) + end +end + +function CalculateDistanceToCoords(coords) + local playerCoords = GetEntityCoords(PlayerPedId()) + return #(playerCoords - coords) +end + +-- Command um nächste Taxi-Station zu finden +RegisterCommand('nearesttaxi', function() + local playerCoords = GetEntityCoords(PlayerPedId()) + local nearestStation = nil + local nearestDistance = math.huge + + for stationId, station in pairs(Config.TaxiStations) do + local distance = #(playerCoords - station.blipCoords) + if distance < nearestDistance then + nearestDistance = distance + nearestStation = {id = stationId, data = station, distance = distance} + end + end + + if nearestStation then + lib.notify({ + title = 'Taxi Service', + description = 'Nächste Station: ' .. nearestStation.data.name .. ' (' .. math.ceil(nearestDistance) .. 'm)', + type = 'info' + }) + + -- Waypoint zur nächsten Station setzen + SetNewWaypoint(nearestStation.data.blipCoords.x, nearestStation.data.blipCoords.y) + else + lib.notify({ + title = 'Taxi Service', + description = 'Keine Taxi-Station gefunden', + type = 'error' + }) + end +end) + +-- Event für Admin Respawn +RegisterNetEvent('taxi:respawnAllStations', function() + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Respawning all stations...") + + -- Alle bestehenden Fahrzeuge löschen + for stationId, vehicles in pairs(stationVehicles) do + for vehicleId, vehicleInfo in pairs(vehicles) do + if vehicleInfo.entity and DoesEntityExist(vehicleInfo.entity) then + exports['qb-target']:RemoveTargetEntity(vehicleInfo.entity) + DeleteEntity(vehicleInfo.entity) + end + if vehicleInfo.driver and DoesEntityExist(vehicleInfo.driver) then + DeleteEntity(vehicleInfo.driver) + end + end + end + + -- Alle Blips entfernen + for _, blip in pairs(stationBlips) do + RemoveBlip(blip) + end + + -- Variablen zurücksetzen + stationVehicles = {} + stationBlips = {} + + -- Stationen neu initialisieren + Wait(1000) + InitializeTaxiStations() + + lib.notify({ + title = 'Taxi Service', + description = 'Alle Taxi-Stationen wurden neu gespawnt', + type = 'success' + }) +end) + +-- Thread zum Überwachen der Tasten im Stations-Taxi +CreateThread(function() + while true do + Wait(0) + + local playerPed = PlayerPedId() + local inStationTaxi = false + local currentStationTaxi = nil + local currentStationId = nil + local currentVehicleId = nil + local currentDriver = nil + local pricePerKm = 0 + + -- Prüfen ob Spieler in einem Stations-Taxi sitzt + for stationId, vehicles in pairs(stationVehicles) do + for vehicleId, vehicleInfo in pairs(vehicles) do + if vehicleInfo.entity and DoesEntityExist(vehicleInfo.entity) and vehicleInfo.occupied then + if IsPedInVehicle(playerPed, vehicleInfo.entity, false) then + inStationTaxi = true + currentStationTaxi = vehicleInfo.entity + currentStationId = stationId + currentVehicleId = vehicleId + currentDriver = vehicleInfo.driver + pricePerKm = vehicleInfo.data.pricePerKm + break + end + end + end + if inStationTaxi then break end + end + + if inStationTaxi and currentStationTaxi then + -- Zeige Hinweise an + local helpText = '[E] - Ziel wählen [F] - Fahrt beenden' + lib.showTextUI(helpText, { + position = "top-center", + icon = 'taxi', + style = { + borderRadius = 10, + backgroundColor = '#48BB78', + color = 'white' + } + }) + + -- Wenn E gedrückt wird, öffne Menü + if IsControlJustReleased(0, 38) then -- E Taste + OpenStationTaxiMenu(currentStationId, currentVehicleId, currentStationTaxi, currentDriver, pricePerKm) + end + + -- Wenn F gedrückt wird, beende Fahrt + if IsControlJustReleased(0, 23) then -- F Taste + lib.hideTextUI() + EndStationTaxiRide(currentStationId, currentVehicleId, currentStationTaxi, currentDriver) + end + else + -- Nicht in einem Stations-Taxi + lib.hideTextUI() + Wait(1000) + end + end +end) + +-- Funktion zum Beenden der Stations-Taxi Fahrt +function EndStationTaxiRide(stationId, vehicleId, vehicle, driver) + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Ending station taxi ride") + + if not vehicle or not DoesEntityExist(vehicle) then + return + end + + local playerPed = PlayerPedId() + + -- Fahrt beenden Benachrichtigung + lib.notify({ + title = 'Taxi Service', + description = 'Fahrt beendet. Du steigst aus.', + type = 'info' + }) + + -- Spieler aussteigen lassen + TaskLeaveVehicle(playerPed, vehicle, 0) + + -- Warten bis ausgestiegen + CreateThread(function() + local timeout = GetGameTimer() + 5000 + while GetGameTimer() < timeout do + if not IsPedInVehicle(playerPed, vehicle, false) then + -- Spieler ist ausgestiegen + break + end + Wait(100) + end + + -- Taxi nach 5 Sekunden zurück zur Station + SetTimeout(5000, function() + ReturnTaxiToStation(stationId, vehicleId, vehicle, driver) + end) + end) +end + +-- Cleanup beim Resource Stop +AddEventHandler('onResourceStop', function(resourceName) + if GetCurrentResourceName() == resourceName then + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleaning up stations...") + + -- TextUI verstecken falls noch angezeigt + lib.hideTextUI() + + -- Alle Station-Fahrzeuge löschen + for stationId, vehicles in pairs(stationVehicles) do + for vehicleId, vehicleInfo in pairs(vehicles) do + if vehicleInfo.entity and DoesEntityExist(vehicleInfo.entity) then + exports['qb-target']:RemoveTargetEntity(vehicleInfo.entity) + DeleteEntity(vehicleInfo.entity) + end + if vehicleInfo.driver and DoesEntityExist(vehicleInfo.driver) then + DeleteEntity(vehicleInfo.driver) + end + end + end + + -- Alle Blips entfernen + for _, blip in pairs(stationBlips) do + RemoveBlip(blip) + end + + DebugPrint("^2[TAXI STATIONS DEBUG]^7 Cleanup completed") + end +end) + + + + + diff --git a/resources/[carscripts]/nordi_taxi/config.lua b/resources/[carscripts]/nordi_taxi/config.lua new file mode 100644 index 000000000..d5cb749ad --- /dev/null +++ b/resources/[carscripts]/nordi_taxi/config.lua @@ -0,0 +1,180 @@ +Config = {} + +Config.Debug = false -- Set to true to enable debug prints, false to disable + + +-- Taxi Fahrzeuge und Preise +Config.TaxiVehicles = { + { + model = 'taxi', + label = 'Standard Taxi', + pricePerKm = 5, + spawnChance = 80 + }, + { + model = 'vstretch', + label = 'Luxus Limousine', + pricePerKm = 15, + spawnChance = 10 + }, + { + model = 'elegyrh7', + label = 'JDM Taxi', + pricePerKm = 15, + spawnChance = 10 + }, + + +} + +-- Taxi Stationen mit festen Fahrzeugen +Config.TaxiStations = { + { + name = "Los Santos Airport Taxi", + coords = vector4(-1051.28, -2712.83, 13.68, 243.31), + blipCoords = vector3(-1051.28, -2712.83, 13.68), + vehicles = { + { + model = 'taxi', + coords = vector4(-1051.28, -2712.83, 13.68, 243.31), + pricePerKm = 5 + }, + { + model = 'taxi', + coords = vector4(-1041.38, -2718.65, 13.67, 239.73), + pricePerKm = 5 + } + } + }, + { + name = "Downtown Taxi Stand", + coords = vector4(913.97, -160.64, 74.72, 200.67), + blipCoords = vector3(913.97, -160.64, 74.72), + vehicles = { + { + model = 'taxi', + coords = vector4(913.97, -160.64, 74.72, 200.67), + pricePerKm = 5 + }, + { + model = 'taxi', + coords = vector4(899.74, -180.99, 73.86, 247.36), + pricePerKm = 5 + } + } + }, + { + name = "Paleto Bay Taxi", + coords = vector4(-339.14, 6072.48, 31.31, 225.76), + blipCoords = vector3(-339.14, 6072.48, 31.31), + vehicles = { + { + model = 'taxi', + coords = vector4(-339.14, 6072.48, 31.31, 225.76), + pricePerKm = 6 + }, + + } + }, + { + name = "Stadtpark Taxi", + coords = vector4(204.9, -846.9, 30.5, 254.69), + blipCoords = vector3(204.9, -846.9, 30.5), + vehicles = { + { + model = 'taxi', + coords = vector4(204.9, -846.9, 30.5, 254.69), + pricePerKm = 6 + }, + { + model = 'taxi', + coords = vector4(213.61, -849.66, 30.28, 248.6), + pricePerKm = 6 + } + + + + } + }, + { + name = "Vespucci Beach Taxi", + coords = vector4(-1614.7, -857.81, 10.02, 140.47), + blipCoords = vector3(-1609.67, -862.78, 10.01), + vehicles = { + { + model = 'taxi', + coords = vector4(-1614.7, -857.81, 10.02, 140.47), + pricePerKm = 5 + }, + { + model = 'vstretch', + coords = vector4(-1609.67, -862.78, 10.01, 230.02), + pricePerKm = 15 + } + } + } +} + +-- Spawn Locations für /taxi Command (mobile Taxis) +Config.MobileTaxiSpawns = { + vector4(-1013.96, -2734.56, 13.67, 246.68), + vector4(902.33, -143.8, 76.62, 327.11), + vector4(-1277.46, -810.35, 17.13, 133.23), + vector4(1705.39, 4803.73, 41.79, 91.83), + vector4(-383.43, 6064.31, 31.5, 135.49), + vector4(136.64, 6369.87, 31.37, 28.48), -- Paleto + +} + +-- Bekannte Ziele mit festen Preisen +Config.KnownDestinations = { + { + name = "Los Santos International Airport", + coords = vector3(-1037.0, -2674.0, 13.8), + price = 50 + }, + { + name = "Vinewood Hills", + coords = vector3(120.0, 564.0, 184.0), + price = 35 + }, + { + name = "Del Perro Pier", + coords = vector3(-1850.0, -1230.0, 13.0), + price = 25 + }, + { + name = "Sandy Shores", + coords = vector3(1815.27, 3649.01, 34.25), + price = 75 + }, + { + name = "Paleto Bay", + coords = vector3(-296.31, 6056.98, 31.36), + price = 100 + }, + { + name = "Mount Chiliad", + coords = vector3(501.0, 5604.0, 797.0), + price = 120 + }, + { + name = "Maze Bank Tower", + coords = vector3(-46.24, -787.47, 44.14), + price = 40 + }, + { + name = "Vespucci Beach", + coords = vector3(-1686.28, -934.24, 7.69), + price = 30 + } +} + +-- Allgemeine Einstellungen +Config.MaxWaitTime = 120 -- Sekunden bis Taxi spawnt +Config.TaxiCallCooldown = 30 -- Sekunden zwischen Taxi-Rufen +Config.MinFare = 10 -- Mindestpreis +Config.PricePerKm = 5 -- Standardpreis pro Kilometer +Config.WaitingFee = 2 -- Preis pro Minute warten +Config.StationTaxiRespawnTime = 300 -- 5 Minuten bis Taxi an Station respawnt + diff --git a/resources/[carscripts]/nordi_taxi/fxmanifest.lua b/resources/[carscripts]/nordi_taxi/fxmanifest.lua new file mode 100644 index 000000000..b7e740a2c --- /dev/null +++ b/resources/[carscripts]/nordi_taxi/fxmanifest.lua @@ -0,0 +1,26 @@ +fx_version 'cerulean' +game 'gta5' + +author 'YourName' +description 'Taxi System with ox_lib and qb-target' +version '1.0.0' + +shared_scripts { + '@ox_lib/init.lua', + 'config.lua' +} + +client_scripts { + 'client/main.lua', + 'client/stations.lua' +} + +server_scripts { + 'server/main.lua' +} + +dependencies { + 'qb-core', + 'ox_lib', + 'qb-target' +} diff --git a/resources/[carscripts]/nordi_taxi/server/main.lua b/resources/[carscripts]/nordi_taxi/server/main.lua new file mode 100644 index 000000000..8231a2081 --- /dev/null +++ b/resources/[carscripts]/nordi_taxi/server/main.lua @@ -0,0 +1,62 @@ + +function DebugPrint(type, message) + if Config.Debug then + if type == "error" then + print('^1[TAXI]^7 ' .. message) + elseif type == "warning" then + print('^3[TAXI]^7 ' .. message) + else -- success/info + print('^2[TAXI]^7 ' .. message) + end + end +end + +local QBCore = exports['qb-core']:GetCoreObject() + + +RegisterNetEvent('taxi:payFare', function(amount) + local src = source + local Player = QBCore.Functions.GetPlayer(src) + + if not Player then return end + + local playerMoney = Player.PlayerData.money.cash + + if playerMoney >= amount then + Player.Functions.RemoveMoney('cash', amount, 'taxi-fare') + TriggerClientEvent('QBCore:Notify', src, 'Du hast $' .. amount .. ' für die Taxifahrt bezahlt', 'success') + + -- Log für Admin + DebugPrint('^2[TAXI]^7 ' .. Player.PlayerData.name .. ' (' .. src .. ') hat $' .. amount .. ' für eine Taxifahrt bezahlt') + else + local bankMoney = Player.PlayerData.money.bank + if bankMoney >= amount then + Player.Functions.RemoveMoney('bank', amount, 'taxi-fare') + TriggerClientEvent('QBCore:Notify', src, 'Du hast $' .. amount .. ' per Karte für die Taxifahrt bezahlt', 'success') + + -- Log für Admin + DebugPrint('^2[TAXI]^7 ' .. Player.PlayerData.name .. ' (' .. src .. ') hat $' .. amount .. ' per Karte für eine Taxifahrt bezahlt') + else + TriggerClientEvent('QBCore:Notify', src, 'Du hast nicht genug Geld für die Taxifahrt!', 'error') + + -- Log für Admin + DebugPrint('^1[TAXI]^7 ' .. Player.PlayerData.name .. ' (' .. src .. ') konnte $' .. amount .. ' für eine Taxifahrt nicht bezahlen') + end + end +end) + +-- Admin Command zum Respawnen aller Taxi-Stationen +QBCore.Commands.Add('respawntaxis', 'Respawne alle Taxi-Stationen (Admin Only)', {}, false, function(source, args) + local Player = QBCore.Functions.GetPlayer(source) + if Player.PlayerData.job.name == 'admin' or QBCore.Functions.HasPermission(source, 'admin') then + TriggerClientEvent('taxi:respawnAllStations', -1) + TriggerClientEvent('QBCore:Notify', source, 'Alle Taxi-Stationen wurden respawnt', 'success') + else + TriggerClientEvent('QBCore:Notify', source, 'Du hast keine Berechtigung für diesen Befehl', 'error') + end +end, 'admin') + +-- Event für das Respawnen der Stationen +RegisterNetEvent('taxi:respawnAllStations', function() + -- Wird an alle Clients gesendet +end) diff --git a/resources/[tools]/cc-chat-1/.gitignore b/resources/[tools]/cc-chat-1/.gitignore new file mode 100644 index 000000000..26a0c37eb --- /dev/null +++ b/resources/[tools]/cc-chat-1/.gitignore @@ -0,0 +1,4 @@ + +build.bat +exclude.txt +.vscode/settings.json diff --git a/resources/[tools]/cc-chat-1/LICENSE b/resources/[tools]/cc-chat-1/LICENSE new file mode 100644 index 000000000..f288702d2 --- /dev/null +++ b/resources/[tools]/cc-chat-1/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/resources/[tools]/cc-chat-1/README.md b/resources/[tools]/cc-chat-1/README.md new file mode 100644 index 000000000..543b470ce --- /dev/null +++ b/resources/[tools]/cc-chat-1/README.md @@ -0,0 +1,71 @@ +

+ + + + + + Discord Status +

+ +
+ +

🎨 CC Chat - Chat Theme

+

+ CC Chat is a chat theme that includes a custom message template for FiveM's default chat resource. +
+ Discord - Documentation - Report Bug - Request Feature +

+ Discord Invite +
+ +### 🖼️ Showcase + +
+Screenshots +
+ + + +
+ +### ⚠️ Important Notice +**If CC Chat is a dependency for another resource you can ignore this notice.** + +Please note that this resource **does not include** any pre-written commands or chat messages; you will need to **create them yourself**. It is designed for people who have some experience with scripting. Only those who have some idea of what they're doing will be given support. + +### ✅ Features + +- Custom text input box +- Custom suggestions box +- A ready-to-use chat template +- Anti-spam system +- [Font Awesome](https://fontawesome.com/) icons (v6.2.1) +- Completely customisable +- Free Forever + +### 🛠 Installation +Official guide to installing **CC Chat**. + +**Dependencies** +- [Chat](https://github.com/citizenfx/cfx-server-data/tree/master/resources/%5Bgameplay%5D/chat) + +**Download** +- Download the [latest releases](https://github.com/Concept-Collective/cc-chat/releases/latest) of cc-chat. + +**Install** +- Create a new folder in your resources folder named ``cc-chat`` +- Extract the archive's contents to your ``cc-chat`` folder. +- ensure ``cc-chat`` anywhere after the default ``chat`` resource in your ``server.cfg``. + +### 🙋 Support +- [Discord](https://discord.conceptcollective.net) + +-------- +### License +For an updated license, check the ``License`` file. That file will always overrule anything mentioned in the ``readme.md`` + +cc-chat - Concept Collective + +Copyright © 2024 Concept Collective. All rights reserved. + +You can use and edit this code to your liking as long as you don't ever claim it to be your own code and always provide proper credit. You're not allowed to sell cc-chat or any code you take from it. If you want to release your own version of cc-chat, you have to link the original GitHub repo, or release it via a Forked repo. diff --git a/resources/[tools]/cc-chat-1/client/main.lua b/resources/[tools]/cc-chat-1/client/main.lua new file mode 100644 index 000000000..e6fc8c55a --- /dev/null +++ b/resources/[tools]/cc-chat-1/client/main.lua @@ -0,0 +1,23 @@ +function getTimestamp() + local meridiem = 'AM' + year , month , day , hour , minute , second = '' + if GetGameName() == 'fivem' then + year , month , day , hour , minute , second = GetLocalTime() + elseif GetGameName() == 'redm' then + year , month , day , hour , minute , second = GetPosixTime() + end + if hour >= 13 then + hour = hour - 12 + meridiem = 'PM' + end + if hour == 12 then + meridiem = 'PM' + end + if minute <= 9 then + minute = '0' .. minute + end + timestamp = hour .. ':' .. minute .. ' ' .. meridiem + return timestamp +end + +exports('getTimestamp', getTimestamp) \ No newline at end of file diff --git a/resources/[tools]/cc-chat-1/fxmanifest.lua b/resources/[tools]/cc-chat-1/fxmanifest.lua new file mode 100644 index 000000000..e3985cf5f --- /dev/null +++ b/resources/[tools]/cc-chat-1/fxmanifest.lua @@ -0,0 +1,26 @@ +version '1.4.1' +author 'Concept Collective' +description 'A chat theme for FiveM' + +lua54 'yes' + +server_script 'server/main.lua' +client_script 'client/main.lua' + +dependency 'chat' + +file 'theme/style.css' + +chat_theme 'ccChat' { + styleSheet = 'theme/style.css', + msgTemplates = { + ccChat = '

{2}

{3}


{4}

' + } +} + +exports { + 'getTimestamp' +} + +game 'common' +fx_version 'adamant' diff --git a/resources/[tools]/cc-chat-1/server/main.lua b/resources/[tools]/cc-chat-1/server/main.lua new file mode 100644 index 000000000..efc19c82f --- /dev/null +++ b/resources/[tools]/cc-chat-1/server/main.lua @@ -0,0 +1,76 @@ +local svConfig = {} + +-- Configuration + svConfig.versionChecker = true -- Version Checker + svConfig.supportChecker = true -- Support Checker (If you use exports, it is recommended that you leave this on) + +-- Script +AddEventHandler('onResourceStart', function(resourceName) + updateLogFile('Resource Started') + if (GetCurrentResourceName() ~= resourceName) then + return + end + if GetCurrentResourceName() ~= 'cc-chat' and svConfig.supportChecker == true then + print('^6[Warning]^0 For better support, it is recommended that "'..GetCurrentResourceName().. '" be renamed to "cc-chat"') + end + if svConfig.versionChecker == true then + PerformHttpRequest('https://api.github.com/repos/Concept-Collective/cc-chat/releases/latest', function (err, data, headers) + if data == nil then + print('An error occurred while checking the version. Your firewall may be blocking access to "github.com". Please check your firewall settings and ensure that "github.com" is allowed to establish connections.') + return + end + local data = json.decode(data) + if data.tag_name ~= 'v'..GetResourceMetadata(GetCurrentResourceName(), 'version', 0) then + print('\n^1================^0') + print('^1CC Chat ('..GetCurrentResourceName()..') is outdated!^0') + print('Current version: (^1v'..GetResourceMetadata(GetCurrentResourceName(), 'version', 0)..'^0)') + print('Latest version: (^2'..data.tag_name..'^0) '..data.html_url) + print('Release notes: '..data.body) + print('^1================^0') + end + end, 'GET', '') + end +end) + +AddEventHandler('chatMessage', function(source, author, message) + local formattedMessage = author .. ': ' .. message + updateLogFile(formattedMessage) +end) + +function updateLogFile(v) + if LoadResourceFile(GetCurrentResourceName(), 'chat_log.log') == nil then + SaveResourceFile(GetCurrentResourceName(), 'chat_log.log', '') + end + local logFile = LoadResourceFile(GetCurrentResourceName(), 'chat_log.log') + local logFile = logFile .. os.date("[%H:%M:%S] ") .. v .. '\n' + SaveResourceFile(GetCurrentResourceName(), 'chat_log.log', logFile) +end + +-- Antispam System (Beta) +local users = {} +function checkSpam(source, message) + local BlockedStatus = false + + -- Checks if the user has sent a message before + if users[source] == nil then + users[source] = {time = os.time()} + return false + end + + -- Check if the user has sent messages too quickly + if os.time() - users[source].time < 2 then + BlockedStatus = true + end + + -- Check if the message is a repeat of the last message + if message == users[source].lastMessage then + BlockedStatus = true + end + + -- Update the user's information in the table + users[source] = {lastMessage = message, time = os.time()} + + return BlockedStatus +end + +exports('checkSpam', checkSpam) \ No newline at end of file diff --git a/resources/[tools]/cc-chat-1/theme/style.css b/resources/[tools]/cc-chat-1/theme/style.css new file mode 100644 index 000000000..35cd57a22 --- /dev/null +++ b/resources/[tools]/cc-chat-1/theme/style.css @@ -0,0 +1,271 @@ +/* Font Awesome Import */ +@import url('https://use.fontawesome.com/releases/v6.4.0/css/all.css'); + +/* Colors */ +.color-0 {color: #ecf0f1;} +.color-1 {color: #e67e22;} +.color-2 {color: #2ecc71;} +.color-3 {color: #f1c40f;} +.color-4 {color: #2980b9;} +.color-5 {color: #3498db;} +.color-6 {color: #9b59b6;} +.color-8 {color: #e74c3c;} +.color-9 {color: #c0392b;} + +.gameColor-w {color: #ffffff;} +.gameColor-r {color: #ff4444;} +.gameColor-g {color: #99cc00;} +.gameColor-y {color: #ffbb33;} +.gameColor-b {color: #33b5e5;} + +* { + font-family: "Segoe UI", Arial, sans-serif; + src: url("../BarlowCondensed.ttf"); + margin: 0; + padding: 0; + font-size: 0.9rem; + background: #00000000; +} + +.no-grow { + flex-grow: 0; +} + +em { + font-style: normal; +} + +#app { + font-family: 'Barlow Condensed', sans-serif; + --webkit-font-smoothing: antialiased; + --moz-osx-font-smoothing: grayscale; + color: #ecf0ff; + background-color: transparent; +} + +.chat-window { + position: absolute; + top: 1.5%; + left: 0.8%; + width: 30% !important; + height: 29.9% !important; + max-width: 1000px; + background: #00000000 !important; + background-color: #00000000 !important; + --webkit-animation-duration: 2s; +} + +.chat-messages { + position: relative; + height: 95%; + font-size: 1.0rem; + margin: 1%; + + overflow-x: hidden; + overflow-y: hidden; +} + +.chat-input { + font-size: 1.65vh; + position: absolute; + + top: 2%; + left: 35%; + width: 30%; + max-width: 1000px; + box-sizing: border-box; +} + +.prefix { + opacity: 0; + height: 0px; + width: 0px; +} + +.chat-input > div.input { + position: relative; + display: flex; + align-items: stretch; + width: 100%; + min-height: 40px !important; + height: auto; + background-color: #24262a; + opacity: 85%; + border-radius: 14px; +} + +textarea { + font-size: 17; + display: block; + box-sizing: border-box; + padding: 5px; + margin-right: 5px; + margin-bottom: 7px; + margin-left: 5px; + margin-top: 7px; + color: #ffffff; + background: #00000000 !important; + background-color: #00000000 !important; + width: 50%; + border-width: 0; + min-height: 40px !important; + overflow: show; + resize: none; +} + +textarea:focus, input:focus { + outline: none; +} + +.suggestions { + margin-top: 20px; + list-style-type: none; + padding: 0px; + padding-left: 27px; + font-size: 0.9rem; + box-sizing: border-box; + color: #ffffff; + background-color: rgba(36, 38, 42, 0.85) !important; + border-radius: 14px; + width: 100%; + padding-left: 0px; + padding: 6px; + padding-bottom: 3px; +} + +.suggestion { + background-color: #17181a !important; + opacity: 100%; + border-radius: 8px; + padding: 7px; + font-weight: bold; +} + +.suggestion small { + font-size: medium; + color: #989898; +} + +.disabled { + color: #989898 !important; + background-color: rgba(252, 253, 254, 0) !important; +} +.param.disabled { + background: linear-gradient(45deg, rgba(224,224,224,1) 0%, rgba(161,161,161,1) 100%) !important; + color: #26292E !important; +} + +.param { + background: linear-gradient(45deg, rgba(255,255,255,1) 0%, rgba(223,223,223,1) 100%); + color: #26292E !important; + padding: 1px; + padding-left: 5px; + padding-right: 5px; + border-radius: 2px; + margin-right: 5px; +} + +.msg { + margin-bottom: 5px; +} + +.multiline { + margin-left: 1.5rem; + text-indent: -1.5rem; + white-space: pre-line; +} + +.help { + color: #FFFFFF; +} + +.disabled { + color: #FFFFFF; +} + +.suggestion { + margin-bottom: 5px; +} + +h1 { + font-size: 13px; + font-weight: bolder; +} + +h2 { + font-size: 13px; + font-weight: 900; +} + +p { + font-size: 15px; + font-weight:650; + margin-bottom: 2px; +} + +#notification { + display: flex; + padding: 6px; + background-color: rgba(0, 0, 0, 0.6) !important; + color: #FEFEFF; + border-radius: 14px; + max-width: 98%; + margin-bottom: 5px; + width: fit-content; + min-width: 15%; + word-wrap: break-word; +} + +#color-box { + width: 10px; + float: left; + min-height: 100%; + border-radius: 8px; + flex-shrink:0; +} + +#info { + margin-left: 10px; + width: auto; + max-width: 100%; + position: relative; + min-width: 85%; +} + +#top-info { + padding-bottom: 5px; +} + +#left-info { + float:left; + width:auto; + margin-top: 2px; +} + +#right-info{ + float:right; + width:50%; +} + +#title { + float:left; + width: auto; + padding-right: 10px; +} + +#sub-title { + float:right; + color: #C6C6C6; + padding-right: 10px; +} + +#time { + float: right; + right: 5px; + color: #C6C6C6; + margin-top: 2px; +} + +.noisy { + background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAUVBMVEWFhYWDg4N3d3dtbW17e3t1dXWBgYGHh4d5eXlzc3OLi4ubm5uVlZWPj4+NjY19fX2JiYl/f39ra2uRkZGZmZlpaWmXl5dvb29xcXGTk5NnZ2c8TV1mAAAAG3RSTlNAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEAvEOwtAAAFVklEQVR4XpWWB67c2BUFb3g557T/hRo9/WUMZHlgr4Bg8Z4qQgQJlHI4A8SzFVrapvmTF9O7dmYRFZ60YiBhJRCgh1FYhiLAmdvX0CzTOpNE77ME0Zty/nWWzchDtiqrmQDeuv3powQ5ta2eN0FY0InkqDD73lT9c9lEzwUNqgFHs9VQce3TVClFCQrSTfOiYkVJQBmpbq2L6iZavPnAPcoU0dSw0SUTqz/GtrGuXfbyyBniKykOWQWGqwwMA7QiYAxi+IlPdqo+hYHnUt5ZPfnsHJyNiDtnpJyayNBkF6cWoYGAMY92U2hXHF/C1M8uP/ZtYdiuj26UdAdQQSXQErwSOMzt/XWRWAz5GuSBIkwG1H3FabJ2OsUOUhGC6tK4EMtJO0ttC6IBD3kM0ve0tJwMdSfjZo+EEISaeTr9P3wYrGjXqyC1krcKdhMpxEnt5JetoulscpyzhXN5FRpuPHvbeQaKxFAEB6EN+cYN6xD7RYGpXpNndMmZgM5Dcs3YSNFDHUo2LGfZuukSWyUYirJAdYbF3MfqEKmjM+I2EfhA94iG3L7uKrR+GdWD73ydlIB+6hgref1QTlmgmbM3/LeX5GI1Ux1RWpgxpLuZ2+I+IjzZ8wqE4nilvQdkUdfhzI5QDWy+kw5Wgg2pGpeEVeCCA7b85BO3F9DzxB3cdqvBzWcmzbyMiqhzuYqtHRVG2y4x+KOlnyqla8AoWWpuBoYRxzXrfKuILl6SfiWCbjxoZJUaCBj1CjH7GIaDbc9kqBY3W/Rgjda1iqQcOJu2WW+76pZC9QG7M00dffe9hNnseupFL53r8F7YHSwJWUKP2q+k7RdsxyOB11n0xtOvnW4irMMFNV4H0uqwS5ExsmP9AxbDTc9JwgneAT5vTiUSm1E7BSflSt3bfa1tv8Di3R8n3Af7MNWzs49hmauE2wP+ttrq+AsWpFG2awvsuOqbipWHgtuvuaAE+A1Z/7gC9hesnr+7wqCwG8c5yAg3AL1fm8T9AZtp/bbJGwl1pNrE7RuOX7PeMRUERVaPpEs+yqeoSmuOlokqw49pgomjLeh7icHNlG19yjs6XXOMedYm5xH2YxpV2tc0Ro2jJfxC50ApuxGob7lMsxfTbeUv07TyYxpeLucEH1gNd4IKH2LAg5TdVhlCafZvpskfncCfx8pOhJzd76bJWeYFnFciwcYfubRc12Ip/ppIhA1/mSZ/RxjFDrJC5xifFjJpY2Xl5zXdguFqYyTR1zSp1Y9p+tktDYYSNflcxI0iyO4TPBdlRcpeqjK/piF5bklq77VSEaA+z8qmJTFzIWiitbnzR794USKBUaT0NTEsVjZqLaFVqJoPN9ODG70IPbfBHKK+/q/AWR0tJzYHRULOa4MP+W/HfGadZUbfw177G7j/OGbIs8TahLyynl4X4RinF793Oz+BU0saXtUHrVBFT/DnA3ctNPoGbs4hRIjTok8i+algT1lTHi4SxFvONKNrgQFAq2/gFnWMXgwffgYMJpiKYkmW3tTg3ZQ9Jq+f8XN+A5eeUKHWvJWJ2sgJ1Sop+wwhqFVijqWaJhwtD8MNlSBeWNNWTa5Z5kPZw5+LbVT99wqTdx29lMUH4OIG/D86ruKEauBjvH5xy6um/Sfj7ei6UUVk4AIl3MyD4MSSTOFgSwsH/QJWaQ5as7ZcmgBZkzjjU1UrQ74ci1gWBCSGHtuV1H2mhSnO3Wp/3fEV5a+4wz//6qy8JxjZsmxxy5+4w9CDNJY09T072iKG0EnOS0arEYgXqYnXcYHwjTtUNAcMelOd4xpkoqiTYICWFq0JSiPfPDQdnt+4/wuqcXY47QILbgAAAABJRU5ErkJggg==); +} \ No newline at end of file