> 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/subitem.md).

# npc.subitem

```lua
npc.subitem(item, count)
```

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

## What it does

Takes an item from the party, with no notice; the count stops at 0. Returns the new count.

## Arguments

### `item` (Int)

The id (`data/inv-*.csv`). Vanilla: `0x2000` (Teleport Stone) and key items most often.

### `count` (Int)

How many to take.

## Result

The new count.

## Timing

Returns at once.

## In NPC Kit

Check first with [haveitem](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/haveitem.md) in `npc.lua`, then take it in a named function:

```lua
take = function()
    npc.subitem(0x8079, 1);
end,
-- in the Lua: if count > 0 then handle.run("take", ...) end
```

## Used with

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

## Example

The NPC takes the item it asked for, only when the player has it.

```lua
local noKey = [[
No key, no door. That's how it works around here,
and I don't make exceptions for anyone at all.
]]

local takeKey = [[
I'll take that key, thanks. You won't need it now,
the door stays open for you from this day on.
]]

take = function()
    npc.subitem(0x8079, 1);
end,

talk = function()
    talkOpen();
    npc.lua(npc.haveitem(0x8079), function(handle, count)
        if count == 0 then
            say(handle, noKey)
            return
        end
        handle.run("take", function() say(handle, takeKey) end)
    end);
    talkClose();
end,
```

## Pitfalls

* Take it in a named function after the check: a `subitem` recorded in `talk` itself runs on every talk, whatever the player has.
