> For the complete documentation index, see [llms.txt](https://fehdead.gitbook.io/npc-kit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/distance.md).

# npc.distance

```lua
npc.distance(a, b)
```

|                         |                                                                         |
| ----------------------- | ----------------------------------------------------------------------- |
| id                      | `0x028F`                                                                |
| arguments               | 2: Int, Int                                                             |
| result                  | int: goes to the very next call, or to `npc.lua(npc.distance(...), fn)` |
| in NPC Kit              | yes                                                                     |
| measured from a kit NPC | returns                                                                 |
| vanilla scripts         | 332 calls in 34 of 1114 scripts                                         |

## What it does

Gives the distance on the ground between two actors (height left out). A result.

## Arguments

### `a` (Int)

### `b` (Int)

The two actors: `-1` the character the player controls, in the kit another NPC with `npc.actor("id")` (in a talk).

## Result

The distance, a float.

## Timing

Returns at once.

## In NPC Kit

`npc.lua(npc.distance(-1, npc.actor("npckit_0021")), fn)` hands it to Lua cut to an integer. For "walk until close", [waitdistance](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/waitdistance.md) waits on a point instead.

## Used with

* [waitdistance](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/waitdistance.md).

## Example

An NPC that answers differently when its friend stands close.

```lua
talk = function()
    talkOpen();
    npc.lua(npc.distance(npc.actor("npckit_0020"), npc.actor("npckit_0021")), function(handle, d)
        say(handle, d < 3 and "My friend here will vouch for me." or "Where did he go now?")
    end);
    talkClose();
end,
```

## Pitfalls

* An index with no actor behind it measures from the map origin `(0, 0)`; there is no error.
* Cut to an integer in Lua: `2.9` is `2`.
