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

TIP: If you’re asking ‘help for code’ it’s best to at least paste a small part of the segment you are in need of help for :wink: then it’s more likely that others are willing to ‘jump in’ more quickly instead of having to ‘dive into’ the code first :wink:

if PayWithBank == 1 then
	-- Put YOUR code to deduct the amount from the players BANK account here
	-- 'Basic Example':  PlayerBankMoney = PlayerBankMoney - TicketPrice
else
	-- Put YOUR code to deduct the amount from the players CASH money account here
	-- 'Basic Example':  PlayerCash = PlayerCash - TicketPrice
end

Is the code you are referring to :slight_smile:

Well assuming you mentioned the lines for CASH, you would need to make an code where it takes cash money from the player. But the reason why i didn’t implemented this, is because many people use different frameworks which might not detect the money deduction or for example ‘see it as an cheat attempt’ if it’s not deducted through their framework.

Therefor i decided to not use ‘general functions’ and just leave it as commented tips, on where to place the code :wink: :slight_smile:

What kind of code you might need totally depends on what framework you’re using, if you have some sort of (money) anti-cheat script/mod which might respond to it, or if you can/want to just use the native game functions to deduct money :slight_smile:

Extra info (just in case): Frameworks for example are: systems like ESX and vRP

Hope this helped you a bit further in telling what you might need :slight_smile:

I get this errorCattura

But this is working in an older version sir, so no game limitation.

I do not see the subway just zero of zero

Older version? well not in my older version.

If you are reffering to other scripts or the one this is based on.
Then it might be because they actually use scripts to ‘point/spawn’ objects to locations or to make them move in directions using ‘physics force’ in game. Which is not at all what mine does.

Mine actually activates the game engine part which is controlling the trains. However i wasn’t able to find any (programming) hooks in which i would be able to let them stop or ‘get triggered’ to utilize a stop/wait/delay system when they would arrive at the stations.

So nope, in MY older versions that wasn’t working, and some other scripts (which are completly different than mine) might do that, but they often don’t use the main game script but ‘applied force’.

It MIGHT be that i have missed a simple API call or so back then, but i don’t work on FiveM mods anymore, so unfortunately i won’t be able to update, test or make new releases anymore.

I don’t have the servers installed either anymore.

hope you understand a bit why this game limitation is the problem with my script and approach while others made it work differently for example :slight_smile:

Reason why i did NOT used the 'applied force method" is because i was working on making LOTS of functions from the original GTA V and GTA:O function like they should again for FiveM (including home interiors per player, garages with ‘virtual worlds’, showers including FULL animations, the GTA:O character creator etc). So i tried to stick to the official API’s as much as possible and tried to work around them to get it functioning as much as possible.

Unfortunately i never came to a point where i finished the trains system due to the shower system and character creator taking up to much time back then.

Thank you for the answer.

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

No problem :slight_smile:

and seeing that script: Ahhhhhh, yup that one uses a completely different approach to use the trains than what i’m doing :slight_smile: (indeed MUCH more manually controlled by the programmer opposed to by (trying to) letting the game handle it as it was ‘originally’ (which was my intention) :slight_smile:

1 Like

This is indeed unfortunately possible, but is also stated in the main post though, there are some problems which i hadn’t figured out yet when i was still working on this mod.

And with OneSync it would have been even a complete re-write (because it doesn’t work in OneSync at all).

Thank you!
Do you plan to update it for OneSync? We would love to use this newer version :slight_smile:

1 Like

Well first of thank you for letting me know you even already enjoy this (unfinished) version already :smiley: Truly appreciated :slight_smile:

I will however need to ‘disappoint’ you a bit i guess :frowning: Because i have (about a year ago or so) completly stopped working on ANY FiveM Mod, including my own server which i wrote from scratch (completly own framework). I don’t have the server running either anymore, nor do i have the SQL files for it anymore.

Reason for this is that i’m a software and hardware developer with several people on staff, and the company became way to busy and occupied overtime, to a point where it was not manage to keep ‘yet another gaming project’ going next to work/business and family life and several other projects i have going on haha :slight_smile:

Last few months i have been focusing on launching a large educational platform aiming at free educational video’s, open source software and hardware etc, and i THINK that this platform will keep occupying me ‘to much’ to (re)focus on projects like these.

I have however ‘granted permission’ to anyone whom wants to use it an re-work it for OneSync already :slight_smile:
I however SUSPECT (don’t know for sure because i opted out of onesync back then (due to my framework was just starting to work and would not work with OneSync), so i have never ran it myself.

But considering that every syncing and such is done completly different i’m ASSUMING (again not certain) that lots of functions and native calls would work completly different or need to be called differently (??).

how do you make yourself the host

This might help a little

function DrawText3D(x,y,z, text)
    local onScreen,_x,_y = World3dToScreen2d(x,y,z)
    local px,py,pz = table.unpack(GetGameplayCamCoord())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
    local scale = ((1/dist)*2)*(1/GetGameplayCamFov())*100

        SetTextColour(50, 168, 105, 255)
        SetTextScale(0.0*scale, 0.55*scale)
        SetTextFont(font)
        SetTextProportional(1)
        SetTextCentre(true)
        BeginTextCommandWidth("STRING")
        AddTextComponentString(text)
        local height = GetTextScaleHeight(0.55*scale, font)
        local width = EndTextCommandGetWidth(font)

        SetTextEntry("STRING")
        AddTextComponentString(text)
        EndTextCommandDisplayText(_x, _y)
end

isset = false

Citizen.CreateThread(function()
    while true do
    	Citizen.Wait(0)
    	if IsControlJustPressed(0, 51) then
            _, entttt = GetEntityPlayerIsFreeAimingAt(PlayerId())
            if (DoesEntityExist(entttt)) then
                isset = true
            end
            xi,yi,zi = table.unpack(GetEntityCoords(entttt))
	    end
    end
end)

Citizen.CreateThread(function()
    while true do
        local xo,yo,zo = table.unpack(GetEntityCoords(entttt))
    	Citizen.Wait(0)
        if (isset == true) then
            DrawText3D(xo,yo,zo + 1.6, "Coords: " .. xo .. " " .. yo .. " " .. zo )
            DrawText3D(xo,yo,zo + 1.5, "ModelID: " .. GetEntityModel(entttt))
            DrawText3D(xo,yo,zo + 1.4, "NetID: " .. NetworkGetNetworkIdFromEntity(entttt))
		end
    end
end)

RegisterCommand("clear", function()
isset = false
end, false)

The Model ID is a hash for the vehicle (it always works just supply it to your spawn script as the vehicle you wanna spawn it will know what you want. its literally what you get when you GetHashKey() Something

Theres also the built in runcode resource for debugging if you didnt know about that (its really useful!)

you just load it up in your browser (go to your server ip so like example.com:30120/runcode/ while its running) and you can paste the code run it

edit: also. almost forgot. you aim at the target object with that little codeblob and press E to display the information then just write or type it down somewhere (netids can be useful too but they are NOT static values and they dont seem to be perfectly synced across clients either…

Hello everyone.

Just pulled the fix for OneSync :wink:
Have fun guys !

1 Like

Yeah, and it has been confirmed (by @Nickoos), with screenshots and all, so please stop (private) messaging me that it doesn’t work for OneSync due to the ‘native spawning system’ :rofl: :joy: because it DOES indeed work (only the ‘hardcap’ had to be removed).

working fine for me with onesync. only issue im seeing is that sometimes the trains do a uturn on non existing tracks or drives through buildings at times? and multiple trains are on the same track as well lol so fars its pretty awesome though!

1 Like

The WHAT? haha, sorry for laughing but I haven’t seen this at all :rofl:

I’m aware of the multiple trains spawning sometimes though, but making ‘abnormal U-Turns’ or driving through buildings??? Nope haha,

ALMOST… makes me want to install FiveM and GTA V again to see it happen ‘live’ haha.

Unfortunately there would not be much I would be able to do against that behavior (except the multiple spawning maybe), because the rest is just a native game script which is being activated (maybe having some memory address issues, wrong parameters or even just conflicts with other functions being called)

Thanks for your ‘compliment’ though :slight_smile: and also thanks for confirming that it ‘does work’ for you on OneSync to :slight_smile:

yeah if it happens again ill take a pic of it lmao shit was hilarious. best part was a member was on it when it happened and… didnt make it lmao

this script literally made our day. hopefully you install fivem again cuz this is freaking awesome!

I’m dying here, seriously :rofl: :rofl: I’m litterally laughing out loud while at the office hahaha.

“The Horror” he must have "experienced’, being on a train and just seeing it happing, reaching that “I’m f*cked moment, but can’t do jack about it” :rofl: :rofl: :rofl: :rofl: :rofl:

I seriously hope (for that member) that your server isn’t an extremely serious RL-RP (RealLife-RolePlay) server. Because mine was, with A LOT of super realism, which “unfortunately” also meant for players that if they got hospitalized so badly that GTA V would consider you “dead”, that it would cost them a SHITLOAD of money to ‘recover’ from it :rofl: :rofl::rofl::rofl::rofl::rofl:

hmm for some reason the trains spawned that one time but now they dont spawn at all