-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(net/five): correct train track node on ownership change #2911
Conversation
Excellent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! It looks like a really valuable change. Left some minor comments.
But also, do you have a good way to reproduce/test it? I tried to play with it locally:
- Put one player in a carriage of a train. Make sure that this player is the owner.
- Get second player on the train as well.
- See
netObjectMgrBase__ChangeOwner
being called, but the code never reaches theCTrain__SetTrainCoord(train, -1, -1);
part. Seems like(CTrain__IsCarriageEngine(train) && *(int*)((char*)train + TrainTrackNodeIndexOffset) == 0)
check is always false in my case. - Disconnect the first player.
- After some time train disappears even tho second player in in a carriage.
Do I misunderstand the use case or this? Am I doing something wrong?
This issue isn't related to ownership changing between players as in most (if not all cases) the client becoming owner should already have knowledge of the track node the train is located on. However, in cases where the server was the previous owner (in cases where no player is in the trains scope to have ownership over the train) the client becoming owner will have no knowledge of the trains current track node. Causing the train to reset to node 0 regardless of where it actually is.
I've also attached the repro resource i used to test this. (find a train track, do /train on the client to create a train. Leave the scope and return) |
ecc189a
to
15365dd
Compare
15365dd
to
6facbc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested it locally and can confirm that it works and makes the difference. Thank you for the great job!
PS: For some reason couldn't trigger train owner change with just one player - everything worked even without fix. But if I use one player to spawn the train, disconnect and use second to fly close to the train - then without the fix train disappears, while with the fix it stays where it should.
There was some instances when testing this patch where I had to decrease the trains Culling distance to 424 (onesync's default scope range). Since even going 4000+ units away from the train's position would still cause it to be relevant for the owning client. I haven't had time to investigate why this would happen though and it does seem to be inconsistent. Though from testing and feedback from others using trains in a production environment. Trains behave very weirdly in OneSync / GTA:O especially with ownership reassignment (issues such as randomly detaching train carriages, negative speeds breaking train blending). Hoping to address some more of these issues in the future. |
I'm so excited for this! |
@Ehbw for spawning trains will we have to do anything differently now to be able to utilize this commit or not really? Currently on client we run this snippet for NPC trains. We use another different system for drivable trains though.
|
If you are already using the server orphan natives. No. |
Goal of this PR
Fixes scenarios where a train becomes owned by the server (orphan natives) and upon a player re-entering the trains scope and becoming owner of the train, The train resets to the node 0 of the track it is currently on
How is this PR achieving the goal
By forcing the train to find its current track node based on the trains current position, only upon ownership change to a player from a server and if the new client has no knowledge of the trains current track node.
This PR applies to the following area(s)
FiveM
Successfully tested on
Game builds: 1604, 2372, 2545, 2802, 3258
Platforms: Windows
Checklist
Fixes issues