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(server/gamestate): freecam status natives #3068

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,62 @@ static void Init()
return resultVector;
}));

fx::ScriptEngine::RegisterNativeHandler("IS_PLAYER_IN_FREE_CAM_MODE", MakePlayerEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
if (const auto& syncTree = entity->syncTree)
{
if (const auto camData = syncTree->GetPlayerCamera(); camData->camMode != 0)
{
return true;
}
}

return false;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_PLAYER_FOCUS_POS", MakePlayerEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
scrVector resultVec = {};
const auto& syncTree = entity->syncTree;

if (!syncTree)
{
return resultVec;
}

const auto camData = syncTree->GetPlayerCamera();

if (!camData)
{
return resultVec;
}

float playerPos[3];
syncTree->GetPosition(playerPos);

switch (camData->camMode)
{
case 0:
default:
resultVec.x = playerPos[0];
resultVec.y = playerPos[1];
resultVec.z = playerPos[2];
break;
case 1:
resultVec.x = camData->freeCamPosX;
resultVec.y = camData->freeCamPosX;
resultVec.z = camData->freeCamPosZ;
break;
case 2:
resultVec.x = playerPos[0] + camData->camOffX;
resultVec.y = playerPos[1] + camData->camOffY;
resultVec.z = playerPos[2] + camData->camOffZ;
break;
}

return resultVec;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_TRAIN_CARRIAGE_ENGINE", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
auto train = entity->syncTree->GetTrainState();
Expand Down
18 changes: 18 additions & 0 deletions ext/native-decls/GetPlayerFocusPos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
ns: CFX
apiset: server
---

## GET_PLAYER_FOCUS_POS

```c
Vector3 GET_PLAYER_FOCUS_POS(char* playerSrc);
```

Gets the focus position (i.e. the position of the active camera in the game world) of a player.

## Parameters
* **playerSrc**: The player to get the focus position of

## Return value
Returns a `Vector3` containing the focus position of the player.
16 changes: 16 additions & 0 deletions ext/native-decls/IsPlayerInFreeCamMode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
ns: CFX
apiset: server
---

## IS_PLAYER_IN_FREE_CAM_MODE

```c
bool IS_PLAYER_IN_FREE_CAM_MODE(char* playerSrc);
```

## Parameters
* **playerSrc**: The player to get the free camera mode status of

## Return value
Returns if the player is in free camera mode.
Loading