1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-11 18:50:26 +02:00
parent 22e4719062
commit d714c6bb8b
2 changed files with 98 additions and 42 deletions

View file

@ -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