Train Counter to File
Useful tool for streamers
Description
Mod find trains by them starting or stopping and will write the amount of trains to a file set in the mod options (%Factorio%/script-output/trains.txt)
Ingame settings:
- Enable, To enable/disable the functionality of this mod aka decrease ups drops because of file system changes when 1000s of trains are changed every second
- SubString, To substitute $t with the amount of trains, rest is a free string
- Location, The location where the file should be saved, always a folder/file under %factorio%/script-output
Changelog
The changes the mod has gone trough
0.3.3
- Updated to work on 0.18.x
0.3.2
- Re-added the substitution option and file location option
0.3.1
- Rewriten for ease of use and new factorio version
0.2.3
- Removed a local variable in the script
- Made sure the variable is changed to a same value for everyone on mod update
0.2.2
- Fixed desync when a state occured between joining and finishing catching up
0.2.1
- Fixed desync and invalid state on join errors by changing startup from using on_nth_tick to using a global on_nth_tick with a second variable to determine if saving is necessary
0.2.0
- Initial release
- new Event system
- new way to detect trains
- more efficient and direct saving to file
Events
The events used by the mod (for performance reasons noted here)
on_init
This function will trigger on creation of a map this mod is added in
It will make sure all variables used by the mod are initializedon_load
This event will trigger on load of the game except when a new mod is added to the save bug factorio?
When loading the mod will make sure to tag the next mod iteration as a save iteration where the file should be overwrittenon_entity_died
This event will trigger whenever an entity has died
If this entity was part of a train, recalculate trainson_player_changed_force
This event will trigger whenever a player changes their force
Saves the new trains file for this player (most important when force restriction mode is enabledon_player_mined_entity
This event will trigger whenever a player mines an entity
If this entity was part of a train, recalculate trainson_train_created
This event will trigger whenever a train is created/merged/separated
Recalculate trainson_nth_tick
This event will trigger after every nth tick
I use this event to delay after destruction or mining of a train. since the entity invalidates AFTER the event
Old 0.1.x versions
Mod find trains by them starting or stopping and will write the amount of trains to a file ('%Factorio%/script-output/stream_data/train_amount.txt')
Changelog
The changes the mod has gone trough
0.1.8
- Updated for 0.16.x
0.1.7
- Should fix an error whenever you try to load the new version into an already existing map
0.1.6
- Added a mod option called "SubString"
- This is the text that will be saved by the mod to the file, use "$t" to get the amount of trains in there.
- Option defaults to "$t"
- Example: "We now have $t trains" will output "We now have 5 trains", if you had 5 trains, to the file
0.1.5
- Updated for 0.15.x
0.1.4
- Something made the game crash for saves where the mod was already in, so i updated it to check if variables already exist in new versions and they will now be removed before being re initiated.
0.1.3
- Fixed a typo that crashed the game on removing of trains (error was in the on_tick loop)
0.1.2
- Made sure the file is resaved on load of a save so the accurate number is displayed for the world
- Checking for invalid files and checking to save after load are now done every 2 seconds
0.1.1
- Removed dependency on base mod (since it doesn't really matter)
- Made sure that every second invalid trains were removed instead of every tick
0.1.0
- Initial release
Events
The events used by the mod (for performance reasons noted here)
on_init
This function will trigger on creation of a map this mod is added in
It will make sure all variables used by the mod are initializedon_load
This event will trigger on load of the game except when a new mod is added to the save bug factorio?
When loading the mod will make sure to tag the next mod iteration as a save iteration where the file should be overwrittenon_tick
This event will trigger every tick of the game
The mod will check if it is ready for the next iteration (every 120 ticks - aka 2 seconds)
If a mod iteration is onging:
- The trains are validated (if they are removed or changed) and will overwrite the file if needed
- It will also check if the iteration was tagged as a save iteration and if so it will overwrite the file
on_train_changed_state
This event will trigger whenever a train starts or stops moving
If this train was not already in the list of trains, add it and overwrite the fileon_runtime_mod_setting_changed
This event will trigger whenever mod option has changed
Edits the substitution string used for saving to file and marks the mod so it will save next iteration