From b71a0a5d3709297ff2a606b5640260132e492189 Mon Sep 17 00:00:00 2001 From: Daniel GP <96537843+DaniGP17@users.noreply.github.com> Date: Sat, 11 Jan 2025 11:26:06 +0100 Subject: [PATCH] feat(gamestate/server): ped AI node getter --- .../include/state/ServerGameState.h | 8 +++++++ .../include/state/SyncTrees_Five.h | 22 +++++++++++++++++-- .../include/state/SyncTrees_RDR3.h | 5 +++++ .../src/state/ServerGameState_Scripting.cpp | 6 +++++ .../GetPedRelationshipGroupHash.md | 17 ++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 ext/native-decls/GetPedRelationshipGroupHash.md diff --git a/code/components/citizen-server-impl/include/state/ServerGameState.h b/code/components/citizen-server-impl/include/state/ServerGameState.h index 4bb919cf68..6d550a6b8e 100644 --- a/code/components/citizen-server-impl/include/state/ServerGameState.h +++ b/code/components/citizen-server-impl/include/state/ServerGameState.h @@ -757,6 +757,12 @@ struct CPedMovementGroupNodeData bool isRagdolling; }; +struct CPedAINodeData +{ + int relationShip; + int decisionMaker; +}; + enum ePopType { POPTYPE_UNKNOWN = 0, @@ -851,6 +857,8 @@ struct SyncTreeBase virtual CPedMovementGroupNodeData* GetPedMovementGroup() = 0; + virtual CPedAINodeData* GetPedAI() = 0; + virtual void CalculatePosition() = 0; virtual bool GetPopulationType(ePopType* popType) = 0; diff --git a/code/components/citizen-server-impl/include/state/SyncTrees_Five.h b/code/components/citizen-server-impl/include/state/SyncTrees_Five.h index a60d007022..314e7cabb3 100644 --- a/code/components/citizen-server-impl/include/state/SyncTrees_Five.h +++ b/code/components/citizen-server-impl/include/state/SyncTrees_Five.h @@ -2466,9 +2466,20 @@ struct CPedMovementGroupDataNode return true; } -}; +}; + +struct CPedAIDataNode : GenericSerializeDataNode +{ + CPedAINodeData data; -struct CPedAIDataNode { }; + template + bool Serialize(Serializer& s) + { + s.Serialize(32, data.relationShip); + s.Serialize(32, data.decisionMaker); + return true; + } +}; struct CPedAppearanceDataNode { @@ -4068,6 +4079,13 @@ struct SyncTree : public SyncTreeBaseImpl { auto [hasNode, node] = this->template GetData(); + return hasNode ? &node->data : nullptr; + } + + virtual CPedAINodeData* GetPedAI() override + { + auto [hasNode, node] = this->template GetData(); + return hasNode ? &node->data : nullptr; } diff --git a/code/components/citizen-server-impl/include/state/SyncTrees_RDR3.h b/code/components/citizen-server-impl/include/state/SyncTrees_RDR3.h index fc7a6f2882..29543dd531 100644 --- a/code/components/citizen-server-impl/include/state/SyncTrees_RDR3.h +++ b/code/components/citizen-server-impl/include/state/SyncTrees_RDR3.h @@ -1311,6 +1311,11 @@ struct SyncTree : public SyncTreeBaseImpl return nullptr; } + virtual CPedAINodeData* GetPedAI() override + { + return nullptr; + } + virtual void CalculatePosition() override { // TODO: cache it? diff --git a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp index d3edd1a51a..42c71f8f02 100644 --- a/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp +++ b/code/components/citizen-server-impl/src/state/ServerGameState_Scripting.cpp @@ -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(); diff --git a/ext/native-decls/GetPedRelationshipGroupHash.md b/ext/native-decls/GetPedRelationshipGroupHash.md new file mode 100644 index 0000000000..7c72b0fab8 --- /dev/null +++ b/ext/native-decls/GetPedRelationshipGroupHash.md @@ -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. \ No newline at end of file