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

# Recruiting Guests

**Larsa, Vossler and Reddas stand in Balfonheim, each one offering to join as a guest. Only one guest fits at a time: talking to another asks whether to dismiss the one you have.**

This example takes place on map id 823, Balfonheim / Sea Breeze Lane.

Download: [recruiting-guests.lua](https://github.com/FelipeJulio/NPC-Kit/tree/main/examples/recruiting-guests.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 joinChoices = { "Yes, join the party", "No" }
local leaveChoices = { "Yes, leave the party", "No, stay" }

local larsaJoin = [[
I have not yet the honor of your company.
Would you have me join you as a guest?
]]
local larsaNotJoined = [[
As you wish. I shall await another occasion.
]]
local larsaLeave = [[
I travel with you as a guest. Would you
have me take my leave of your company?
]]
local larsaStayed = [[
Then I remain, gladly, at your service.
]]
local larsaSwap = [[
%s already graces your party as a guest.
Should they part, may I take their place?
]]

local vosslerJoin = [[
I'm not in your ranks yet. Want me along
as a guest? Say the word.
]]
local vosslerNotJoined = [[
Understood. I stay put.
]]
local vosslerLeave = [[
I'm marching with you as a guest.
Want me to fall out?
]]
local vosslerLeft = [[
Done. I've fallen out of your ranks.
]]
local vosslerStayed = [[
Understood. I hold my place in the line.
]]
local vosslerSwap = [[
%s already holds the guest post.
Dismiss them, and I take it?
]]

local reddasJoin = [[
I do not stand among your party. Do you
require me as a guest?
]]
local reddasNotJoined = [[
Very well. Your decision stands.
]]
local reddasLeave = [[
I serve in your party as a guest. Do you
relieve me of that duty?
]]
local reddasLeft = [[
So be it. I am relieved of my post.
]]
local reddasStayed = [[
Very well. I remain at your side.
]]
local reddasSwap = [[
%s already serves as your guest.
Relieve them, and I shall take their place?
]]
local swapChoices = { "Yes, dismiss and join", "No" }

local guests = {
    {
        id = "npckit_0063",
        name = "Larsa",
        join = larsaJoin,
        notJoined = larsaNotJoined,
        leave = larsaLeave,
        stayed = larsaStayed,
        swap = larsaSwap,
        row = 13,
        model = 0x00630010,
        pos = { 317.411, 2.022, 43.367 },
        dir = 0.007,
        joinMes = 75,
        leaveMes = 76,
    },
    {
        id = "npckit_0064",
        name = "Vossler",
        join = vosslerJoin,
        notJoined = vosslerNotJoined,
        leave = vosslerLeave,
        left = vosslerLeft,
        stayed = vosslerStayed,
        swap = vosslerSwap,
        row = 12,
        model = 0x0063000E,
        pos = { 320.256, 2.022, 44.352 },
        dir = -0.774,
        joinMes = 73,
    },
    {
        id = "npckit_0065",
        name = "Reddas",
        join = reddasJoin,
        notJoined = reddasNotJoined,
        leave = reddasLeave,
        left = reddasLeft,
        stayed = reddasStayed,
        swap = reddasSwap,
        row = 14,
        model = 0x00630001,
        pos = { 321.036, 2.022, 47.127 },
        dir = -1.558,
        joinMes = 77,
    },
}

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

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

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

local function place(modelKey, pos, dir)
    npc.setautorelax(1);
    npc.usecharhit(0);
    npc.bindp2_d4(modelKey, 4, 3);
    npc.stdmotionread(0);
    npc.stdmotionreadsync();
    npc.stdmotionplay_2c2(0x01000000, 0);
    npc.setoverheadicontype(0);
    npc.usemapid(1);
    npc.usecharhit(1);
    npc.setweight(-1);
    npc.set_ignore_hitgroup(1);
    npc.motionloop(1);
    npc.setpos2(pos[1], pos[2], pos[3]);
    npc.dir(dir);
    npc.fetchambient();
    npc.bonecalcforce(-1);
    npc.clearhidecomplete();
    npc.show();
    npc.showshadow();
end

local function banner(mesId)
    npc.musictrans(-1, 30, 32);
    npc.setstatuserrorctrldenystatus_by_menu(1);
    npc.seteventtimestop(1);
    npc.moveblurcaptureonce();
    npc.movebluraplpha(1);
    npc.moveblurfade(15);
    npc.moveblurfadesync();
    npc.setmeswinmesid(0, mesId);
    npc.ames_1fe(0, 0x01000000, 0x03c0, 0x021c, 4, 0);
    npc.messync(0, 1);
    npc.musictrans(-1, 30, 127);
    npc.moveblurclearfade(15);
    npc.moveblurfadesync();
    npc.seteventtimestop(0);
    npc.setstatuserrorctrldenystatus_by_menu(0);
end

local function say(handle, speaker, body)
    if not dialog.amese.open {
        speaker = speaker,
        body = body,
        queue = true,
        onClose = function() handle.finish() end,
        onError = function() handle.finish() end,
    } then
        handle.finish()
    end
end

local function offer(handle, speaker, body, choices, run, reply, noReply)
    if not dialog.aaske.open {
        speaker = speaker,
        body = body,
        choice = choices,
        cancel = 1,
        queue = true,
        onClose = function(index, reason)
            if reason == "dismissed" and index == 0 then
                handle.run(run, function()
                    if reply then
                        say(handle, speaker, reply)
                    else
                        handle.finish()
                    end
                end)
            elseif reason == "dismissed" then
                say(handle, speaker, noReply)
            else
                handle.finish()
            end
        end,
        onError = function() handle.finish() end,
    } then
        handle.finish()
    end
end

local function myMod()
    local hired = {}
    for _, guest in ipairs(guests) do
        local def = {
            id = guest.id,
            map = 823,
            name = guest.name,

            init = function()
                place(guest.model, guest.pos, guest.dir);
            end,

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

            talk = function()
                talkOpen();
                for _, other in ipairs(guests) do
                    if other ~= guest then
                        npc.lua(npc.ispartymember(other.row), function(handle, inParty)
                            hired[other.row] = inParty == 1
                            handle.finish()
                        end);
                    end
                end
                npc.lua(npc.ispartymember(guest.row), function(handle, inParty)
                    if inParty == 1 then
                        offer(handle, guest.name, guest.leave, leaveChoices, "leave", not guest.leaveMes and guest.left or nil, guest.stayed)
                        return
                    end
                    for _, other in ipairs(guests) do
                        if other ~= guest and hired[other.row] then
                            offer(handle, guest.name, guest.swap:format(other.name), swapChoices, "swap" .. other.row, nil, guest.notJoined)
                            return
                        end
                    end
                    offer(handle, guest.name, guest.join, joinChoices, "join", nil, guest.notJoined)
                end);
                talkClose();
            end,

            talkterm = talkTerm,

            join = function()
                npc.addguestbattlemember(guest.row);
                npc.showparty();
                banner(guest.joinMes);
            end,

            leave = function()
                npc.removeguestbattlemember(guest.row);
                npc.showparty();
                if guest.leaveMes then
                    banner(guest.leaveMes);
                end
            end,
        }
        for _, other in ipairs(guests) do
            if other ~= guest then
                def["swap" .. other.row] = function()
                    npc.removeguestbattlemember(other.row);
                    npc.addguestbattlemember(guest.row);
                    npc.showparty();
                    banner(guest.joinMes);
                end
            end
        end
        npc.add(def)
    end
end

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

Who is in the party is read from the game at every talk, with `npc.ispartymember`, one `npc.lua` per guest: nothing is kept in Lua, so it still holds after the game restarts. `join`, `leave` and the `swap` functions are actor functions run with `handle.run`; each swap removes the current guest with `removeguestbattlemember` and adds the new one with `addguestbattlemember`. The three say the same things, each in their own voice.
