Transport Fever 2

Transport Fever 2

Not enough ratings
Random Road Number Mod
By themeatballhero
Addresses for modders how to incorporate and how the random number mod works.
   
Award
Favorite
Favorited
Unfavorite
Introduction & Basics
Random numbers is a low resource cost solution to cleaning up the buy menu while adding more realism to your consists. Essentially, it costs almost nothing to clean up your buy menu.

The mod runs off small texture files around 250kb with 10 different cube meshes. Each is UVed next to each other for different numbers. In the code, it uses custom loads in the mdl to achieve this.

The PSD is in two places, one listed below:
https://drive.google.com/drive/folders/1ZE_A-mS-AStn258zV1IO2P1SxaxmRzGf usp=share_link

and in the mod folder (ID: 2913933660). My google drive also contains a .blend file and obj containing the needed mesh files for modders to incorporate and easily access values for rotations and scaling and transforms needed for the custom cargo slots in the vehicle's mdl.

To make it easier for the modder, I've also made a zip folder which contain all the necessary files to include in your mod (materials, meshes, example .mdl file - the gulf tanker one - and base textures that you may need).

There's also a separate zip file template for the E8 numberboards. That will be discussed in a separate section. Both zip files will be needed when making random numbers for the E8s!

As of now, I am requesting that you do not use dependencies for your random numbers anymore. Include all the random number meshes & textures inside your mod. Just make your MDL files for the fonts unique enough where they won't conflict with other mods.

You can copy those files to your mod and use as you wish. Just change the pathing on the materials and mdl's to prevent someone else messing up your mod. (IE using the original path but they changed their mtl file to use a different color).

To make your own fonts, use the PSDs listed here:
https://drive.google.com/drive/folders/1ZE_A-mS-AStn258zV1IO2P1SxaxmRzGf?usp=sharing

In the Photoshop section I cover how to make your own fonts.
Textures & the UV Map

Above is an example of the font using the rroman font. It uses a blank background with the color white chosen for the font. You can change the color of the font to your liking in your image editing program. Personally, I use photoshop. Photopea.com, paint.net and gimp are other programs as well that can open PSD files.

As you can see, the numbers are arranged in a way for each mesh to read the texture. The image size is 1024x256.

Meshes 0-9 are each individually UVed to their respective number position on the image. So each mesh may look the same, but the UV mapping is different.

These images must be interpolated alpha (dxt5/bc3) with the transparent background.
The walls are indicated below:

PSD Overview
To the right is the structure of each font.

First, we have the emissive mask used for lit numberboards on locomotives or other various uses.

For this you will need a large mesh (#1), behind the numbers meshes (#2).
#1 will be an emissive type material, and preferably a separate object, so you can duplicate it in your mdl for when they're not lit. When its not lit, you'll need mesh #1 to be white/the color of your choice for the numberboard digits. I'll cover this more in the MDL section.

To better match the shading of the locomotive, I suggest getting a color sample over the desired color on the finished vehicle albedo.

I also strongly suggest making a selection in your image editing software and copying an area where the number will be located approximately:

Then in the random number PSD pasting it and stretching it to the canvas, like below:

I should note I use Photoshop, so I'm not aware if clipping masks are a feature offered in Gimp or paint.net. If not, you will have to come up with another method or just ditch the grunge. Photopea.com may have it however, its very close to the UI of PS.

Shout out to Logan/YeastCheese for sending me those grunge textures.
Folder Structure
This is important because going forward, we need to think of all the different font materials that will be used over time.

The MTL folder structure should be used as below:
/res/models/material/meatball/loads/fonts/[font name]_[font color].mtl

For the font color section I would recommend the generic color name (yellow) and the hexdecimal color. So ie: cityof_yellow_febd11

The MDL structure:
/res/models/model/vehicle/waggon/fonts/[font name]/[font color]/[mdl files]

Meshes should not be included in your mod, require the base set for your mod as a dependency.
Emissive (Lit) Numberboards
First, lets set up your numberboard emissive meshes. If your vehicle doesn't have numberboards, you can skip ahead to the next section.

Its important for this step, so the numberboard numbers don't light up when the vehicle isnt in lead.

{--model ID #1, ID added for example, not true ID every time. See model tab in model editor model ID materials = { "[your name]/[mod name]/[other folders]/numberboard_background_emmissive.mtl", }, mesh = "[path to your numberboard background mesh]", name = "Lit Numberboard", transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, }, {--model ID #2 materials = { "[your name]/[mod name]/[other folders]/numberboard_background_physical.mtl", }, mesh = "[path to your numberboard background mesh, should be same as above]", name = "Unlit Numberboard", transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, }, {--model ID #3 [see next section on parent IDs] [this would be the parent for the emissive/lit numbers] }, {--model ID #4 [see next section on parent IDs] [this would be the parent for the unlit numbers] },

In the railVehicle section, you'll need to edit the below:
railVehicle = { -- other configurations configs = { { -- other configurations frontForwardParts = { 1,3 }, innerForwardParts = { 4, }, backForwardParts = { }, frontBackwardParts = { }, innerBackwardParts = { }, backBackwardParts = { },--duplicate the IDs from frontForwardParts if you plan on having the locomotive facing reverse in the rear of the train when the train is reversible } } }

model ID #2 is always present, regardless of locomotive position. The polygon offset section of the emissive material handles this.

For curved numberboards, like on the E8, it is my personal goal as a model creator to make separate meshes for these instances. This would then change the mesh section of that model.
Number Parent IDs
Parent IDs are empties in the code with no mesh or materials assigned to them. These will rotate and scale each section/individual road number appropriately. So rather than moving each individual slot in the slotProvider (look further down for more info), you can move this in the model editor under the 'MODEL' tab.

In the model window, you will get ID #s, and if you drag out the window, an icon will appear on the right hand side. Click that and you can move, scale and rotate the entire location/size of the numbers.

This also standardizes the locations of the numbers in the slotProvider section, so editing that section becomes a breeze. Do keep in mind, on curved models, like the end of tank cars, will require a bit of editing and playing with the locations in model editor.

The model editor only edits on a hundredth of a meter, so if you need something more precise, you'll need to manually change the metadata slotProvider section in your code editor like Notepad++.


So first, lets take a look at this bit:
{ name = "random number side 1", transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1.6310000419617, 0, 1, }, }, { name = "random number side 2", transf = { -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, -1.6310000419617, 0, 1, }, }, { name = "random number side 3", transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 6.3000001907349, 0, 0, 1, }, }, { name = "random number side 4", transf = { 1, 0, 0, 0, -0, 1, 0, 0, 0, -0, 1, 0, -6.3000001907349, 0, 0, 1, }, },

Assuming you have one road number per a 4 sided vehicle, you create a parent ID in the code. Each one is rotated for their respective side. You can configure the rotation easily via the model section in the model editor.

You can add as many parent IDs as you need, for instance if your unit is like Union Pacific's GP9s and have 8 different locations of their road numbers....

Feel free to copy the above code and add it to your LOD0 section of the mesh list before the metadata.
Metadata: Cargo Slot Provider
I would say its incredibly important to give a read over at the wiki regarding custom loads to get a better understanding of the feature, here's the link.[www.transportfever2.com]

Copy this file's information into your mdl:
https://drive.google.com/file/d/1famNuwzQhf1WoJ8Wtqr1Szz-xHqKwhrm/view?usp=share_link

This is the section where the game decides on the numbers to show, and where they show.

However, these are group (mesh ID) based, we can control to a degree the rotation, scale and general transformation information of each "slot". The "slot" is this chunk of code right here:
{ group = 19, models = { "vehicle/waggon/fonts/carknocker/white/0.mdl", "vehicle/waggon/fonts/carknocker/white/1.mdl", "vehicle/waggon/fonts/carknocker/white/2.mdl", "vehicle/waggon/fonts/carknocker/white/3.mdl", "vehicle/waggon/fonts/carknocker/white/4.mdl", "vehicle/waggon/fonts/carknocker/white/5.mdl", "vehicle/waggon/fonts/carknocker/white/6.mdl", "vehicle/waggon/fonts/carknocker/white/7.mdl", "vehicle/waggon/fonts/carknocker/white/8.mdl", "vehicle/waggon/fonts/carknocker/white/9.mdl", }, randomId = 1, transf = { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, },
Lets break this down:
  • group: the mesh ID that is the parent, it controls the location of the children, just like a mother duck with her ducklings.

  • models: the list of mdls that will display at random. Whatever is listed here, the game will choose one of them at random to display.

  • randomId: If you want multiple slots to always have the same mesh (in this instance numeral) shown, this is how to do it; they have to share the same randomID. In my code, I have it listed as 1,2,3,4,5 and 6 so it would be a road number with 6 digits.

  • transf: If you're reading this, I'm sure you know by now what the transf does. Luckily for you, all you have to figure out is the spacing on the X axis. The default is .15m apart, as that seemed to work best for most of the fonts I've used, but you can adjust that as needed. Do not edit scaling here, as the group/parent ID will handle the entire scaling.

    The rotation and scale, and main transformation are controlled by the parent, these just control the offset from the parents location.

    Keep in mind, for curved surfaces, like the E8's curved numberboards or tank car sides, you'll need to manually rotate each digit for the numberboard.


    Also note that in notepad++ you can mass replace all instances of a text's mtl name. To access the replace tool, highlight the text you want to replace and press ctrl + h. So like here:

    vehicle/waggon/fonts/carknocker/white/0.mdl

    not every vehicle has carknocker font, so say you would replace it with the folder of your choice.
Metadata: Slot Levels
Read through the code comments. This may help you understanding.
{ loadConfigs = { { cargoEntries = { { capacity = 4, --make this a low number but not 0 so the train will display any open loads as well customCargoModels = { configurations = { { slotLevels = { { },--this line would be added if there were no numbers showed when the train was empty. So don't add this line. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, },--this makes it always show regardless of if car is filled or not. You need to list all slot IDs (numbers next to each slot in the Cargo Slot Provider section, under "models" in the model editor)
},
},
},
},
seats = { },
type = "IRON_ORE",--because these are supposed to contain industry loads, you have to define a type. Make it any vanilla industry type.
},
},
toHide = { },
},
},
},[/code]

I encourage you once again to take a look at the wiki to understand the slotLevel section a bit more.
https://www.transportfever2.com/wiki/doku.php?id=modding:vehicleadvancedtopics#custom_cargo_models
The EMD E8 Curved Numberboards
Curved numberboards are annoying and hard to get placements and angles correct. And unfortunately, thats exactly what the E8s have, a curved numberboard with weird angles.

I finally got around to addressing this with new meshes and a new method.

First, there are 3 important parts:
  • The number of digits per road number (Road numbers with 2,3 or 4 digits are currently supported)
  • The numeral placement within the road numbers, I called these slots in the folder system
  • The numeral itself.

Because of the way the meshes were made, they work with the existing random number PSDs and textures.

Another important note, one random numberboard mesh for the E8 has both the left and right side numbers included in the same mesh, so for example:

Using the standard random number setup, you would need 6 of the below blocks of code in the metadata of your vehicle's mdl:
{ group = 4, models = { "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/1.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/2.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/3.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/4.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/5.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/6.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/7.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/8.mdl", "vehicle/waggon/usa/streamliners/fonts/zephyr/zephyr_black/9.mdl", }, randomId = 1, transf = { 1, 0, 0, 0, -0, 1, 0, 0, 0, -0, 1, 0, -0.20000000298023, -0.019999999552965, 0, 1, }, },

With the E8 numberboard meshes, you only need 3 of the above.

The folder structure is as follows, starting in:

/vehicle/train/emd_e8/

-<font name>
--e8_numberboard_emiss
---digit_count_<insert digit total>
----slot_<insert numeral slot placement>
-----random number mdl

As the modder, all you need to do, in terms of folder structure, is rename the folder "font name" and delete the folders for the digit count that aren't used by your mod (for example, if the road number is 742, you would delete the digit_count_2 and digit_count_4 folders) and change the mtl pointing to the mtl that is used (should be the same for all numberboard mdls).

In the google drive folder link above, there is also an example mdl, by the name of example_lackakwanna_e8.mdl.

Wrapping Up
Well, you should have them just about working! If you still can't get this working, feel free to either message me on Discord [discord.gg] or drop a comment below.


Happy modding!
-meatball