[RELEASE] FiveM Freight train (AI) and enterable trams (as passenger) (Suited for Roleplay to)

===================================================
SCRIPT HAS BEEN RE-WORKED (Jan 2nd 2024) ! PLEASE READ THIS FIRST!!
===================================================
Officially I don’t maintain this script at all anymore, but the person whom took over
to ‘finish it’, also seems to have left FiveM modding. And since I noticed quite some
comments, questions etc on this topic lately again, I decided to give it ONE FINAL update.

It is basically now ‘released as-is’ and will not be updated anymore due to a major lack
of time for gaming related projects on my side the last couple of years.

So that this one has been updated does NOT mean “I’m back for more” haha, I just wanted to
help out the folks whom are still trying to use this trains system, and hope this ‘reworked’ version
helps them a bit.

Q: Does it work with OneSync/Infinity?
A: NO CLUE! Honestly… But I don’t expect it to do though! I have been ‘away from FiveM’ for years now and haven’t dived into that stuff at all. I just tested it a few minutes ago with a bare minimum FX server and is seems to be doing what it needs to do. It might still contain some bugs but the code is now very simplistic, and has LOTS of comments in it, so you should be able to adapt it to your own needs now :slight_smile:

Q: Will you make it compatible for Infinity/OneSync etc etc?
A: No, sorry I won’t. Again: Lack of time :wink:

Q: But if you released/updated it again, then you HAVE to maintain it again right?
A: NO I don’t. To say it a bit harsh: I have more important things going on in life at the moment
than focusing on video games, and I have stated in advance that It’s not actively supported.
Don’t like that? Don’t use it :wink: FiveM doesn’t like that? Also fine, just remove the post then :slight_smile:

I just wanted to help out once more because everybody else seemed to have ditched the project, but that doesn’t mean that I have time for scripts like these again, sorry. Just hope this update helped out some people now :slight_smile:

Have a happy new year :slight_smile:
===================================================

First post and directly a release - Introduction
Hi all, and first of all: What a wonderful and useful community :smiley:
Daytime programmer/hardware developer and in my spare time like to expand my knowledge,
and skill sets by making random project, varying from robotic to game development, including
texture design, game scripting etc. Had a longtime running SA-MP server and decided to move
on to something ‘a bit newer’ now haha. And now i have decided to upload my version of trains
since it turned out much more ‘extensive’ than I had initially anticipated (or planned), and hope
that it will be useful for others to use, or even ‘just to learn’ or ‘take snippets’ from :slight_smile:

What is it
It’s a complete re-make add-on based-on (well inspired on more now haha):

(Yes i do have (written) permission from @Blumlaut :wink: )

I got a request from our (closed server) players to ‘re-enable’ the trains,
so I downloaded the addon from @Blumlaut and thats where it ‘escalated’ haha.

What does it offer

  • Spawns/Activates the NATIVE GTA/FiveM trains on the ‘normal game tracks’
  • Passenger system for the Metro’s (NO player limit!)
  • Players can walk around IN the Metro train
  • Players need to purchase a ticket at one of the underground Metro stations or at the airport
  • Ticket will invalidate when used (players need to buy a new one)
  • SMS Style notifications when boarding or buying
  • SMS Style Bank error when player doesn’t have enough money (even bank brand can be setup)
  • If you enter a train without having a ticket, you will get a warning to leave, followed by a 1 star wanted level if you don’t leave the train/metro
  • ‘Terrorist Detection’ when player is shooting from the metro (resulting in 4 star wanted instantly)

All interaction are done as ‘normal game interaction’ would have been done (in normal online or
single player), no need to type commands or console/chat shortcuts

The ticket machine has animations (using ATM animation for it)

Nearly all options (allowed to enter when wanted, ‘terrorist detection’, Banks Brand sms icon/style, ticket price, number of metro’s to spawn (1 or 2) can easily be configured with variables i’ve created
at the top of the script.

The script is HEAVILY commented so that it should be easier for most to understand what happens
where and how (which would also make it a bit more suitable for beginners i guess)

- Known “issues/bugs”

  • The ‘old messed up’ ticket machines above ground don’t work (see screenshot)
    I could not find that model in the game files after many hours of searching, if someone has/knows
    the model file I could update it if requested :slight_smile:
  • The Metro doors ‘disappear’ when a player enters it as passenger (fully see through) i suspect that
    this is a game/model limitation.

What does the script user/server owner need to do
PLEASE READ THIS PART: You will need to implement your OWN money/bank handling part.
In which i mean that you will need to make sure that the money gets taken from either the
bank account or cash money. Reason for this is that many servers use different banking systems,
just like mine does. So i did not implemented the ‘take money away from player’ part.

However I have (very detailed) explained exactly in my code where (and a bit how) you can
add those parts :slight_smile:

Expected Questions
I expect some questions like: Can you make the trains so we can drive them?
Short answer is “Yes”… BUT… it turned out not to be stable or smooth (jumpy trains and such),
and it caused de-syncing. However several of these questions I have already replied to and explained
in the readme file of my source/release :slight_smile:
Here are some screenshots of the Add-on:


Arriving Metro at the station (Note: Ped’s will NOT get in)


Shooting from the Metro (on public transport) is considered to be an terrorist act
(is configurable if you want this or not)


The Freight train


This is the Ticket Machine Model which does NOT work (yet) since i just can’t find the model name
for it. have found one model name but that one doesn’t respond in my scan, so i suspect it’s a different model.

Where to download:
My Github Page

Anyway,
Hope it will be useful, interesting and well received :slight_smile:

Kind Regard,
VenomXNL

49 Likes

Thanks you did a good job m8 you also made a good looking topic with a lot of information

3 Likes

Thanks man, hope it’s not ‘to long’ (as in resulting in TL;DR and then asking questions why some things need attention when setting it up haha) :slight_smile: :rofl:

2 Likes

you’ll have to manually tell the train to stop when it’s near the station using SetTrainCruiseSpeed to gradually slow it down to 0, or SetTrainSpeed to instantly stop it in it’s place (however the latter will make the train accelerate immediately again if the cruise speed is still > 0)

1 Like

@Vespura Yeah i know, i have done that in the script (tested) and even made hem drivable, but it either took away LOTS of the ‘asthetics’ (aka realism), or it even caused ‘flippin’ trains on some connected clients while
testing (even when doing it via an server event).

Have mentioned and explained this “elaborately” in the readme of the release to :slight_smile:

Thank you for your information, it might be useful if someone would want to implement stopping them :slight_smile:

3 Likes

My bad then, I’ve only read this topic and noticed you tried the drivable trains which caused issues. Didn’t know you also tried stopping the trains at stations.

As for the doors that you can’t walk through, you have to remove (delete) the vehicle doors on the side of the platform, however you can only restore them by fixing the vehicle sadly :confused: I was making a similar resource, but gave up since the trains kept de-spawning all the time as soon as more than 1 player joined the server. And no matter what it was impossible to fix for some reason.

3 Likes

[quote=“Vespura, post:6, topic:268613”]
As for the doors that you can’t walk through, you have to remove (delete) the vehicle doors on the side of the platform, however you can only restore them by fixing the vehicle sadly :confused:

Yeah i figured that part out to (the needing to fix the vehicle) so i’ve decided to not make it to ‘overcomplicated’ and just leave it as it is, since the doors (even though invincible) can still be used as cover now in for example hijack or ‘terrorist roleplay’ scenarios.

Well it seems like that the original resource i’ve used does the job quite well. I have to admit that SOMETIMES we have a de-spawn, but most of the time it works just fine, i’ve set them to mission entity’s, invincible etc to ensure they are ‘high prio’ in the game (seems to work, i remember this
from my days in GTA IV when making Realism mods) and tried it here again.

However IF it despawns, it’s not much of an issue since on next connect or when there is a moment
that the server has 0 players it will instantly create new trains and make that current player host.
When the other players join then, they seem to take over the missionentity registration :slight_smile:

We have tested it several times and it SEEMS to work out quite well, lets just hope it keeps working
this well, and if someone finds issues please do report them.

I don’t work (much) on this mod anymore since it’s just a ‘side feature’ of our server so it will only
get attention when someone notifies me of issues haha.

4 Likes

I just checked and indeed, the above ground ticket machines are not models. You would need to provide coordinates instead.

Good work!

4 Likes

Thanks for confirming! :smiley: (Don’t have a map editor or so installed).

I suspected this already (that they where part of the 'TrainStationMapPart/Component)

I might then in the future add them as small vectors with a radius like 0.5 or so :slight_smile:

BTW:
@d0p3t Do you have any tip on how to “more easily” find the modelname of
objects while in game? (for example when i see an object and get the hash
from it with my own “GetNearestObject” function, but then i will need to get an ‘easy way’ to get the model name… I know how to in most games like Fallout, NV, GTA SA, IV etc, but not for V… do you have any recommendations? or will it really be:
“Searching in hash lists made by others?”

1 Like

You can try this - Basic In-Game Debug Tool (LUA) :stuck_out_tongue:

3 Likes

@XIII Are you f*ing kidding me? :rofl:
Didn’t even knew about that simple solution hahaha

BUT does that model ID refer to a ‘permanent’ model number and is it
directly callable in my own scripts? like: "RequestModel(‘12345567’)
Or is it a (session or file/dlc) addressed number like in games as fallout for example?

Edit: Since i had made a simple scanning (to console) function, but the issue i had
there is that it only returns the hash, and i’m not certain if i can just use the hash
as a permanent solution to spawn/call or interact with objects.

Thanks

3 Likes

I use the entity debugger of Mooshe’s DevTools (available on the forum)

4 Likes

Will i need to add in TRAINS! or does your script do it? I been waiting in the subway station for 20 minutes no train… lol… but i have purchased a ticket and it says the bank and everything.

Same here. I even flew around and did not see any trains. The very first time though I saw a freight train sitting on the subway track not moving.

I moved the script near the top of my start order and now 2 freight trains spawn and sit on the metro line.

still no train… no clipped everywhere… and never found one.

I can get them to spawn, but it is the freight train on the subway line and it just sits there. Hopefully someone can get this working.

So everything seems to be working L:)

I am wondering if there is a way to add more train cars to the freight train? (to make it longer)

1 Like

Are your trains moving and the freight train on the right track?

I’m currently working on seeing where the problem is, it LOOKS LIKE IT, that we don’t have issues when we test it locally (on a LAN hosted server), not even with multiple people.

BUT now we have tested it with a 100% remote hosted server (one at my company) and we all played while remotely connected to that server, and then it WILL de-sync and even ‘de-spawn’? the trains.

The drivers however WILL remain, they will be ‘left in the open’ ON the track (I assume at the position where their train previously was).

I guess it has something to do with the game handling the trains and NOT fully
recognizing them as mission objects/entity’s.

I will try as soon as possible if it’s in some way possible to ‘remove them from the
respawn buffer/list’ (or however GTA V Rage handles it) or if there is a way how I
can mark them as a ‘crucial item’ for the game. (which should do the same).

Alternatively I can try to look for alternatives to ‘alternate’ between ‘hosts’ for the
train (since AI and such is ‘hosted’ by the clients nearby). But all these will be
quite difficult to keep managed since all of these options would have to be with
Natives I assume.

Will see if i can find anyway to solve it.

For now people CAN test the trains by using /XNLforcetrains command.
BEWARE THOUGH!: That command is NOT limited to admins or so!

I have updated the repositroy (on my github) with a new(er) client.lua which
decreased the risk of the train (freight) being on the wrong track.

However i will look into the other problem asap.

WARNING: When using the XNLforcetrains command, it will NOT cleanup the
previous trains, even though I call DeleteAllTrains, i suspect this is since they are
mission trains. The other ‘downside’ to this is that if i would ‘start hosting them’,
and create the trains for the session, and i would then leave… then my buddy whom
would still be in the server CAN NOT delete the mission trains since I’m the one
whom created them with the refrence. So he has no pointer at all to delete them.

And as far as i know: We can’t stream vehicles via the server (yet) like we could
do in SA-MP for example.

BTW: Sorry for my late reply, i already noticed yours instantly when you posted it, but could not reply anymore (at the moment I’m still a limited member since this account is ‘brand new’. I will however try to do my best and update/help where i can :slight_smile: