[RELEASE] FiveM-Trains : Complete standalone AI trains system and enterable trains

! ALERT ! THIS IS NOT COMPATIBLE WITH INFINITY !
Not compatible with FxServer Build 2689+.

Since @VenomXNL has stopped working on his Trains Project (XNL-FiveM-Trains-U3), I asked him to take over his code and rework it for OneSync.

I always wanted to make a real living city for my RP server.
So… we need trains for transportation !
For a couple of month, I used his script and modified a lot for making it compatible onesync.
Last month, I saw some people having trouble making it working proprely.
I’v pushed some fix to VenomXNL’s git and It started in my head with several idea.

It was better, since he wanted to stop his dev, to make his project live again.

Iv keeped some utilities he used.

- Spawns a freight train (AI controlled only) which drives around Los Santos
- Spawns 1 or 2 Metro’s (opposite direction and server own can choose 1 or 2 in client.lua)
- Metro’s and the Freight are all AI controlled
- Trains stop at station now ! (VenomXNL don't)
- Passenger system for the Metro’s (NO player limit!)
- Players can walk around IN the Metro train
- Players need to purchase a ticket at 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)
- Metro Station Detection (players can only Exit the metro at Metro stations)
- Wanted Level Handling (not allowed to enter while wanted) (also configurable in config.lua)
- ‘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
in the config.lua.

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 Metro doors ‘disappear’ when a player enters it as passenger (fully see through) but it still
keeps it’s collision (thus can’t walk through it), 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. May be I will add a universal system for it in the futur.

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

Screenshots



Where to download
My github

Update

- 1.1: The train now stop at station.
- 1.2 : Fixed a bug for spawning train when the ressource go "too fast" to load.
        Added blips for trains. (Can be desactivated in config)

Hope you will be interrested in this rework and give feedback.

Best regards.

39 Likes

Iv been following the Old train for a few weeks and i think its great you have taken it over. Keep up the good work :slight_smile:

TUTORIAL for ESX:

I have gotten this to wrok with esx (for the payment methods) I will explain what to do below in each file

Client.lua

at the top of the client.lua put this peice of code

ESX = nil

Citizen.CreateThread(function()
    while ESX == nil do
        TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
        Citizen.Wait(0)
    end
end)

And then at line 417 to 421 (might be shorter if you do this first) in client.lua put these lines

if PayWithBank == 1 then
                        TriggerServerEvent('FiveM-Trains:buyTicket')
else
                        TriggerServerEvent('FiveM-Trains:buyTicketBank')
end

Now for the Server.lua. At the top of Server.lua put these 2 lines (just like the client)

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

Then put these 2 events at the bottom of the server.lua file

RegisterNetEvent("FiveM-Trains:buyTicket")
AddEventHandler("FiveM-Trains:buyTicket", function()
    local _source = source
    local xPlayer = ESX.GetPlayerFromId(_source)
    if xPlayer.getMoney() >= TicketPrice then
        xPlayer.removeMoney(TicketPrice)
    else
        xPlayer.showNotification("You do not have enough Money!")
    end
end)

RegisterNetEvent("FiveM-Trains:buyTicketBank")
AddEventHandler("FiveM-Trains:buyTicketBank", function()
    local _source = source
    local xPlayer = ESX.GetPlayerFromId(_source)
    xPlayer.removeAccountMoney('bank', TicketPrice)
end)

And that is all to make it work with ESX :slight_smile:

7 Likes

It would be good to create the physical ticket for the inventory and DB

AND

add blips for train stops

  {name="End and start of the journey ",color=38, id=599,x = -503.1493, y = -669.3173, z = 11.80},
  {name="STOP 1 Alta Street PhilBox Hill",color=38, id=599,x = -214.4281, y = -1038.7393, z = 30.13}, 
  {name="STOP 2 Carson Avenue Davis",color=38, id=599,x = 107.4152, y = -1721.3209, z = 11.04},
  {name="STOP 3 North Rockford Drive Del Perro",color=38, id=599,x = -1350.6663, y = -457.5231, z = 15.04},
  {name="STOP 4 South Boulevard Del Perro Rockford Hills",color=38, id=599,x = -807.8964, y = -137.8175, z = 19.95},
  {name="STOP 5 Abe Milton Parkway Rockford Hills",color=38, id=599,x = -298.8444, y = -325.2876, z = 10.06},
  {name="STOP 6 Autopista de Olympic Strawberry",color=38, id=599,x = 263.3448, y = -1200.8344, z = 38.90},
  {name="STOP 7 Innocence Boulevard Little Seoul",color=38, id=599,x = -543.36, y = -1284.29, z = 26.9},
  {name="STOP 8 New Empire Way Los Santos International Airport",color=38, id=599,x = -893.77, y = -2337.12, z = -11.73},
  {name="STOP 9 New Empire Way Los Santos International Airport",color=38, id=599,x = -1096.81, y = -2724.38, z = -7.41},
  {name="STOP 10 BACK TO THE CITY New Empire Way Los Santos International Airport",color=38, id=599,x = -1074.72, y = -2712.58, z = -7.41},
  {name="STOP 11 BACK TO THE CITY New Empire Way Los Santos International Airport",color=38, id=599,x = -872.28, y = -2301.47, z = -11.73},
1 Like

in this version I do not get the trains unless I add in client.

Citizen.CreateThread(function()
SwitchTrainTrack(0, true)
SwitchTrainTrack(3, true)
N_0x21973bbf8d17edfa(0, 120000)
SetRandomTrains(1)
end)

yes trains

name texture
42d126de33fe8d621aedf2940ff08582b0ffec36_2_342x500

dt1_21_stat
dt1_21_stat+hi
dt1_21_station+hidr

its idem and use
rsn_os_tram_006_emrsn_os_tram_006_em_a.dds


Example:


OLD TICKET OFFICE DOWN ON THE TRAIN TRACKS

metro_stationhut002seoul

v_serv_metro_paybooth

prop_turnstyle_bars


prop_turnstyle_01

I leave this here that the ideas arise XD

2 Likes

Thank you for sharing this! Will give this a try later today, im excited! Been wanting something like this for a long time now but everything has been kinda broken in onesync :smiley:

1 Like

You’re welcome ! :smiley:

@Daniel_Martin For the ticket, I prefer not.
I don’t want to add ESX dependency …

Great mate, I love that script and Im happy to know its now in good hands again. If you need something let me know! :slight_smile:

1 Like

Hello ! Is it possible to have a continuous GPS position of the train/metro on the map?

Will be added in next release.

1 Like

Update

Fixed a bug for spawning train when the ressource load "too fast".
Added blips for trains. (Can be desactivated in config)

Does this work with OneSync Infinity?

Don’t have actually a key for Infinity, so, can’t say or dev on it.
Give it a try on Infinity and tell me if it work :wink:

I already have but the trains don’t spawn.

It would be good to put a coordinate system for the stations that cannot buy tickets if the texture of the ticket machine does not match

The best things to do is to replace these machine :confused:

I have tested id and the trains don’t spawn, tells me it started it but there are no trains.

the train will spawn but will disappear when it goes a little far from me , when i teleport myself into the train it will go around the map and will NOT despawn

I am unable to get ticket sales to work at some stations.

I need help please.

Can you tell me how to implement the physical ticket system to be able to put stores in the stations?

or a coordinate system for the sale of tickets.

It would be greatly appreciated.

I always try to help but I am not a certified programmer I am a self-taught person so any help would really be a symptom of incalculable humanity for me

By the way, I already tried to change these machines, it didn’t work for me


:sweat_smile: :cold_sweat: :cry: :sob: :rage: :face_with_symbols_over_mouth: XD

It’s breaking my head
got me really frustrated

I don’t know what else I can do to keep all the stations working