# Faction API

## Set Faction Level

Changes the relation of the given faction. Note: The faction must be available in the AI's faction list.

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp"><strong>EmeraldAPI.Faction.SetFactionLevel(EmeraldSystem EmeraldComponent, string Faction, RelationTypes RelationType)
</strong></code></pre>

{% code fullWidth="false" %}
```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Faction.SetFactionLevel(EmeraldComponent, "Undead", RelationTypes.Enemy);
```
{% endcode %}

## Add Faction Relation

Adds the Faction and Faction Relation to the AI's Faction Relations List. **Note:** The faction must exist within the Emerald Faction Manager's Faction List.

{% code fullWidth="false" %}
```csharp
EmeraldAPI.Faction.AddFactionRelation(EmeraldSystem EmeraldComponent, string Faction, RelationTypes RelationType)
```
{% endcode %}

{% code fullWidth="false" %}
```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Faction.AddFactionRelation(EmeraldComponent, "Undead", RelationTypes.Enemy);
```
{% endcode %}

## Get Target Faction Relation

Gets the relation of the passed target and this AI in the form of a string (Enemy, Neutral, or Friendly). If a faction cannot be found, or if it is not a valid target, you will receive a value of Invalid Target.

{% code fullWidth="false" %}
```csharp
EmeraldAPI.Faction.GetTargetFactionRelation(EmeraldSystem EmeraldComponent, Transform Target)
```
{% endcode %}

{% code fullWidth="false" %}
```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Faction.GetTargetFactionRelation(EmeraldComponent, YourTargetTransform);
```
{% endcode %}

## Get Target Faction Name

Gets the faction name of the passed AI target. The AI's own transform can also be passed to get its own faction name.

{% code fullWidth="false" %}
```csharp
EmeraldAPI.Faction.GetTargetFactionName(Transform Target)
```
{% endcode %}

{% code fullWidth="false" %}
```csharp
//Example
EmeraldAPI.Faction.GetTargetFactionName(YourTargetTransform);
```
{% endcode %}

## Change Faction

Changes the AI's faction (Note: The FactionName must exists within the Faction Manager's Current Faction list).

{% code fullWidth="false" %}
```csharp
EmeraldAPI.Faction.ChangeFaction(EmeraldSystem EmeraldComponent, string FactionName)
```
{% endcode %}

{% code fullWidth="false" %}
```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Faction.ChangeFaction(EmeraldComponent, "Undead");
```
{% endcode %}

## Copy Faction Data

Copies all faction data from the FactionDataToCopy and applies it to the EmeraldComponent. This is the AI Faction Relations List (within the Faction Settings foldout of the Detection Component).

{% hint style="info" %}
**Note:** The AI's EmeraldComponent is the one who will receive the FactionDataToCopy AI's faction data.
{% endhint %}

{% code fullWidth="false" %}
```csharp
EmeraldAPI.Faction.CopyFactionData(EmeraldSystem EmeraldComponent, EmeraldSystem FactionDataToCopy)
```
{% endcode %}

{% code fullWidth="false" %}
```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Faction.CopyFactionData(EmeraldComponent, TheEmeraldComponentToCopy);
```
{% endcode %}
