# Combat API

## Knockback AI

Knocks back the AI (like with the Knockback Module) based on the set parameters.

{% hint style="warning" %}
**Important:** This will need to be added manually where your Character Controller damages an AI target or when you would like to cause a knockback effect.
{% endhint %}

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.KnockbackAI(Vector3 Direction, Transform Target, ICombat TargetICombat, float KnockbackDistance = 2.5f, float KnockbackDuration = 0.25f, float MovementDelay = 0.25f)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Knocks back the AI from its forward facing direction using the default settings (2.5 units over 0.25 seconds)
EmeraldAI.EmeraldAPI.Combat.KnockbackAI(-transform.forward, transform, GetComponent<EmeraldAI.ICombat>());
```

{% endcode %}

## Trigger Ability

Overrides the AI's current ability and attack distance so the ability can be used when called (given within distance).

{% hint style="warning" %}
&#x20;**Important:** The AI's attack animation index (from an AI's Animation Profile's Attack List) is required. If the attack animation index does not exist within the AI's Attack List, there will be an error.
{% endhint %}

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.TriggerAbility(EmeraldSystem EmeraldComponent, EmeraldAbilityObject AbilityObject, int AttackDistance, int AttackAnimationIndex)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.TriggerAbility(EmeraldComponent, DesiredAbilityObject, DesiredAttackDistance, AttackAnimationIndex);
```

{% endcode %}

## Kill AI

Instantly kills this AI.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.KillAI(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.KillAI(EmeraldComponent);
```

{% endcode %}

## Reset AI

Resets the AI so it can be reused (can also be used for custom mechanics such as reviving).

{% hint style="info" %}
&#x20;**Note:** This is automatically called when an AI is killed and then re-enabled.
{% endhint %}

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.ResetAI(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.ResetAI(EmeraldComponent);
```

{% endcode %}

## Get Distance From Target

Returns the current distance between the AI and their current combat target (Returns -1 if the Combat Target is null).

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.GetDistanceFromTarget(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.GetDistanceFromTarget(EmeraldComponent);
```

{% endcode %}

## Get Combat Target

Returns the AI's combat target.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.GetCombatTarget(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.GetCombatTarget(EmeraldComponent);
```

{% endcode %}

## Set Combat Target

Assigns a specified combat target for your AI to attack within the AI's Detection Radius. Note: Targets outside of an AI's Detection Radius will be ignored. If you want no distance limitations, use OverrideCombatTarget(Transform Target).

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.SetCombatTarget(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.SetCombatTarget(EmeraldComponent, YourTargetTransform);
```

{% endcode %}

## Override Combat Target

Assigns a specified combat target for your AI to attack ignoring any distance limitations. If the target is not within attacking range, the AI will move to the target's position and attack based on its attack distance, even if it is outside of its detection radius.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.OverrideCombatTarget(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.OverrideCombatTarget(EmeraldComponent, YourTargetTransform);
```

{% endcode %}

## Flee From Target

Makes an AI flee from the specified target by switching their behavior to Coward. The AI will remain with the Coward until it is reset manually.

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp"><strong>EmeraldAPI.Combat.FleeFromTarget(EmeraldSystem EmeraldComponent, Transform Target)
</strong></code></pre>

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.FleeFromTarget(EmeraldComponent, YourTargetTransform);
```

{% endcode %}

## Search For Closest Target

Searches for a new target within the AI's Detection Radius closest to the AI.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.SearchForClosestTarget(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.SearchForClosestTarget(EmeraldComponent);
```

{% endcode %}

## Search For Random Target

Searches for a new random target within the AI's Detection Radius.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.SearchForRandomTarget(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.SearchForRandomTarget(EmeraldComponent);
```

{% endcode %}

## Get Last Attacker

Returns the transform that last attacked the AI.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Combat.GetLastAttacker(EmeraldSystem EmeraldComponent, Transform Target)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Combat.GetLastAttacker(EmeraldComponent);
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/available-api/combat-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
