> 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/api/starting-template.md).

# Starting Template

**A whole NPC in one file: a Seeq standing in Rabanastre's Muthru Bazaar who tells you he was made with NPC Kit.**

He doesn't walk around or do anything fancy. He stands, idles, turns to you when you talk to him, says one line and turns back. It's the smallest NPC that does everything an NPC needs, and a good place to start from.

Save it as `scripts/MyFirstNpc.lua` in your mod, then enter the Muthru Bazaar (map 290).

```lua
local ok, npc = pcall(require, "scripts.NPCKit.Helper")
if not ok then
    print("Couldn't install, NPC Kit is missing.")
    return
end

local line = [[
I'm an NPC made entirely with NPC Kit, friend.
No .ebp file was edited to put me right here,
only one Lua script in somebody's mod folder.{wait}
Want one of your own? Copy this script, change
the model and the line, and enter the bazaar.
]]

-- What every vanilla talk does: HUD off, turn to the player, talking pose, mouth and nods on.
local function talkOpen()
    npc.sethpmenu(0);
    npc.ucoff();
    npc.settrapshowstatus(0);
    npc.setaturnlookatlockstatus(0);
    npc.raturna(-1);
    npc.turnsync();
    npc.stdmotionplay_2c2(0x01000002, 20);
    npc.setkutipakustatus(1);
    npc.setunazukistatus(1);
end

-- And after it: mouth and nods off, everything back as it was, back to the idle.
local function talkClose()
    npc.setkutipakustatus(0);
    npc.setunazukistatus(0);
    npc.lookatoff();
    npc.ucon();
    npc.sethpmenu(1);
    npc.clear_force_char_nearfade();
    npc.setmaphighmodeldepth(-1);
    npc.setmapmodelstatus(1);
    npc.setstatuserrordispdenystatus(0);
    npc.settrapshowstatus(1);
    npc.stdmotionplay_2c2(0x01000000, 20);
end

-- When the talk closes: turn back the way he was facing.
local function talkTerm()
    npc.setaturnlookatlockstatus(1);
    npc.aturn_261(npc.getdestrotangzx_227(0));
end

local function myMod()
    npc.add {
        id = "npckit_0002",
        map = 290,                   -- Rabanastre, Muthru Bazaar
        name = "NPCKit 0002",

        -- Places him the way vanilla NPCs start: model, idle motion, collision, weight, position.
        init = function()
            npc.setautorelax(1);
            npc.usecharhit(0);
            npc.bindp2_d4(0x006E0019, 4, 3);  -- a Seeq
            npc.stdmotionread(16);
            npc.stdmotionreadsync();
            npc.stdmotionplay_2c2(0x01000000, 0);  -- his idle
            npc.setoverheadicontype(0);
            npc.usemapid(1);
            npc.usecharhit(1);
            npc.setweight(-1);
            npc.set_ignore_hitgroup(1);
            npc.motionloop(1);
            npc.setpos2(29.36, -9.0, 68.65);  -- in the bazaar
            npc.dir(1.676);
            npc.fetchambient();
            npc.bonecalcforce(-1);
            npc.clearhidecomplete();
            npc.show();
            npc.showshadow();
        end,

        -- Repeats while the map runs. He just waits; it must give a frame back.
        main = function()
            npc.wait(90);
        end,

        -- The talk: open, say one line, close.
        talk = function()
            talkOpen();
            npc.lua(function(handle)
                if not dialog.amese.open{
                    speaker = "NPCKit 0002",
                    body = line,
                    queue = true,
                    onClose = function() handle.finish() end,
                    onError = function() handle.finish() end,
                } then
                    handle.finish()
                end
            end);
            talkClose();
        end,

        talkterm = talkTerm,
    }
end

event.registerEventAsync("onInitDone", myMod)
```

***

### What each part does

| part                                | what it does                                                                                                       |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
| `id`, `map`, `name`                 | who he is, the map he's on, and the name shown over him when you can talk to him                                   |
| `init`                              | runs once when the map loads: model, motion, position                                                              |
| `main`                              | his routine, repeated while the map runs. Here he only waits                                                       |
| `talk`                              | what happens when you press the talk button next to him                                                            |
| `talkterm`                          | what happens when the talk ends                                                                                    |
| `talkOpen`, `talkClose`, `talkTerm` | what every vanilla talk does around its window: the talking pose, the mouth and the nods, then everything put back |
| `myMod`                             | declares him on `onInitDone`, when every script has started and NPC Kit is ready                                   |

The dialog window is the Lua Loader's `dialog.amese`, from its dialog capability ([Lua Loader documentation](https://gitlab.com/ff12-module-loader/modules/ff12-lua-loader-docs)).

{% hint style="warning" %}
**Every way out of the dialog calls `handle.finish()`**, `onError` and a refused `open` included. The talk waits at `npc.lua` until it does, so a missing `finish` leaves the player stuck. See [Lua During the Game](https://fehdead.gitbook.io/npc-kit/api/lua-during-the-game.md).
{% endhint %}

***

### Make it yours

* **Another model**: change `0x006E0019` to a key from the [Model Reference](https://fehdead.gitbook.io/ffxii-modding-guide/modding/resources/model-reference).
* **Another place**: change `map` and the `setpos2` point. [NPC Kit Editor](https://fehdead.gitbook.io/npc-kit/editor.md) shows you where an NPC stands while you move it.
* **More lines, choices, items**: open more `dialog.*` windows from `npc.lua`, and use the calls in [References](https://fehdead.gitbook.io/npc-kit/references.md).
