fivem
fivem copied to clipboard
feat(extra-natives/rdr3): Add extra natives for train tracks
Goal of this PR
This PR provides three new natives for RedM for working with train tracks:
- GET_TRACK_COUNT: Returns the number of tracks that are currently loaded in the world.
- GET_TRACK_FROM_INDEX: Returns the name hash of the track at the given index, or 0 if that index is invalid.
-
LOAD_TRACKS_FROM_FILE: Disposes of the currently-loaded tracks and loads new ones from a given
traintracks.xml
file. This allows for fully customized rail networks.
How is this PR achieving the goal
The extra natives can be find in extra-natives-rdr3/src/TrackNatives.cpp
.
GET_TRACK_COUNT
and GET_TRACK_FROM_INDEX
are just directly accessing the track data.
LOAD_TRACKS_FROM_FILE
is based on FiveM's LOAD_WATER_FROM_PATH.
While this approach appears to work without issue, I am not sure how vehicle replication works. If a connecting client doesn't run a resource containing a LOAD_TRACKS_FROM_FILE
call before the server tells it to spawn a replicated train object, the client will crash. I ran a few tests on my local machine with multiple clients, and I did not get any crashes upon logging onto a local server. However, I currently cannot rule out the possibility that a higher ping or larger set of resources to load may delay the execution of a script long enough to cause a crash. More thorough testing may be required unless someone with more intimate knowledge of CFX's vehicle replication system can confirm that this will never be an issue.
This PR applies to the following area(s)
RedM, Natives
Successfully tested on
Game builds: 1491.50
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
Fixes #2424