Transport Fever 2

Transport Fever 2

Create your own game world!
Give your game a personal touch and change it to your liking. Create, share and install mods. Customize the game with new landscapes, vehicles, stations, assets and more.
How do you enable track editing for a station mod?
I downloaded this mod recently
https://steamhost.cn/steamcommunity_com/app/1066780/discussions/0/6760560470126495811/

The problem is that I want to use different track types and catenary for different sections of the station, but when I click "Configure" in the game, the only option I get is to delete the station. With other stations I can usually select the track types I want to use. I have located the folder where this mod is stored. What file do I need to make changes to in order to get access to track editing or what piece of code should I look for?

I am looking at the con file in res > construction > station > rail

This is what I get regarding track types:

-- currently the following types are supported:
--
-- type = "track":
-- guess what - represents a track and currently has no properties.
--
-- type = "platform":
-- a platform with the following properties:

-- width: numeric, required
-- width of the platform
--
-- terminal: numeric, optional, default = 2
-- number of terminals. One-sided platforms require one terminal,
-- two-sided platforms require two terminals. A platform with
-- zero terminals can not be added to a line.
--
-- isOnLeftSide: boolean, optional, default = false
-- true is required if the layout element is a platform, followed
-- by the corresponding track. This is the case if the first layout
-- element is a platform or for any one-sided platform, which precedes its track.
--
-- reverse: boolean, optional, default = false
-- turns the platform around the z-axis. Usefull for symetric
-- platform layouts to reuse one layout for the first and the last platform.
--
-- platformLayouts: list
-- the corresponding platform layouts for the available station lengths (see above).
--
-- type = "lastPlatform":
-- defines the last platform to use when the number of tracks has been reached with
-- the following properties:
--
-- even: platform - the platform to use for an even number of tracks.
-- odd: platform - the platform to use for an odd number of tracks.
--
-- The first element defines the origin of the coordinate system for the station.
-- The middle of width defines x = 0, middle of length y = 0.

trackLayout = {
{ type = "platform", width = 12, terminals = 1, isOnLeftSide = true, platformLayouts = firstPlatformLayouts },
{ type = "track" , }, -- track 1
{ type = "track" , }, -- track 2
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , }, -- track 3
{ type = "track" , }, -- track 4
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , }, -- track 5 and so on...
{ type = "track" , },
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , },
{ type = "track" , },
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , },
{ type = "track" , },
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , },
{ type = "track" , },
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , },
{ type = "track" , },
{ type = "platform", width = 12, platformLayouts = middlePlatformLayouts },
{ type = "track" , },
{ type = "track" , },
-- must always be the last entry when used. Contains last platform for even and/or odd number of tracks:
{ type = "lastPlatform",
even = { type = "platform", width = 12, terminals = 1, platformLayouts = lastPlatformLayouts },
},
}

And this

function data()

local config = {
-- height of planum
baseHeight = 0,

-- controls the terrain alignment when baseHeight > 0
alignTerrain = false,

-- length of one platform segment
segmentLength = 40,

-- available station sizes in number of segments
availableSizes = {
4, 6, 8, 10, 12 -- 160m, 240m, 320m, 400m, 480m
},

-- available number of tracks
availableNumberOfTracks = {
2, 4, 6, 8, 10, 12, 14, 16, 18, 20
},

trackTypes = { "standard.lua", "high_speed.lua" },
--streetType = "standard/country_medium_new.lua",
--streetType = "standard/town_medium_new.lua",
streetType = "standard/town_small_new.lua",

modelPath = "station/train/mz_liege/",

-- TF-compatibility
modelRotation = 90, -- rotate all TF-models
lengthEndSegment = 14, -- size of platform end parts in Train Fever^^, default = 0

-- list of available layouts for the station. Liege only has one
trackLayouts = {
trackLayout,
},

-- called after the layout is finished to place buildings and street connections.
-- The third parameter of the function "StationBuilder.placeBuilding" has the following structur:
-- the model to place
-- building: string, required - filename of the model
-- x: numeric, optional, default = 0 - x position (coordinate system of the station)
-- y: numeric, optional, default = 0 - the y position
-- groundFace: rectangle(left, top, length, width)
-- optional - allign terrain area. If fill = true the area is filled with industry concrete
-- street: vector, optional - defines a street connection
finishStation = function(params, config, result)
local terminalGroups = result.terminalGroups
terminalGroups[#terminalGroups + 1] = { terminals = {{ #result.models, 0 }} }
StationBuilder.placeBuilding(
config, result,
{
--building = "tom_mz_liege.mdl", x = config.stationX - .5,
--groundFace = { left = config.stationX - .5 - 33, top = -14 / 2, length = 14, width = 33, fill = false },
--street = { x = config.stationX - .5 - 33, y = 0, length = -20 },
building = "tom_mz_liege.mdl", x = config.stationX + 2,
--ok groundFace = { left = config.stationX + 2 - 33, top = -14*4 , length = 14*8, width = 33, fill = true },
groundFace = { left = config.stationX + 2 - 33, top = -14*5 , length = 14*10, width = 33, fill = true },
street = { x = config.stationX + 2 - 33, y = 0, length = -20 },
}
)
terminalGroups[#terminalGroups + 1] = { terminals = {{ #result.models, 0 }} }
StationBuilder.placeBuilding(
config, result,
{
--building = "tom_mz_liege.mdl", x = config.stationXEnd + .5, rotateZ = -90,
--groundFace = { left = config.stationXEnd + .5, top = -14 / 2, length = 14, width = 33, fill = false },
--street = { x = config.stationXEnd + .5 + 33, y = 0, length = 20 },
building = "tom_mz_liege.mdl", x = config.stationXEnd + 3, rotateZ = -90,
--ok groundFace = { left = config.stationXEnd + 3 - 33, top = -14*4 , length = 14*8, width = 66, fill = true },
groundFace = { left = config.stationXEnd + 3 - 33, top = -14*5 , length = 14*10, width = 66, fill = true },
street = { x = config.stationXEnd + 3 + 33, y = 0, length = 20 },
}
)
end
}
< >
Showing 1-1 of 1 comments
RadiKyle 6 14 Nov, 2024 @ 6:57am 
Hi, I replied yesterday and now it's gone, odd...

How deep do you want to get into coding this?

This is an older non-modular station mod that pre-dates modular stations. For *modular* stations, they all generally work the same way (at least ones based on the vanilla modular codebase) and will automatically make all tracks types available. A few earlier modular station mods are still limited to "static" tracks only (ie, ones having track .module files), however my mod here unlocks many of those mods to work with any track type:
https://mod.io/g/transportfever2/m/unlock-platform-tracks

*Non-modular* / custom station mods however are a different beast, as there are many ways they can be coded. Some mods have custom script code that use API calls to find all track types loaded in the session and makes them available in a dropdown list in the station Configure options. Others simply hard-code a list of track types to choose from.

Based on the code snippets you posted, this mod appears to be one of the latter, specifically:
trackTypes = { "standard.lua", "high_speed.lua" },
appears to be one of the station options in the .con file for the list of available track types. Currently it has only the 2 vanilla track types (presumably there's another option there in the .con file for the catenary yes/no).

So if you just want something quick and dirty, you could try simply adding the .lua name of other track types you want to use to that list:
trackTypes = { "standard.lua", "high_speed.lua", "some_other_track_mod.lua", },
Whether or not this works depends on how robustly the mod is coded. You obviously need to make sure the other track mod(s) in question are also enabled at the same time -- basically you've just created a dependency.

If it works you'll see the other track types in the station Configure options menu. If not you might get errors and/or a crash. Experimentation is the easiest way to find out. Make a copy of the mod in your staging_area folder so you can edit it without buggering up the official version. Make sure to load the correct version when loading your test map.

A bit more sophisticated would be to create a separate mod that runs an addModifier in runFn on that station mod's .con file to add the extra track types, that way you're not messing in the code of the original mod, which could cause conflicts with other mods out there.

If instead you want to add all track types to that mod, that's a bunch more coding. I'd try attacking it with an addModifier on the .con file options, and using API commands to build the track selection list dynamically, with a bunch of filters in place for all the "hidden" trackTypes created by other mods doing similar (there are quite a few). Plus I'd simply look at how other mods have done it for ideas.

I think it's not overly complicated code, but depending on your current experience with TpF2 modding and coding in general, it may need a little or a lot of learning/experimenting.
Last edited by RadiKyle; 14 Nov, 2024 @ 6:59am
< >
Showing 1-1 of 1 comments
Per page: 1530 50