Skip to content

Commit

Permalink
feat(gamestate/server): ped AI node getter
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniGP17 committed Jan 10, 2025
1 parent c95b323 commit 8b4fcc4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,12 @@ struct CPedMovementGroupNodeData
bool isRagdolling;
};

struct CPedAINodeData
{
int relationShip;
int decisionMaker;
};

enum ePopType
{
POPTYPE_UNKNOWN = 0,
Expand Down Expand Up @@ -851,6 +857,8 @@ struct SyncTreeBase

virtual CPedMovementGroupNodeData* GetPedMovementGroup() = 0;

virtual CPedAINodeData* GetPedAI() = 0;

virtual void CalculatePosition() = 0;

virtual bool GetPopulationType(ePopType* popType) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2468,7 +2468,16 @@ struct CPedMovementGroupDataNode
}
};

struct CPedAIDataNode { };
struct CPedAIDataNode
{
CPedAINodeData data;
bool Parse(SyncParseState& state)
{
data.relationShip = state.buffer.Read<int>(32);
data.decisionMaker = state.buffer.Read<int>(32);
return true;
}
};

struct CPedAppearanceDataNode
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,11 @@ struct SyncTree : public SyncTreeBaseImpl<TNode, true>
return nullptr;
}

virtual CPedAINodeData* GetPedAI() override
{
return nullptr;
}

virtual void CalculatePosition() override
{
// TODO: cache it?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,12 @@ static void Init()
return 0;
}));

fx::ScriptEngine::RegisterNativeHandler("GET_PED_RELATIONSHIP_GROUP_HASH", makeEntityFunction([](fx::ScriptContext& context, const fx::sync::SyncEntityPtr& entity)
{
auto ped = entity->syncTree->GetPedAI();
return ped ? ped->relationShip : 0;
}));

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

```c
Hash GET_PED_RELATIONSHIP_GROUP_HASH(Ped ped);
```
Gets the current relationship group hash of a ped.
## Parameters
* **ped**: The target ped
## Return value
The relationship group hash.

0 comments on commit 8b4fcc4

Please sign in to comment.