forked from Simnation/Main
ed
This commit is contained in:
parent
22e4719062
commit
d714c6bb8b
2 changed files with 98 additions and 42 deletions
|
@ -11,7 +11,7 @@ local waitingForTrain = false
|
||||||
|
|
||||||
-- Beim Laden des Scripts
|
-- Beim Laden des Scripts
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
Wait(1000) -- Kurz warten bis alles geladen ist
|
Wait(1000)
|
||||||
CreateStationBlips()
|
CreateStationBlips()
|
||||||
print("^2[TRAIN] Blips erstellt^7")
|
print("^2[TRAIN] Blips erstellt^7")
|
||||||
end)
|
end)
|
||||||
|
@ -316,7 +316,6 @@ function BoardTrain(train, station)
|
||||||
duration = Config.Notifications.duration.medium
|
duration = Config.Notifications.duration.medium
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Hier würde die normale Zugfahrt-Logik weitergehen
|
|
||||||
-- Für jetzt einfach nach 10 Sekunden wieder aussteigen lassen
|
-- Für jetzt einfach nach 10 Sekunden wieder aussteigen lassen
|
||||||
SetTimeout(10000, function()
|
SetTimeout(10000, function()
|
||||||
TaskLeaveVehicle(playerPed, train, 0)
|
TaskLeaveVehicle(playerPed, train, 0)
|
||||||
|
@ -340,41 +339,81 @@ function BoardTrain(train, station)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Zug spawnen
|
-- KORRIGIERTE Zug Spawn-Funktion
|
||||||
function SpawnTrainAtLocation(spawnPoint)
|
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)
|
-- Alle Models vorladen
|
||||||
while not HasModelLoaded(model) do
|
local mainModel = GetHashKey(Config.TrainCars.main)
|
||||||
Wait(500)
|
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
|
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)
|
local train = CreateMissionTrain(24, spawnPoint.x, spawnPoint.y, spawnPoint.z, true)
|
||||||
|
|
||||||
if DoesEntityExist(train) then
|
if DoesEntityExist(train) then
|
||||||
|
print("^2[TRAIN] Zug erfolgreich erstellt, ID: " .. train .. "^7")
|
||||||
|
|
||||||
SetEntityHeading(train, spawnPoint.w)
|
SetEntityHeading(train, spawnPoint.w)
|
||||||
SetTrainSpeed(train, 0.0)
|
SetTrainSpeed(train, 0.0)
|
||||||
SetTrainCruiseSpeed(train, 0.0)
|
SetTrainCruiseSpeed(train, 0.0)
|
||||||
|
|
||||||
-- Waggons hinzufügen
|
-- Waggons hinzufügen (nur die erfolgreich geladenen)
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
Wait(1000)
|
Wait(2000) -- Länger warten
|
||||||
for _, carModel in pairs(Config.TrainCars.cars) do
|
|
||||||
local carHash = GetHashKey(carModel)
|
for _, carHash in pairs(carModels) do
|
||||||
RequestModel(carHash)
|
print("^3[TRAIN] Füge Waggon hinzu: " .. carHash .. "^7")
|
||||||
while not HasModelLoaded(carHash) do
|
local success = CreateMissionTrainCar(train, carHash, false, false, false)
|
||||||
Wait(500)
|
if success then
|
||||||
|
print("^2[TRAIN] Waggon erfolgreich hinzugefügt^7")
|
||||||
|
else
|
||||||
|
print("^1[TRAIN] Fehler beim Hinzufügen des Waggons^7")
|
||||||
end
|
end
|
||||||
CreateMissionTrainCar(train, carHash, false, false, false)
|
Wait(1000)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return train
|
return train
|
||||||
end
|
else
|
||||||
|
print("^1[TRAIN] CreateMissionTrain fehlgeschlagen^7")
|
||||||
return nil
|
return nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Hilfsfunktionen
|
-- Hilfsfunktionen (bleiben gleich)
|
||||||
function GetStationById(id)
|
function GetStationById(id)
|
||||||
for _, station in pairs(Config.TrainStations) do
|
for _, station in pairs(Config.TrainStations) do
|
||||||
if station.id == id then
|
if station.id == id then
|
||||||
|
@ -388,10 +427,9 @@ function CalculatePrice(fromStation, toStation)
|
||||||
local distance = GetDistanceBetweenStations(fromStation, toStation)
|
local distance = GetDistanceBetweenStations(fromStation, toStation)
|
||||||
local price = Config.PriceCalculation.basePrice + (distance * Config.PriceCalculation.pricePerKm / 100)
|
local price = Config.PriceCalculation.basePrice + (distance * Config.PriceCalculation.pricePerKm / 100)
|
||||||
|
|
||||||
-- Kostenlose Stationen prüfen
|
|
||||||
for _, freeStation in pairs(Config.PriceCalculation.freeStations) do
|
for _, freeStation in pairs(Config.PriceCalculation.freeStations) do
|
||||||
if fromStation.id == freeStation then
|
if fromStation.id == freeStation then
|
||||||
price = price * 0.5 -- 50% Rabatt
|
price = price * 0.5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -458,6 +496,19 @@ RegisterCommand('traintest', function()
|
||||||
end
|
end
|
||||||
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
|
-- Cleanup
|
||||||
AddEventHandler('onResourceStop', function(resourceName)
|
AddEventHandler('onResourceStop', function(resourceName)
|
||||||
if GetCurrentResourceName() == resourceName then
|
if GetCurrentResourceName() == resourceName then
|
||||||
|
|
|
@ -1,42 +1,53 @@
|
||||||
Config = {}
|
Config = {}
|
||||||
|
|
||||||
-- Allgemeine Einstellungen
|
-- Debug aktivieren
|
||||||
Config.Debug = false
|
Config.Debug = true
|
||||||
Config.DefaultCurrency = 'cash'
|
Config.DefaultCurrency = 'cash'
|
||||||
Config.InteractionDistance = 5.0
|
Config.InteractionDistance = 5.0
|
||||||
Config.StationInteractionDistance = 3.0
|
Config.StationInteractionDistance = 10.0
|
||||||
|
|
||||||
-- Zug Ankunft Einstellungen
|
-- Zug Ankunft Einstellungen
|
||||||
Config.TrainArrival = {
|
Config.TrainArrival = {
|
||||||
enabled = true,
|
enabled = true,
|
||||||
spawnDistance = 500.0, -- Entfernung von wo der Zug spawnt
|
spawnDistance = 500.0,
|
||||||
approachSpeed = 15.0, -- Geschwindigkeit beim Heranfahren
|
approachSpeed = 15.0,
|
||||||
arrivalSpeed = 5.0, -- Geschwindigkeit bei Ankunft
|
arrivalSpeed = 5.0,
|
||||||
waitTime = 30000, -- Wartezeit am Bahnhof (30 Sekunden)
|
waitTime = 30000,
|
||||||
despawnAfterWait = true -- Zug nach Wartezeit löschen wenn niemand einsteigt
|
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 = {
|
Config.TrainStations = {
|
||||||
{
|
{
|
||||||
id = "sandy_depot",
|
id = "sandy_depot",
|
||||||
coords = vector4(2533.0, 2833.0, 38.0, 0.0),
|
coords = vector4(2533.0, 2833.0, 38.0, 0.0),
|
||||||
name = "Sandy Shores Depot",
|
name = "Sandy Shores Depot",
|
||||||
description = "Hauptdepot in Sandy Shores",
|
description = "Hauptdepot in Sandy Shores",
|
||||||
|
|
||||||
-- Spawn-Punkt für ankommende Züge (weiter entfernt)
|
|
||||||
trainSpawnPoint = vector4(2033.0, 2833.0, 38.0, 0.0),
|
trainSpawnPoint = vector4(2033.0, 2833.0, 38.0, 0.0),
|
||||||
|
|
||||||
-- Interaktionspunkt für Spieler
|
|
||||||
interactionPoint = vector3(2535.0, 2835.0, 38.0),
|
interactionPoint = vector3(2535.0, 2835.0, 38.0),
|
||||||
|
|
||||||
blip = {
|
blip = {
|
||||||
sprite = 795,
|
sprite = 795,
|
||||||
color = 2,
|
color = 2,
|
||||||
scale = 0.8
|
scale = 0.8
|
||||||
},
|
},
|
||||||
|
|
||||||
-- Verfügbare Ziele von diesem Bahnhof
|
|
||||||
destinations = {
|
destinations = {
|
||||||
"sandy_north", "ls_depot", "elysian", "terminal", "downtown", "paleto"
|
"sandy_north", "ls_depot", "elysian", "terminal", "downtown", "paleto"
|
||||||
}
|
}
|
||||||
|
@ -144,13 +155,7 @@ Config.PriceCalculation = {
|
||||||
basePrice = 25,
|
basePrice = 25,
|
||||||
pricePerKm = 0.5,
|
pricePerKm = 0.5,
|
||||||
maxPrice = 300,
|
maxPrice = 300,
|
||||||
freeStations = {"sandy_depot"} -- Kostenlose Startbahnhöfe
|
freeStations = {"sandy_depot"}
|
||||||
}
|
|
||||||
|
|
||||||
-- Zug Konfiguration
|
|
||||||
Config.TrainCars = {
|
|
||||||
main = "freight",
|
|
||||||
cars = {"freightcar", "freightcont1", "freightgrain"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Menü Einstellungen
|
-- Menü Einstellungen
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue