[Release] TrainSportation ~ Drive & Be a Passenger in a train!

Update:

Some stuff fixed/tweaked:

  • Config.Debug is set to false. To see debug messages/effects set to true.
  • Config.TrainSpeeds changed to ->
Config.TrainSpeeds = {
	[1030400667] = { ["MaxSpeed"] = 36, ["Accel"] = 0.05, ["Dccel"] = 0.1, ["Pass"] = false }, -- F Trains
	[868868440] = { ["MaxSpeed"] = 91, ["Accel"] = 0.1, ["Dccel"] = 0.1, ["Pass"] = true }, -- T Trains
}

  • [“Pass”] = true means the train will let passengers in.
  • MaxSpeeds to to https://en.wikipedia.org/wiki/Rail_speed_limits_in_the_United_States
  • Using SetTrainCruiseSpeed and not SetTrainSpeed now. (SetTrainCruiseSpeed accelerates to the speed. SetTrainSpeed instantly goes to it.)
  • Added e-break with X, debug break changed to W+S (requires Debug.Config)
  • TrainSportation will detect if you are in a train and setup up. (If you are in a Train and reload the resource you won’t have to re-enter the Train)
1 Like

thanks for the update. also i tried the thing you said to make the train longer i found number 17 to be the longest. although its all containers not a mix but its way longer which is nice. thanks for the great script :slight_smile:

1 Like

Is there any reason why the freight train is spawning at the LS Transit station and the tram is spawning in the freight train location?

Old

Errr Might have mixed them up lol?

Inside config.lua is Config.TrainLocations

Swap the train id’s and it should change back.

Edit:

Are you sure you have the most updated version? I just tried it and it worked normally…

Downloaded the newest version and switched out the IDs, still spawns the freight train at the tram station

Try re downloading and just using it. Don’t switch IDs. It should be fine I just tested it!

That is what I did the first time before switching out the IDs. Still does not work

Not sure what to tell you… It works when I fresh download it fresh github. I can not reproduce the error/bug you are talking about.

If you are changing the ID’s in the config and it doesn’t change in-game it’s not the scripts problem. Are you restarting the server/restarting the resource after you update/make changes?

The ID of the trolley is 24!

Config.TrainLocations = {
	{ ['x'] = 247.965,  ['y'] = -1201.17,  ['z'] = 38.92, ['trainID'] = 24, ['trainX'] = 247.9364, ['trainY'] = -1198.597, ['trainZ'] = 37.4482 }, -- Trolley
	{ ['x'] = 670.2056,  ['y'] = -685.7708,  ['z'] = 25.15311, ['trainID'] = 23, ['trainX'] = 670.2056, ['trainY'] = -685.7708, ['trainZ'] = 25.15311 }, -- FTrain
}

This should be your Config.TrainLocations!

The trolley hasn’t been changed in the recent update. It’s exactly the same as before, and the only thing that changed was the trainID of the other train:

How can people get in as passengers because if they are pressing F only one gets teleportet at the back (driver Cabine).

but it can be done so that the doors can open or close, for example on key 2?

I had some issues where the train disappeared for no reason with it being the only resource installed. I fixed it though! I just edited the client.lua and removed function that allows for train deletion. It might have been just my client though, not sure :slight_smile:

Is there a way to make it so when we leave the train that the train doesnt take off after you exit to make it better for roleplay?

@Lex_The_Great I also found a lua script for you to add to make the train more likely to explode due to damage which makes it more realistic. Just add this lua file into the client scripts. https://www.gta5-mods.com/scripts/vulnerable-trains-lua

Thats not how it works, it looks like it was made for GTALua, which is quite different from FiveM’s usage of Lua

Also is there a way if multiple trains are on the tracks we could have then collide and derail?

I’m getting a similar issue, but instead of them spawning in opposite spots only freight trains spawn at both locations. Didn’t touch any of the files.

When i go to the T on the map and enters the Green Circle, it wont show anything :stuck_out_tongue:

@Lex_The_Great I hope you can add this so it can help players. This iswhat I changed in the client.lua. Basically I added the function drawTxt above the incircle=false. This will allow text to form under the current circle to state for the playe to Press the G key to spawn the train. I hope this helps. Also I added a photo to show how the end result works.

function drawTxt(text, font, centre, x, y, scale, r, g, b, a)
	SetTextFont(font)
	SetTextProportional(0)
	SetTextScale(scale, scale)
	SetTextColour(r, g, b, a)
	SetTextDropShadow(0, 0, 0, 0, 255)
	SetTextEdge(1, 0, 0, 0, 255)
	SetTextDropShadow()
	SetTextOutline()
	SetTextCentre(centre)
	SetTextEntry("STRING")
	AddTextComponentString(text)
	DrawText(x, y)
end

incircle = false
Citizen.CreateThread(function()
	Log("Train Markers Init.")
	while true do		
		Wait(0)
		if Config.ModelsLoaded then	
			for i=1, #Config.TrainLocations, 1 do
				local coords = GetEntityCoords(GetPlayerPed(-1))
				local trainLocation = Config.TrainLocations[i]
				if(GetDistanceBetweenCoords(coords, trainLocation.x, trainLocation.y, trainLocation.z, true) < Config.DrawDistance) then
					DrawMarker(Config.MarkerType, trainLocation.x, trainLocation.y, trainLocation.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z-2.0, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false)
					drawTxt('Press ~g~G~s~ to Spawn~b~ Train', 2, 1, 0.5, 0.8, 0.6, 255, 255, 255, 255)
				end
				if(GetDistanceBetweenCoords(coords, trainLocation.x, trainLocation.y, trainLocation.z, true) < Config.MarkerSize.x / 2) then
					if(IsControlPressed(0,58) and(GetGameTimer() - Config.EnterExitDelay) > Config.EnterExitDelayMax) then -- G
						Config.EnterExitDelay = 0
						Wait(60)
						createTrain(trainLocation.trainID, trainLocation.trainX, trainLocation.trainY, trainLocation.trainZ)
					end
				end
			end
		end
	end
end)

This is the file in its entirety. I hope this helps with your script.
client.lua (6.1 KB)

1 Like

Hey, thanks. I don’t really have time/energy to put into fivem anymore.

This resource lets you enter trains. The main goal is for someone to remove the spawn areas and script it into a job or something? Any train that spawns should be able to enter with this enabled.

If you want to do a pull request on the github with your changes I’ll accept it!

I believe this is hard coded? I don’t know of a way.