How do I add trains in my server?

How do I add trains into my server, so the AI are driving them around?

1 Like

Use the following snippet

SwitchTrainTrack(0, true) -- main track trains
SwitchTrainTrack(3, true) -- main track metro

SetTrainTrackSpawnFrequency(0, 120000)
SetRandomTrains(1)
2 Likes

where do i put that at? my server cfg?

1 Like

In a client script

1 Like

what script

1 Like

In a client script. If you don’t know what that is, how the hell are you even running a server?

1 Like

What he said, a client script is a client.lua typically. This client.lua goes in a resource…

(You also need a fxmanifest.lua or __resource.lua to start it)

1 Like

When adding random AI trains to the map with the following code, it seems to spawn the trains poorly like solo train cars going around, 3-4 of the same cars attached without a lead car. Train cars being left on the tracks not moving, etc. Anyone know why?

1 Like

I had found a script that adds AI trains, and had no issues

2 Likes

which is it?

2 Likes

Some people do this in their spare time and just want an answer so they can continue with their project. No need to be an ass about it.

1 Like