Jump to content

[REL] Trains on railroads (open source)


Mr_Moose

Recommended Posts

This is the resource that brings life to all the train tracks around San Andreas, by spawning trains with attached carriages allover the tracks on certain triggers. In this topic I will explain how it all works and how to install and configure it.

Download link:

http://code.albonius.com/?action=download&id=568586d994ef88c80b2eb46b4860fc16

https://github.com/GTWCode/GTW-RPG/tree/master/%5Bresources%5D/GTWtrain

Help and support:

Bug reports

Related questions

Screenshot

Live demo:

mtasa://gs.gtw-games.org:22005

Demo video

https://www.youtube.com/watch?v=gO6atdRgduE

Description of the files:

Latest release: 2.0.0 is highly optimized compared to earlier versions, uses built in functions from MTA 1.4 which improves the carriages sync a lot. This version also comes with passenger trains (brown streak). As usual 100% open source, customizable parameters (see below) and much more to make the trains just like real trains who works out of the box and makes the game more interesting.

Settings:

maxAttachedTrailers: the maximum amount of attached trailers that can be added to a train, (locomotives also counts)

minAttachedTrailers: the minimum amount of attached trailers that can be added to a train, (locomotives also counts)

compensationSpeed: This is multiplied with the syncer and determine how fast the trailers will move when they get far away from the locomotive, should be above 7 to avoid being too slow and below 15 on a long train to prevent derails.

streamOut: Set this to false to prevent the trailers from spawning in different tracks after the train has been streamed out, set it to true if you want a large amount of short trains.

allowDoubleEngines: Specify if longer trains should be able to spawn with 2 locomotives

allowBoxTrailers: Set this to true and some of the trailers will be of the type box freight instead of flat trailers.

cleanUpDistance: How far away the nearest player can go from the locomotive before the train is cleaned up (removed)

maxSyncDistance: How far away from the nearest player the train will stay synced, above this distance the train will compress to it's origional state, the trailers will basically go into eachothers and the train will stop to prevent derails.

maxNumberOfTrains: How many trains that can exist at the same time in the entire server.

timeToNextTrain: Global timer in seconds before a new train can be created

timeNextTrainInterval: How long time in seconds a player needs to wait in case he misses his train on the station for instance.

maxSpeed: (Global) How fast will the train ever go, note that it may derail above 1 (160km/h)

minSpeed: (Global) Lowest possible speed, the train can't stop completely on the stations yet but this allow them to go close enough stop without getting stuck, should not be lower than 0.01 (Recommendation)

accelerationConst: This value is divided from the distance to the nearest train station and indicates how fast the train will slow down or speed up when it reaches the train station. 300

Debugmodes

Setting this value to 0 means it's live.

Setting this value to 1 will show all the trigger markers as in a semi transparent black color

Setting this value to 2 will show trigger markers and spawn markers as transparent white. This makes it easy to add new locations or index new train tracks in the future.

Spawn points

Array of x,y,z, direction (bool) locations where a train can be spawned. This should be placed carefully to make sure that the trains stay on the track you want it on for instance.

Trigger points (markers)

Invisible markers that trigger the train creation function as soon a player with or without vehicle (not another train tho) hit's the marker and becomes the element syncer of the train that appears.

Train Locations

This is the list of train stations, taken from AC train driver job which isn't published yet but you find it in our server as well.

Any suggestions for future improvements are welcome here in this thread, enjoy!

Edited by Guest
Link to comment

Well I guess the next version will be open source then, and by that I hope that more people will start to publish as open source. Just a few more days since the latest version needs to be tested.

Features in 1.4.6

  • Added a check to prevent trains from spawning inside each others
  • Sync direction when trains exist on the tracks to prevent collisions
  • Improved default values and debug mode 2
  • ToDo: Add the tracks in SF docks.

Link to comment
I used to upload the open source version of this one in earlier versions, what do you need to change then?
Wanted to be able to read the source for security reasons.

That and to check for any possible performance improvements.

Link to comment
Wanted to be able to read the source for security reasons.

That and to check for any possible performance improvements.

Good idea, not sure if there is so much more to improve in it thought but if you find any way of improvement I would like to hear about it. v1.4.6 is now released.

Link to comment
Wanted to be able to read the source for security reasons.

That and to check for any possible performance improvements.

Good idea, not sure if there is so much more to improve in it thought but if you find any way of improvement I would like to hear about it. v1.4.6 is now released.

No source so that is sort of useless.

Link to comment

Soon it's time for the official release of version 1.4.7, see feature list below.

Features:

  • Guaranteed open source code
  • Improved the sync algorithm with support for accordion technique, this means that the train compress and decompress after a certain distance from the sync player, by using this technique there is 0% chans for derailment and 0% chans for mixed tracks.
  • Added more tracks, spawners and trigger points, this time also with SF docks train tracks.
  • Added stop blocks which prevent trains from driving in areas where the tracks isn't mapped in case they end up in a "non circular" track. Useful in case you don't like flying trains.
  • More randomized selection of locomotives and carriages.
  • More accurate acceleration as well as deceleration close to stations and stop blocks.

Link to comment
  • 3 weeks later...

Version 1.4.7 is finally released:

Changes in 1.4.7:

- Improved the sync algorithm by including carriages rotation

- Sync the element syncer to prevent bad sync within the train when the syncer has high ping

- Fade out trains that doesn't move due to distance

- Added trains on the SF docks railroad

- Added train stations where the trains stop for a while

- Added stop blocks to prevent "flying trains"*

- Improved default values

* The term "Flying trains" describe trains that reach the "end" of their track and just keep traveling to the next node but fact is that this nodes doesn't follow the train track which the players can see on the map, by adding stop blocks it's possible to stop the trains before they reach that node where they start to fly. For example between south LV in a straight line to SF train station.

Link to comment
  • 4 weeks later...

Version 1.4.8 released

Main focus this time has been on performance and optimization as well as preparation for the 1.4 release of MTA which in this case is about the brown streak carriages, the only thing that is missing from making this the perfect train system for all kinds of servers in general. Compression and streaming out features will now work without mixing up the carriages on different tracks, trains will also stop permanent at the blocks and slow down near train stations to pickup and drop off passengers and cargo before it continues it's path.

Changes in 1.4.8:

* Improved sync performance by 10x

* Tested in MTA 1.4 with brown streak carriages (works)

* Fixed a bug in the stop blocks described in comments

* Optimized default values

Link to comment
  • 2 weeks later...
  • 3 weeks later...
  • 1 month later...

Latest version: 2.0.0 will be found here: http://code.albonius.com/?action=download&id=568586d994ef88c80b2eb46b4860fc16

News:

  • Upgraded to work with MTA 1.4
  • Using built in functions and removed it's out dated sync system written in lua.
  • Added brown streak carriages and passenger trains
  • Optimized parameters and made the trains spawn more common like in GTA SA single player
  • Improved the difference between stop blocks and stations to make trains stop in the middle of the station and force it to stop when it reaches a stop block.
  • Made the acceleration and deceleration smother at low speed (common issue in older versions).

Link to comment
  • 3 months later...

Two important updates today, moved the project to GitHub:

https://github.com/GTWCode/GTW-RPG/tree/master/GTWtrain

And improved the following:

[*]Added an extra distance check to prevent conflicts like spawns nearby other trains

[*]Improved the stop algorithm to prevent trains from going outside the tracks

[*]Allowed more carriages to attach by default

[*]Improved acceleration to start and stop faster but accelerate more slowly (like a real train)

[*]Added export calls to train horn so you know where the trains are by hearing them (Resource link)

Link to comment
  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...