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

# npc.haveitem

```lua
npc.haveitem(item)
```

|                         |                                                                         |
| ----------------------- | ----------------------------------------------------------------------- |
| id                      | `0x02E4`                                                                |
| arguments               | 1: Int                                                                  |
| result                  | int: goes to the very next call, or to `npc.lua(npc.haveitem(...), fn)` |
| in NPC Kit              | yes                                                                     |
| measured from a kit NPC | returns                                                                 |
| vanilla scripts         | 4044 calls in 182 of 1114 scripts                                       |

## What it does

Gives how many of an item the party holds. A result.

## Arguments

### `item` (Int)

The item id (`data/inv-*.csv`): `0x0000+` items, `0x1000+` equipment, `0x2000+` loot, `0x8000+` key items. Vanilla's most common: `0x2000` and `0x8079`.

## Result

The count, `0` or more.

## Timing

Returns at once.

## In NPC Kit

Branch on it in Lua:

```lua
local found = [[
You have it! Show it to me, quickly, come on.
I've waited so long to see it with my own eyes.
]]

local notYet = [[
Come back when you've found it, and not before.
I'll be right here waiting for you, as always.
]]

npc.lua(npc.haveitem(0x8079), function(handle, count)
    if count > 0 then
        say(handle, found)
    else
        say(handle, notYet)
    end
end);
```

## Used with

* [additem](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/additem.md), [additemmes](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/additemmes.md), [subitem](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/subitem.md): give and take.
* [havegill](https://fehdead.gitbook.io/npc-kit/vm-reference/calls/havegill.md): the same for gil.

## Example

A quest giver that answers by what the player carries, and gives a reward once.

```lua
local thanksAgain = [[
Thanks again, friend. I owe you more than coin,
and I won't ever forget what you did for me here.
]]

local reward = [[
You found it! Here, take these, you've earned it.
It's the least I can do after all your trouble.
]]

local request = [[
Bring it back to me, and I'll make it worth it.
I pay very well for things that others call lost.
]]

local rewarded = false

reward = function()
    npc.subitem(0x8079, 1);
    npc.additemmes(0x0000, 3);      -- 3 Potions
end,

talk = function()
    talkOpen();
    npc.lua(npc.haveitem(0x8079), function(handle, count)
        if rewarded then
            say(handle, thanksAgain)
        elseif count > 0 then
            handle.run("reward", function()
                rewarded = true
                say(handle, reward)
            end)
        else
            say(handle, request)
        end
    end);
    talkClose();
end,
```

## Pitfalls

* `rewarded` lives while the game runs, not in the save: after a reload the NPC rewards again.
