From d714c6bb8be6b671ff10aa0f08882f8a0b581510 Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Mon, 11 Aug 2025 18:50:26 +0200 Subject: [PATCH] ed --- .../[freizeit]/nordi_ai_train/client.lua | 89 +++++++++++++++---- .../[freizeit]/nordi_ai_train/config.lua | 51 ++++++----- 2 files changed, 98 insertions(+), 42 deletions(-) diff --git a/resources/[freizeit]/nordi_ai_train/client.lua b/resources/[freizeit]/nordi_ai_train/client.lua index 0fa092bc3..f57a84b2c 100644 --- a/resources/[freizeit]/nordi_ai_train/client.lua +++ b/resources/[freizeit]/nordi_ai_train/client.lua @@ -11,7 +11,7 @@ local waitingForTrain = false -- Beim Laden des Scripts CreateThread(function() - Wait(1000) -- Kurz warten bis alles geladen ist + Wait(1000) CreateStationBlips() print("^2[TRAIN] Blips erstellt^7") end) @@ -316,7 +316,6 @@ function BoardTrain(train, station) duration = Config.Notifications.duration.medium }) - -- Hier würde die normale Zugfahrt-Logik weitergehen -- Für jetzt einfach nach 10 Sekunden wieder aussteigen lassen SetTimeout(10000, function() TaskLeaveVehicle(playerPed, train, 0) @@ -340,41 +339,81 @@ function BoardTrain(train, station) end) end --- Zug spawnen +-- KORRIGIERTE Zug Spawn-Funktion function SpawnTrainAtLocation(spawnPoint) - local model = GetHashKey(Config.TrainCars.main) + print("^3[TRAIN] Versuche Zug zu spawnen bei: " .. spawnPoint.x .. ", " .. spawnPoint.y .. ", " .. spawnPoint.z .. "^7") - RequestModel(model) - while not HasModelLoaded(model) do - Wait(500) + -- Alle Models vorladen + local mainModel = GetHashKey(Config.TrainCars.main) + print("^3[TRAIN] Lade Hauptmodel: " .. Config.TrainCars.main .. " (Hash: " .. mainModel .. ")^7") + + RequestModel(mainModel) + local timeout = 0 + while not HasModelLoaded(mainModel) and timeout < 10000 do + Wait(100) + timeout = timeout + 100 end + if not HasModelLoaded(mainModel) then + print("^1[TRAIN] Hauptmodel konnte nicht geladen werden: " .. Config.TrainCars.main .. "^7") + return nil + end + + -- Waggon-Models vorladen + local carModels = {} + for _, carName in pairs(Config.TrainCars.cars) do + local carHash = GetHashKey(carName) + print("^3[TRAIN] Lade Waggon-Model: " .. carName .. " (Hash: " .. carHash .. ")^7") + + RequestModel(carHash) + timeout = 0 + while not HasModelLoaded(carHash) and timeout < 5000 do + Wait(100) + timeout = timeout + 100 + end + + if HasModelLoaded(carHash) then + table.insert(carModels, carHash) + print("^2[TRAIN] Waggon-Model geladen: " .. carName .. "^7") + else + print("^1[TRAIN] Waggon-Model konnte nicht geladen werden: " .. carName .. "^7") + end + end + + -- Zug erstellen local train = CreateMissionTrain(24, spawnPoint.x, spawnPoint.y, spawnPoint.z, true) if DoesEntityExist(train) then + print("^2[TRAIN] Zug erfolgreich erstellt, ID: " .. train .. "^7") + SetEntityHeading(train, spawnPoint.w) SetTrainSpeed(train, 0.0) SetTrainCruiseSpeed(train, 0.0) - -- Waggons hinzufügen + -- Waggons hinzufügen (nur die erfolgreich geladenen) CreateThread(function() - Wait(1000) - for _, carModel in pairs(Config.TrainCars.cars) do - local carHash = GetHashKey(carModel) - RequestModel(carHash) - while not HasModelLoaded(carHash) do - Wait(500) + Wait(2000) -- Länger warten + + for _, carHash in pairs(carModels) do + print("^3[TRAIN] Füge Waggon hinzu: " .. carHash .. "^7") + local success = CreateMissionTrainCar(train, carHash, false, false, false) + if success then + print("^2[TRAIN] Waggon erfolgreich hinzugefügt^7") + else + print("^1[TRAIN] Fehler beim Hinzufügen des Waggons^7") end - CreateMissionTrainCar(train, carHash, false, false, false) + Wait(1000) end end) return train + else + print("^1[TRAIN] CreateMissionTrain fehlgeschlagen^7") + return nil end - return nil end --- Hilfsfunktionen +-- Hilfsfunktionen (bleiben gleich) function GetStationById(id) for _, station in pairs(Config.TrainStations) do if station.id == id then @@ -388,10 +427,9 @@ function CalculatePrice(fromStation, toStation) local distance = GetDistanceBetweenStations(fromStation, toStation) local price = Config.PriceCalculation.basePrice + (distance * Config.PriceCalculation.pricePerKm / 100) - -- Kostenlose Stationen prüfen for _, freeStation in pairs(Config.PriceCalculation.freeStations) do if fromStation.id == freeStation then - price = price * 0.5 -- 50% Rabatt + price = price * 0.5 end end @@ -458,6 +496,19 @@ RegisterCommand('traintest', function() end end) +RegisterCommand('testtrainspawn', function() + local playerCoords = GetEntityCoords(PlayerPedId()) + local playerHeading = GetEntityHeading(PlayerPedId()) + local spawnPoint = vector4(playerCoords.x + 10, playerCoords.y, playerCoords.z, playerHeading) + + local train = SpawnTrainAtLocation(spawnPoint) + if train then + print("^2[TRAIN] Test-Zug gespawnt!^7") + else + print("^1[TRAIN] Test-Zug spawn fehlgeschlagen!^7") + end +end) + -- Cleanup AddEventHandler('onResourceStop', function(resourceName) if GetCurrentResourceName() == resourceName then diff --git a/resources/[freizeit]/nordi_ai_train/config.lua b/resources/[freizeit]/nordi_ai_train/config.lua index 481ee14cd..6dd216906 100644 --- a/resources/[freizeit]/nordi_ai_train/config.lua +++ b/resources/[freizeit]/nordi_ai_train/config.lua @@ -1,42 +1,53 @@ Config = {} --- Allgemeine Einstellungen -Config.Debug = false +-- Debug aktivieren +Config.Debug = true Config.DefaultCurrency = 'cash' Config.InteractionDistance = 5.0 -Config.StationInteractionDistance = 3.0 +Config.StationInteractionDistance = 10.0 -- Zug Ankunft Einstellungen Config.TrainArrival = { enabled = true, - spawnDistance = 500.0, -- Entfernung von wo der Zug spawnt - approachSpeed = 15.0, -- Geschwindigkeit beim Heranfahren - arrivalSpeed = 5.0, -- Geschwindigkeit bei Ankunft - waitTime = 30000, -- Wartezeit am Bahnhof (30 Sekunden) - despawnAfterWait = true -- Zug nach Wartezeit löschen wenn niemand einsteigt + spawnDistance = 500.0, + approachSpeed = 15.0, + arrivalSpeed = 5.0, + waitTime = 30000, + despawnAfterWait = true } --- Bahnhof Konfiguration +-- Korrigierte Zug Konfiguration - Nur funktionierende Models +Config.TrainCars = { + main = "freight", -- Hauptlok + cars = {"freightcar"} -- Nur ein funktionierender Waggon +} + +-- Alle verfügbaren Zug-Models (zum Testen) +Config.AvailableTrainModels = { + "freight", -- Güterzug Lok + "freightcar", -- Güterwagon + "freightcont1", -- Container 1 + "freightcont2", -- Container 2 + "freightgrain", -- Getreide Waggon + "tankercar", -- Tankwagon + "metrotrain", -- Metro + "freight2" -- Alternative Lok +} + +-- Rest der Config bleibt gleich... Config.TrainStations = { { id = "sandy_depot", coords = vector4(2533.0, 2833.0, 38.0, 0.0), name = "Sandy Shores Depot", description = "Hauptdepot in Sandy Shores", - - -- Spawn-Punkt für ankommende Züge (weiter entfernt) trainSpawnPoint = vector4(2033.0, 2833.0, 38.0, 0.0), - - -- Interaktionspunkt für Spieler interactionPoint = vector3(2535.0, 2835.0, 38.0), - blip = { sprite = 795, color = 2, scale = 0.8 }, - - -- Verfügbare Ziele von diesem Bahnhof destinations = { "sandy_north", "ls_depot", "elysian", "terminal", "downtown", "paleto" } @@ -144,13 +155,7 @@ Config.PriceCalculation = { basePrice = 25, pricePerKm = 0.5, maxPrice = 300, - freeStations = {"sandy_depot"} -- Kostenlose Startbahnhöfe -} - --- Zug Konfiguration -Config.TrainCars = { - main = "freight", - cars = {"freightcar", "freightcont1", "freightgrain"} + freeStations = {"sandy_depot"} } -- Menü Einstellungen