[Unsupported] Driveable Trains

release
fun
script
scripting
trains

#1

This unfinished resource is no longer being developed and has been recreated into a working resource at [Release] TrainSportation ~ Drive & Be a Passenger in a train!

Warning: This isn’t a finished project, just something to learn from.

Some notes:

  1. There is potential for trains to be used in RP Jobs, or other stuff.
  2. There is a problem with trolleys, the doors open but there is invisible barrier :frowning:.
  3. Maybe you could teleport the passengers into the trolley?
  4. I’ve differentiated the speeds for the trolley and regular train. The Acceleration is also differentiated https://github.com/LexTheGreat/DriveableTrains/blob/master/client.lua#L93
  5. I couldn’t find a way to get the nearest train so it uses the return of the CreateTrain function, sends that to the server, then the server sends that to everyone else so they can find the nearest train by position. If there is a better way please let me know ;-; I used ray-cast as well as nearest-vehicle.

If you load the resource there are two places the trains spawn
247.9364, -1198.597, 37.4482 – Trolley
670.2056, -685.7708, 25.15311 – Train

Press G to spawn trains, make sure it’s loaded by pressing F8, should say loaded keys.
If you need to restart this resource, press KP8 and it will clear out the trains. If you don’t do this the server will loose track of the trains, and you will have to restart to get rid of it.

F = Enter Exit
W = Accel Forwards
S = Accel Backwards
X = Debug Instant stop :stuck_out_tongue: 200mph -> 0 instantly
F8 = Fivm’s console

Oh, if you get out of the train when next to a spot that it stops at by default (Trolley stops at the train stations) It will start to go around the track by it’s self. There is no driver but it still goes…?


#2

God damnit, you beat me to it :c . Literally needed to finish the networking :frowning:


#3

Great work i cant wait to use this


#4

Rip my hopes and dreams:
https://illusivetea.me/WhyIsThereSoManyFuckingRpServers/2F166V95b.mp4


#5

You can always create a ped inside it when you get out :wink: then there will never be no driver


#6

You could, although, what I was bring up is that the train will run off on you when you get out near a train station. :dizzy_face:


#7

Are you setting the speed in a loop? if not it will go back to the default speed when you get out, happened to me :stuck_out_tongue:


#8

x.x Has to be ghosts trains


#9

Also, Have you networked your stuff? I cannot seem to be able to network the engine train so that non host can get in :c Mightve got it now, but need someone to test :stuck_out_tongue:


#10

Yes!

https://github.com/LexTheGreat/DriveableTrains/blob/master/client.lua#L138

https://github.com/LexTheGreat/DriveableTrains/blob/master/server.lua#L10


#11

Thought you needed to actually use the network stuff, like:

netid = NetworkGetNetworkIdFromEntity(Train)
            NetworkRegisterEntityAsNetworked(VehToNet(Train))
            SetEntityAsMissionEntity(Train)
            SetNetworkIdCanMigrate(netid,true)
            SetNetworkIdExistsOnAllMachines(netid,true)
            NetworkRequestControlOfEntity(Train)

¯_(ツ)_/¯


#12

Yeah, pretty sure you do now i think about it, the host changes the localid for the entity to a network one, then sends that to all the clients which they turn into an entity they can register


#13

Yeah I’m with tea on this one. If you try to get entity id’s from net id’s on the other clients they will be 0.the host will actually have real values.

That’s the problem tea and I have been having with our train scripts


#14

Hmmm, I havn’t tested with more players than my self, I don’t have a person to test with. If this doesn’t work over the network then:

You could try this? Base is there, you just need to send the right ID to the server

https://github.com/LexTheGreat/DriveableTrains/blob/master/client.lua#L164


#15

Im having the issue with networking on my train scripts, and so is @JinkLeft :stuck_out_tongue:


#16

I believe its not a script problem but the engines. The networkidtoent always returns 0… I believe this function is meant to be used directly on gta online and not fivem? I don’t think there is anyway to do networking with trains at the moment…


#17

Well, that’s a problem then for a lot of players other than the host or whoever spawns the train because how can you set other clients in an entity that doesn’t exist to them?

For example if I spawn these trains and save their entity ID and send it to the server.

Then when a new player joins I request that entity table and try to create a blip for the entity it won’t work. It will only work on the player who spawned those trains because the entities exist for them.


#18

The train is also classed as a vehicle tho, therefore falling into the idea that it should work


#19

The train exists for everyone when you spawn it (If they can see it, it exists), the ent id is just different for each client I believe? And there is no way I can find to get the train after creating it ;-; ortherwise it would be easy, but nearestveh doesn’t return trains :confused:


#20

Hence why you need to use networking :stuck_out_tongue: