Access Faction System From Game Code

#1
Hi.
I'm currently having issues to generally access AI functionality from game code.
What I'm currently trying to do is to set an entity's faction from code. My current approach:

Code: Select all

m_pFactionComponent = m_pEntity->GetOrCreateComponent<IEntityFactionComponent>(); m_pFactionComponent->SetFactionId( ??? );
The "???" is the part that I don't know. This function (SetFactionId) takes a uint8 as a parameter. However I don't know the uint8 id number of my available factions (I've already set up factions.xml). So I thought I just get it from the FactionMap. If you look here at the FactionMap (line 41): https://github.com/CRYTEK/CRYENGINE/blo ... ctionMap.h
it has the function:
virtual uint8 GetFactionID(const char* szName) const override;

This seems to be exactly what I want. And how do I get the FactionMap? My approach would be from the FactionSystem. If you look at this (line 45): https://github.com/CRYTEK/CRYENGINE/blo ... onSystem.h
you'll find the function
CFactionMap* GetFactionMap() { return &m_factionMap; }

So my approach would be to get the FactionSystem form game code. Then get the FactionMap from it and then use the GetFactionID function to get the faction id by the faction's name.

The problem is: It seems as if I'm not able to access the FactionSystem.
If I write gEnv->pAISystem, it seems as if the pAISystem doen't have any accessable members or functions. Can anyone help me out here? Thanks.

- Jannis

Re: Access Faction System From Game Code

#3
Thank you so much. My problem was that I included <CryAISystem/IFactionMap.h> but I forgot about <CryAISystem/IAISystem.h>. I feel kind of dumb now :D Thanks.

However I sadly got a new problem. If I just include <CryAISystem/Components/IEntityFactionComponent.h> then I'll get a lot of errors when I try to build. I just commented out all code related to it to test it. Without the IEntityFactionComponent.h, everything compiles fine. With it, I get the attached errors.
Errors.png
Errors.png (84.39 KiB) Viewed 1531 times

Re: Access Faction System From Game Code

#4
Looks like it might be another missing include

Code: Select all

#include "CryAISystem\IFactionMap.h"
Also make sure that you have included the header and cpp files that you have made in the CmakeLists.txt
You can also just Close VS delete the Solution folder and generate the solution again to make sure that everything
is in the CMakeLists.txt file

Also check for missing "}" bracket Sometime that can even happen as well. :D

Re: Access Faction System From Game Code

#5
Thank you very much again. Now I even feel more stupid :D I did #include <CryAISystem/IFactionMap.h>.
But of course I did it after the inclusion of the IEntityFactionComponent.h. Due to your response I realized that the Component needs this and so I have to include it before the Component. So I just moved this include two lines up and everything is fine now. Thank you very much.

Who is online

Users browsing this forum: No registered users and 3 guests

cron