> 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/examples/two-npcs-in-a-scene.md).

# Two NPCs in a Scene

**Talk to NPCKit 0006 and it plays a short scene with NPCKit 0007: a fade, fixed camera shots on whoever speaks, each with its own body language, and the camera given back at the end.**

This example takes place on map id 290, Rabanastre / Muthru Bazaar.

Download: [two-npcs-in-a-scene.lua](https://github.com/FelipeJulio/NPC-Kit/tree/main/examples/two-npcs-in-a-scene.lua)

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

local news = [[
Did you hear? There's a new face in the bazaar,
some traveler who showed up just this morning.
]]

local doubt = [[
Another one? This city never sleeps, I swear.
Every single day the gates bring someone new.
]]

local hello = [[
Go on and say hello. He doesn't bite, you know.
He might even have some fresh news from the road.
]]

local idle, talking, question, reproach, joy = 0x01000000, 0x01000002, 0x01000016, 0x01000012, 0x01000010

local function placeNpc(model, x, y, z, heading)
    npc.setautorelax(1);
    npc.usecharhit(0);
    npc.bindp2_d4(model, 4, 3);
    npc.stdmotionread(16);
    npc.stdmotionreadsync();
    npc.stdmotionplay_2c2(idle, 0);
    npc.setoverheadicontype(0);
    npc.usemapid(1);
    npc.usecharhit(1);
    npc.setweight(-1);
    npc.set_ignore_hitgroup(1);
    npc.motionloop(1);
    npc.setpos2(x, y, z);
    npc.dir(heading);
    npc.fetchambient();
    npc.bonecalcforce(-1);
    npc.clearhidecomplete();
    npc.show();
    npc.showshadow();
end

local function talkOpen()
    npc.sethpmenu(0);
    npc.ucoff();
    npc.settrapshowstatus(0);
    npc.setaturnlookatlockstatus(0);
    npc.raturna(-1);
    npc.turnsync();
    npc.stdmotionplay_2c2(talking, 20);
    npc.setkutipakustatus(1);
    npc.setunazukistatus(1);
end

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(idle, 20);
end

local function talkTerm()
    npc.setaturnlookatlockstatus(1);
    npc.aturn_261(npc.getdestrotangzx_227(0));
end

local function speaking(actor, on)
    actor.setkutipakustatus(on);
    actor.setunazukistatus(on);
    actor.setkubifuristatus(on);
end

local function speak(speaker, listener, motion, shot)
    speaking(listener, 0);
    listener.stdmotionplay_2c2(idle, 20);
    speaking(speaker, 1);
    speaker.stdmotionplay_2c2(motion, 20);
    npc.camerastart_7e(0, shot);
end

local lines = {
    { "NPCKit 0006", news, "asks" },
    { "NPCKit 0007", doubt, "frowns" },
    { "NPCKit 0006", hello, "smiles" }
}

local function play(handle, index)
    local line = lines[index]
    if not line then
        handle.run("close", function() handle.finish() end)
        return
    end
    handle.run(line[3], function()
        if not dialog.amese.open {
                speaker = line[1],
                body = line[2],
                queue = true,
                onClose = function() play(handle, index + 1) end,
                onError = function() handle.finish() end
            } then
            handle.finish()
        end
    end)
end

local function myMod()
    npc.add {
        id = "npckit_0007",
        map = 290,
        name = "NPCKit 0007",

        init = function()
            placeNpc(0x006E0012, 37.7, -9.0, 62.5, 1.5708);
        end,

        main = function()
            npc.wait(60);
        end
    }

    npc.add {
        id = "npckit_0006",
        map = 290,
        name = "NPCKit 0006",
        cameras = {
            ["npckit_0006"] = { eye = { 38.000, -7.500, 63.000 }, target = { 39.000, -7.570, 62.650 }, fov = 33.0 },
            ["npckit_0007"] = { eye = { 39.400, -7.500, 63.000 }, target = { 37.500, -7.570, 62.560 }, fov = 33.0 }
        },

        init = function()
            placeNpc(0x006E0013, 39.5, -9.0, 62.5, -1.5708);
        end,

        main = function()
            npc.wait(60);
        end,

        open = function()
            npc.fadeout(15);
            npc.fadesync();
            npc.hideparty();
            npc.lookatoff();
            npc.dir(-1.5708);
            npc.camerastart_7e(0, npc.camera("npckit_0006"));
            npc.wait(3);
            npc.fadein(15);
            npc.fadesync();
        end,

        asks = function()
            speak(npc, npc.on("npckit_0007"), question, npc.camera("npckit_0006"));
        end,

        frowns = function()
            speak(npc.on("npckit_0007"), npc, reproach, npc.camera("npckit_0007"));
        end,

        smiles = function()
            speak(npc, npc.on("npckit_0007"), joy, npc.camera("npckit_0006"));
        end,

        close = function()
            local other = npc.on("npckit_0007")
            npc.fadeout(15);
            npc.fadesync();
            speaking(npc, 0);
            speaking(other, 0);
            other.stdmotionplay_2c2(idle, 0);
            npc.showparty();
            npc.cameraclear();
            npc.wait(1);
            npc.fadein(15);
            npc.fadesync();
        end,

        talk = function()
            talkOpen();
            npc.lua(function(handle)
                handle.run("open", function() play(handle, 1) end)
            end);
            talkClose();
        end,

        talkterm = talkTerm
    }
end

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

`cameras` holds the two fixed shots, each an eye, a target and a field of view, named by the id of the NPC it frames (see [Custom Camera](https://fehdead.gitbook.io/npc-kit/api/custom-camera.md)); `npc.camera("npckit_0006")` is that shot as `camerastart_7e` takes it. `open` fades out, hides the party, stops the NPC looking at the player and turns it to its partner. Each line runs an actor function (`asks`, `frowns`, `smiles`) that switches who speaks, with `npc.on` for the other NPC, plays a talking motion (`0x01000016` a question, `0x01000012` reproach, `0x01000010` joy, as vanilla talks use them) and cuts to the speaker's shot. `close` fades out, puts the party and the camera back and fades in.
