Skip to content

Commit

Permalink
feat(extra-natives/five): add getters for new track junction
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGamerzs committed Feb 26, 2025
1 parent 0dec7bf commit 34ff92a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
43 changes: 43 additions & 0 deletions code/components/extra-natives-five/src/TrackNatives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ static InitFunction initFunction([]()
}
});

fx::ScriptEngine::RegisterNativeHandler("GET_TRACK_JUNCTION_COUNT", [](fx::ScriptContext& context)
{
context.SetResult<int>(g_trackJunctions.size());
});

fx::ScriptEngine::RegisterNativeHandler("REGISTER_TRACK_JUNCTION", [](fx::ScriptContext& context)
{
int8_t trackIndex = context.GetArgument<int8_t>(0);
Expand Down Expand Up @@ -425,6 +430,44 @@ static InitFunction initFunction([]()
context.SetResult<bool>(true);
});

fx::ScriptEngine::RegisterNativeHandler("IS_TRACK_JUNCTION_ACTIVE", [](fx::ScriptContext& context)
{
size_t junctionIndex = context.GetArgument<size_t>(0);

const std::lock_guard _(g_trackJunctionLock);

if (junctionIndex >= g_trackJunctions.size())
{
fx::scripting::Warningf("natives", "IS_TRACK_JUNCTION_ACTIVE: Invalid junction id (%i) provided. There are %i registered junctions\n", junctionIndex, g_trackJunctions.size());
context.SetResult<bool>(false);
return;
}

context.SetResult<bool>(g_trackJunctions[junctionIndex].isActive);
});

fx::ScriptEngine::RegisterNativeHandler("GET_TRACK_JUNCTION_INFO", [](fx::ScriptContext& context)
{
size_t junctionIndex = context.GetArgument<size_t>(0);

const std::lock_guard _(g_trackJunctionLock);

if (junctionIndex >= g_trackJunctions.size())
{
fx::scripting::Warningf("natives", "GET_TRACK_JUNCTION_INFO: Invalid junction id (%i) provided. There are %i registered junctions\n", junctionIndex, g_trackJunctions.size());
context.SetResult<bool>(false);
return;
}

context.SetResult<bool>(true);

*context.GetArgument<int*>(1) = g_trackJunctions[junctionIndex].onTrack;
*context.GetArgument<uint32_t*>(2) = g_trackJunctions[junctionIndex].onNode;
*context.GetArgument<int*>(3) = g_trackJunctions[junctionIndex].newTrack;
*context.GetArgument<uint32_t*>(4) = g_trackJunctions[junctionIndex].newNode;
*context.GetArgument<bool*>(5) = g_trackJunctions[junctionIndex].direction;
});

fx::ScriptEngine::RegisterNativeHandler("GET_TRACK_NODE_COORDS", [](fx::ScriptContext& context)
{
int8_t trackIndex = context.GetArgument<int8_t>(0);
Expand Down
14 changes: 14 additions & 0 deletions ext/native-decls/GetTrackJunctionCount.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_TRACK_JUNCTION_COUNT

```c
int GET_TRACK_JUNCTION_COUNT();
```


## Return value
Returns the number of track junctions
21 changes: 21 additions & 0 deletions ext/native-decls/GetTrackJunctionInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
ns: CFX
apiset: client
game: gta5
---
## GET_TRACK_JUNCTION_INFO

```c
bool GET_TRACK_JUNCTION_INFO(int junctionId, int* trackIndex, int* trackNode, int* newIndex, int* newNode, bool* direction);
```
## Parameters
* **junctionId**: The track junction handle
* **trackIndex**: The track index a train should be on
* **trackNode**: The node a train should be on
* **newIndex**: The new track index for a train to be placed on
* **newNode**: The new track node for a train to be placed on
* **direction**: The direction a train should be traveling for this junction
## Return value
Returns true if junction id is valid, false otherwise.
16 changes: 16 additions & 0 deletions ext/native-decls/IsTrackJunctionActive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ns: CFX
apiset: client
game: gta5
---
## IS_TRACK_JUNCTION_ACTIVE

```c
bool IS_TRACK_JUNCTION_ACTIVE(int junctionId);
```
## Parameters
* **junctionId**: The track junction handle
## Return value
Returns wether the track junction is active, if invalid junction id returns false

0 comments on commit 34ff92a

Please sign in to comment.