# Giving orders

Tell your allied bots to follow you, guard a spot, fetch items or attack someone.

import { AccordionItem, Accordions } from '@prosefly/astro-components';

Bots in your [faction](/ai-players/guide/factions/), or in a faction allied with yours, take orders from you. Any
player can order the bots on their side, operator or not. With the
[client add-on](/ai-players/guide/client-add-on/#the-orders-screen), press K for a screen that sends the same orders
from buttons.

## The orders

| Order | Example | What the bot does |
| :---- | :------ | :---------------- |
| **follow** | `/aiplayer order Ann follow Alice` | Follows Alice, staying within a few blocks, and fights whatever hurts her. |
| **stay** | `/aiplayer order Ann stay` | Holds the spot where it got the order. |
| **defend** | `/aiplayer order Ann defend 100 64 -20` | Guards that spot (or its own, if you leave the position out) and fights any monster or enemy that comes within 16 blocks. |
| **bring** | `/aiplayer order Ann bring minecraft:iron_ingot 8` | Gets the item (from its inventory, its chests, or by mining and crafting), walks up to you and throws it to you. Up to 64 at a time. |
| **attack** | `/aiplayer order Ann attack Ben` | Fights Ben until he dies. |
| **home** | `/aiplayer order Ann home` | Walks home and stays there. |
| **end** | `/aiplayer order Ann end` | Goes to [the End](/ai-players/guide/the-end/) with its faction's party once it's ready, as if its play style went there. |
| **outer** | `/aiplayer order Ann outer` | Goes on to the outer islands once the End is finished (and to the End first, if it isn't), as if its play style went there. |
| **free** | `/aiplayer order Ann free` | Ends the current order. `free all` clears every order. |

You can order a whole group at once: `@faction red` orders every bot in the red faction, and `@all` every bot
in the game (the ones you're not allowed to order just refuse).

```txt title="Commands"
/aiplayer order @faction red follow Alice
/aiplayer order @all stay
```

:::danger[attack means attack]
`attack` makes the bot fight its target whatever their relation, even if it's an ally, a villager or a player from
a friendly faction. Only its own faction mates are safe, because a faction can't hurt its own members.
:::

## The end and outer orders

`end` and `outer` work differently from the other orders, and the bot doesn't drop everything for them. They flip
a switch so the bot counts as a style that goes to the End, and nothing else changes. It still has to get
**ready** by its own style's bars: its gear at the style's goal and enchanted, its potions, its eyes of ender and
the trip's kit. It tells you once what it still lacks
(`<Ann> Not ready for the End yet, I still need my best armor, enchanted gear`), and until then it lives its
normal life, sleeping, working and answering calls. Once ready, it sets out without waiting for a full party, and
ready mates come along when it calls. A bot on the Easy difficulty refuses both orders with
"Ann cannot: its difficulty does not attempt the End".

An `end` order ends `done` when the faction's End record says the End is finished (the egg is home, or gone). It
ends `died` when the bot dies, and `timed out` like any order, except that the timeout and you leaving the server
are put on hold while the bot is on its trip. If you `free` a bot in the End, it stays with the fight until the exit
portal opens, then goes home through it.

`outer` runs the first trip if the End isn't finished, then the second. It ends `done` when the bot holds or wears
an elytra (or one lies in its faction's chests), or when the city is stripped and its ship looted. A bot freed on
the outer islands goes home back through the gateway while it holds an ender pearl.

`/aiplayer order @faction red end` sends the whole faction. Each bot goes once it's ready, along with whoever else
is ready at that point. See [The End](/ai-players/guide/the-end/#sending-a-bot-yourself).

## Lining up orders

A bot works on one order at a time and keeps up to three more in line. When an order is done, the next one
starts. `free` skips to the next order, and `free all` clears the line.

You get a chat message when one of your orders ends, for example `Ann ended bring cobblestone 8: done`.

## How long orders last

An order ends when:

- the bot finishes it (it brought the items, the attack target died...);
- it can't be done (the bot can't reach the target, for example);
- it runs out of time: **20 minutes** by default, counted from when the bot starts working on it;
- the player who gave it leaves the server;
- someone frees it.

## Bots on duty

While working on an order, a bot still eats, runs from danger and fights back, then gets back to its order. It
won't sleep, go home for the night or do anything else on its own until the order is over. If it dies, it picks
its orders back up after respawning. A bot on an order also answers "No, I am busy" when a faction mate
[calls for help](/ai-players/guide/factions/#calling-for-help), and it doesn't raid. The `end` and `outer` orders
are the exception, since they don't count as duty. A bot under one still answers calls (the `assist` goes in front
of the order, which waits) and lives as usual until its trip starts.

## Bots ordering each other

Bots give orders too. When a bot [calls its faction for help](/ai-players/guide/factions/#calling-for-help) and a
faction mate answers yes, the caller gives that bot an **`assist`** order, telling it to follow the caller and wait
with it until the call is over (or to walk to a bot that says it's stuck). You can't give `assist` with `/aiplayer order` (only a call gives it), but it lives
in the same queue. `/aiplayer info <bot>` shows it (`order: assist Ann from Ann`), `free` ends it, and the usual
timeout applies. The one exception is a party on its way to
[the End](/ai-players/guide/the-end/#the-call-and-the-party), whose `assist` lasts as long as the trip.

## Technical details

<Accordions>
  <AccordionItem title="Who can give orders">
    A player in the bot's faction or an allied faction can order it at permission level 0. Anyone else needs
    permission level 2 (operators, the server console and command blocks have it). With `@faction` or `@all`,
    each bot you're not allowed to order replies with a refusal while the others obey. With `default_relation`
    set to `ally` in the [server configuration](/ai-players/reference/server-config/), every faction player can order
    every bot of a faction that has no explicit relation with theirs. At level 0, a target is named by player name
    or UUID. Selectors like `@e[...]` need level 2.
  </AccordionItem>
  <AccordionItem title="Refused orders">
    - Every order is refused by a bot whose brain is switched off (`debug <bot> auto off`): "\<bot\> is not taking
      orders (auto is off)".
    - `attack` is refused for a creeper, for something that isn't alive (a minecart, say), for the bot itself
      and for a player it can't hurt (creative, spectator, PvP off).
    - `bring` is refused from the server console (there's nobody to bring it to).
    - `home` is refused for a bot without a home.
    - `end` and `outer` are refused for a bot whose difficulty has `end_dragon: false` (the shipped Easy).
    - A fifth order is refused with "queue full".
    - A `stay`, a `defend` post or an escort at a player's side is a wait the player asked for, so the
      [stall guard](/ai-players/guide/how-bots-live/#technical-details) never walks a bot off its post.
  </AccordionItem>
  <AccordionItem title="Timeouts and logging">
    The timeout is `order_timeout_minutes` in the [server configuration](/ai-players/reference/server-config/) (20 by
    default). It's stamped when the order is given but counted from when it becomes active, so an order queued
    behind a `follow` keeps its full time. Replies go to the issuer only. The server log records every accepted
    order, every `free` and every ending, for example `Order for AI player Ann from Alice: follow Alice` and
    `...: follow Alice ended: timed out`. `/aiplayer info <bot>` shows the queue on its `order:` line.
  </AccordionItem>
  <AccordionItem title="Known limits">
    - `bring` throws one stack at a time and counts a throw as delivered, even if you walk away.
    - An `attack` target in another dimension makes the bot wait for the timeout.
    - Orders can't make a bot mine or build something specific yet.
    - An `end` order given once the faction's End is already finished ends `done` right away instead of being refused.
  </AccordionItem>
</Accordions>
