Skip to content
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

feat(extra-natives/five): track switching #3044

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ehbw
Copy link
Contributor

@Ehbw Ehbw commented Dec 26, 2024

Goal of this PR

Introduce a way to register track switching. Track switching allows for a train to change the track index it is currently navigating along. Suggested by @glitchdetector

How is this PR achieving the goal

introduces REGISTER_TRACK_SWITCH and SET_TRACK_SWITCH_ACTIVE to allow for registration of a train switch and ability to enable/disable the track switch

This PR applies to the following area(s)

FiveM, Natives

Successfully tested on

A test resource showing the functionality plus invalid use cases that are accounted for
track-swapping-example.zip

Game builds: 1604, 2060, 3258, 3407

Platforms: Windows

Checklist

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

Fixes issues

@Ehbw Ehbw force-pushed the feat/track-switching branch from 155f6ac to b027b49 Compare December 26, 2024 22:13
@github-actions github-actions bot added triage Needs a preliminary assessment to determine the urgency and required action invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Dec 26, 2024
@TheGamerzs
Copy link
Contributor

TheGamerzs commented Jan 4, 2025

Great feature.

Using the example, when the train gets to the end track node after a switch, it warps back to the old track to the node index of:
(Not verified) OldSwitchNode - NewSwitchNode (in the example it seems: 3899 - 87)

I tested this with multiple clients:
If two clients have a different value for a switch (or not registered)
And one of the clients is standing on the train engine or carriages they will fling up in the sky, at the switch node

(Not sure if related to the native or my (VM or hardware))
I had two clients (cl2).
Client A registered the switch and created the train.
Client B (No switch registered) then was driving the train with Client A on a carriage.
Client B then began switching tracks (Unexpected behaviour), this seemed to switch fine.
Once Client B got to the end of the track and warped back (to the first issue location), my graphics stopped streaming new ~~~~assets then the issue with textures being a massive triangle then froze the VM
(Only happened when testing this)
This was my VM error.

@Ehbw
Copy link
Contributor Author

Ehbw commented Jan 4, 2025

If two clients have a different value for a switch (or not registered)
And one of the clients is standing on the train engine or carriages they will fling up in the sky, at the switch node

That's to be expected. When using this in a script you should ideally register the same value across all clients.

Client A registered the switch and created the train.
Client B (No switch registered) then was driving the train with Client A on a carriage.
Client B then began switching tracks (Unexpected behaviour), this seemed to switch fine.
Once Client B got to the end of the track and warped back (to the first issue location), my graphics stopped streaming new assets then the issue with textures being a massive triangle then froze the VM

The freezing does seem to be unrelated and tied to your VM. Although with the example I provided, the track it switches to is marked as a loop track (although it does not create an actual loop) rather then something like a ping-pong track and therefore will teleport back to node 0 (which is located close to the train tunnel in that area of the map)

Comment on lines +316 to +318
if (newTrack->m_nodeCount < newTrackNode)
{
fx::scripting::Warningf("natives", "REGISTER_TRACK_SWITCH: Invalid toNode was passed (%i), should be from 0 to %i\n", newTrackNode, newTrack->m_nodeCount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (newTrack->m_nodeCount < newTrackNode)
{
fx::scripting::Warningf("natives", "REGISTER_TRACK_SWITCH: Invalid toNode was passed (%i), should be from 0 to %i\n", newTrackNode, newTrack->m_nodeCount);
if (newTrack->m_nodeCount - 1 < newTrackNode)
{
fx::scripting::Warningf("natives", "REGISTER_TRACK_SWITCH: Invalid toNode was passed (%i), should be from 0 to %i\n", newTrackNode, newTrack->m_nodeCount - 1);

Stops Out Of Bounds stuff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Requires changes before it's considered valid and can be (re)triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants