fivem icon indicating copy to clipboard operation
fivem copied to clipboard

feat(gamestate/server): CREATE_TRAIN(_CARRIAGE) natives

Open Ehbw opened this issue 1 year ago • 10 comments

Goal of this PR

Allows for server-side creation of functioning trains, to be used in strict and relaxed entity lockdown modes.

How is this PR achieving the goal

By adding the CREATE_TRAIN and CREATE_TRAIN_CARRIAGE to allow for the creation of trains and its carriages through server-setters. The following LOAD_TRAIN_CONFIG_FROM_PATH and LOAD_TRAIN_TRACKS_FROM_PATH are also added to address the issue of the server lacking knowledge of train configurations and train index's. Currently the information is only used to prevent invalid track ID's and train config indexes which cause unintended client behaviour.

Modifications were required for the client, to have server-setter trains behave as intended when re-entering a the scope of a client or changing ownership. By updating the trains current track node to its relative position and then force blending on ownership change (if the server was the last owner). This has no effect on client created trains or trains actively owned by other players.

While creating this PR I also completed the CTrainGameStateDataNode based on the research provided by gottfriedleibniz, and some of my own.

Examples of Invalid and Valid uses of these natives can be found here: https://gist.github.com/Ehbw/c40e88f0686275f4a6fe417573babb64

A functioning script snippet can be found here: https://gist.github.com/Ehbw/ef9d2302c4833bab5b23160588ff3a6f

This PR applies to the following area(s)

FiveM, Server, Natives

Successfully tested on

Builds prior to the tuners update (2372) results in all trains being deleted by the owning client when leaving the owner's scope. This behaviour is identical to client created trains on these same builds. This would be resolved with blocking deletion of any server-owned entity as suggested here https://github.com/citizenfx/fivem/issues/962

Game builds: 1604-3095

Platforms: Windows

Checklist

  • [x] Code compiles and has been tested successfully.
  • [x] Code explains itself well and/or is documented.
  • [x] My commit message explains what the changes do and what they are for.
  • [x] No extra compilation warnings are added by these changes.

Fixes issues

resolves #2197

Ehbw avatar Dec 31 '23 19:12 Ehbw

imo, it would be nice to get the feature out, and then add support for custom tracks later, a working but limited feature is better than no feature

Mycroft-Studios avatar Feb 12 '24 15:02 Mycroft-Studios

any update on this???

Mycroft-Studios avatar Apr 23 '24 12:04 Mycroft-Studios

Any update on this???

FjamZoo avatar May 06 '24 16:05 FjamZoo

Bump, please merge this PR. A lot of work was done in testing this by @Ehbw and this would be an amazing thing to have!

CoZmoTheGod avatar May 16 '24 19:05 CoZmoTheGod

Bump, please merge this PR. A lot of work was done in testing this by @Ehbw and this would be an amazing thing to have!

Yes, would be amazing

spacevx avatar May 19 '24 13:05 spacevx

Any update on this???

CeebDev avatar Jun 20 '24 12:06 CeebDev

Is this essentially something we can use, if merged ofc, in order to rewrite a script such as https://github.com/LexTheGreat/TrainSportation in order to stop so much desync between our client sided trains etc?

please merge this, we want trains

Heisenberg691 avatar Jul 13 '24 14:07 Heisenberg691

please merge this, we want trains

one can only hope heh

:eyes:

spacevx avatar Aug 20 '24 06:08 spacevx