> For the complete documentation index, see [llms.txt](https://docs.minecraftbot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.minecraftbot.com/examples/start-plugins/killaura-advanced.md).

# Killaura (intermediate)

**FightTask.cs**

This task is responsible for targeting, moving, and attacking the closest non-friendly player.

{% tabs %}
{% tab title="Commented Code" %}

```csharp
public class FightTask : ITask, ITickListener
    {
        private string[] Friendly;

        public FightTask(string[] friendly) {
            this.Friendly = friendly;
        }

        public override bool Exec() {
            return !Context.Player.IsDead() && !Context.Player.State.Eating;
        }

        public async Task OnTick() {

            // Get the closest player to us that is not in our friends list.
            var target = Context.Entities.GetClosestPlayer(false,
                         entity => !Friendly.Contains(entity.GetName()));
            if (target == null)
                // No target found, so do nothing this tick.
                // Optionally you could make the bot roam in this case.
                return;

            // Begin moving towards the target. We do not await for the task
            // to complete since we also want to attack the target while we
            // are running.
            var movementTask = target.Follow();

            // Find the best sword in our inventory and attempt to select it.
            // This should/could be in a different task, as this task should
            // be only responsible for moving and attacking targets.
            var sword = Inventory.FindBest(EquipmentType.Sword);
            if(sword != null) await sword.Select();

            // Run this for as long as we are chasing this player OR
            // if we are already very close to the target player.
            while (movementTask.IsMoving() ||
                   target.Position.Distance(Context.Player.GetPosition()) < 2) {
                
                // Only attack the player if it is within 4 blocks to us.
                if(target.Position.Distance(Context.Player.GetPosition()) < 5)
                    target.Attack();

                // Wait 2 ticks before each attack.
                await Context.TickManager.Sleep(2);
            }
        }
    }
```

{% endtab %}

{% tab title="Raw Code" %}

```csharp
public class FightTask : ITask, ITickListener
    {
        private string[] Friendly;

        public FightTask(string[] friendly) {
            this.Friendly = friendly;
        }

        public override bool Exec() {
            return !Context.Player.IsDead() && !Context.Player.State.Eating;
        }

        public async Task OnTick() {

            var target = Context.Entities.GetClosestPlayer(false, entity => !Friendly.Contains(entity.GetName()));
            if (target == null) return;

            var movementTask = target.Follow();

            var sword = Inventory.FindBest(EquipmentType.Sword);
            if(sword != null) await sword.Select();

            while (movementTask.IsMoving() ||
                   target.Position.Distance(Context.Player.GetPosition()) < 2) {
                
                if(target.Position.Distance(Context.Player.GetPosition()) < 5)
                    target.Attack();

                await Context.TickManager.Sleep(2);
            }
        }
    }
```

{% endtab %}
{% endtabs %}

**RespawnTask.cs**

This task is responsible for respawning the bot when it dies.&#x20;

```csharp
    public class RespawnTask : ITask, IDeathListener
    {
        public override bool Exec() {
            return true;
        }

        public async Task OnDeath() {
            await Context.Player.Respawn();
        }
    }
```

{% file src="/files/-LtGcvuNGvR0xvdmwDq7" %}
Full Plugin Source Code
{% endfile %}
