Jump to content

Freights Trailers ?


InDev

Recommended Posts

If you do find a way to do it, good luck getting the trains to drive normally. There's a weird circumstance that happens whenever I drive a train. It will speed up all of a sudden, going really fast as if a hack was present on it, often causing derailment. Unless you can circumvent that issue if you experience that as well, I wouldn't invest too much effort into making a huge train.

Link to comment

Mmm, attachElements is good but the trailer bug: he disappear and appear with the angle of the camera and has no collision

and he get out of the rails in the turnings so if there is more than one trailer it will make some problems...

In the GTA:SA the trailers are attached by a function i think, there is probably a way to make it ?

Link to comment

I'm speaking here from the lua side since I don't know how MTA works internally for trains.

+With regards to the problem of train sudden high speed: indeed this is weird. Also in some turns the train goes pretty slow.

The solution I use is to have a custom handling of trains: using forward and brake_reverse to set a "desired speed" (with some acceleration and deceleration factors too). This desired speed is then used directly with https://wiki.multitheftauto.com/wiki/SetTrainSpeed either each frame or with a small enough timer. This guarantees that the train stays at the requested speed, whatever the nature of the track (turn, slope, etc.).

You can have a look at the result on the DKR Clan server: mtasa://94.76.220.253:44004

+With regards to the trailers:

Indeed even if well positioned attachTrailerToVehicle doesn't seem to work, I have therefore tried several things:

- Since I use a custom handling and set SetTrainSpeed for the front train, it can be done too for the trailers. You can either do script based trailer creation or detect the trailer behind with https://wiki.multitheftauto.com/wiki/ProcessLineOfSight

In practice you'll see that even with the same setTrainSpeed, over time some gaps tend to form. So you have to accelerate/slow down the trailers depending on their distance to the train.

I don't have the code for it anymore because it was not really perfect. Either done clientside or client requesting serverside setTrainSpeed, it was not smooth enough.

- A better way is to play with the position (and velocities) of the trailers directly. Using matrix transformations and appropriate train/trailer sizes, it's easy to determine what the position of a following trailer should be. In turns it still works well enough if you propagate correctly from one trailer to the other. However with more than 3 trailers I had a problem in some parts of the track in LS only (could see up to 10 trailers though).

This solution, if the sizes/offsets are well approximated, works well however now the main problem is synchronization.

Done client side, this looks great for the driver, if nothing is done serverside, then other people won't see the trailers move.

I tried to have the driver send the expected positions of his trailers and the server dispatch this information to all other (not the driver*) players. *In order to have the driver side always represent the "truth". This works well with few players but on a real scale server this caused massive server lag so I had to disable it.

Since it works well for the client that does it, a good way to have it working really in a multiplayer fashion would be to let MTA handle the trailers sync and not do it manually from LUA, with a function like setElementSyncer done on the trailers to set the front train driver as the syncer for the trailers.

This has been discussed here already:

https://forum.multitheftauto.com/viewtop ... er#p299824

so now I'm waiting to see when/if it will be implemented.

Link to comment

I haven't read question properly. It was very late morning before I went to bed, apologies. attachElements is not the way to go for this. MTA's trains aren't perfect and tend to be buggy. So, either follow Kayl's directions because setting trailers speed would be the way to go around it or wait for MTA to get these train bugs resolved (it may take some time).

Link to comment

No sorry karlys is specificated to our server because this is not finished and there are many useless things (for tests) and that my brother must remove and it can still simplify it !But he will think of it.

But maybe he will say to you how to make. :wink:

Link to comment

I'm on forum MTA but with the account of Famas because I no idea of username ^^

After this topic of Famas:

Ok thanx for all guys i will try to getTrainSpeed on the train and apply it with setTrainSpeed on the trailers i think it's gonna work...

PS:

setElementSyncer will be good :D

It's me who aswered :mrgreen: Because I didn't think that you would like to speak to me!

So I will have an account soon and I will identify me by "(Brother)" at the end of my reply while waiting.

(Brother)

Link to comment

Not very conclusive video.

I see only one person on the video.

Show us the same thing on a server with 90 people with at least 10 persons driving trains at the same time and the video being taken by someone not driving a train (and streaming in the moving train and its trailer during the video)

Then we'll see how good this "secret" solution is.

Given the elements displayed I'm afraid this is using the setTrainSpeed solution, which, as you will see on a real scale server can be a bit laggy and not as pretty sometimes. But at least it's a working solution.

Link to comment

I use peds who driving the trailer ! :mrgreen:

The peds in freights trailers make the same action that the ped in train at the same time (setPedControlState...)

The peds are invisible with the function setElementAlpha(..., 0)

All freights trailers and the peds and the train can't to be stream (setElementStreamable(..., false ))

And if the freights trailers deviate compared to the train, the freights trailers will be replaced with setElementPosition

I'm agree that with 90 players the system will lag so maybe I will make the same system with setTrainSpeed or simplified this system

But I didn't understand:

with at least 10 persons driving trains at the same time and the video being taken by someone not driving a train (and streaming in the moving train and its trailer during the video)

The Famas's brother

Link to comment

Ok, funny idea.

However setPedControlState is clientside so it works well on your screen only. Did you try with other people with you?

When I mention the stream in problem it's because I tried in the past to use peds to control vehicles. It worked well until someone approached the vicinity of the original position of the vehicle controlled by the ped. Since you are not the syncer of a vehicle not controlled by yourself, the server didn't know it moved hence sent the old position to the new comer.

setTrainSpeed has two versions, one of which is serverside and seem to work well as long as someone stays in the vicinity of the moving train/trailers. In order not to overload the server with that, I used "timed" calls (client knowing what the speed should be > server setting the speed) however the result was not perfect (some jittering).

Link to comment

Yes but it's always an idea :mrgreen:

No I didn't test yet with an other player and I see very well that you want to say.

The peds and trains are create in serverside so evrybody see. But like setPedControlState is placed in clienside, I see the train accelerated but other players see the train always at station ?

I tried in the past to use peds to control vehicles. It worked well until someone approached the vicinity of the original position of the vehicle controlled by the ped. Since you are not the syncer of a vehicle not controlled by yourself, the server didn't know it moved hence sent the old position to the new comer.

Maybe if you use setElementStreamable(yourped,false) in server-side (after that you are created the ped of course) that will not arrive !

The Famas's brother

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...