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

# A Magic Trick

**NPCKit 0005 offers a magic trick. Say yes and a wolf fades in in front of it, stays five seconds and fades out, and the NPC asks if it was cool.**

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

Download: [magic-trick.lua](https://github.com/FelipeJulio/NPC-Kit/tree/main/examples/magic-trick.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 offer = [[
Hey, you there! Want to see a funny magic trick?
It's a good one, I promise you won't regret it.
]]

local offerChoices = { "Yes haha, show me!", "Not now, thanks." }

local watch = [[
Watch closely now, don't blink or you'll miss it.
I'll pull a whole wolf right out of thin air!
]]

local tada = [[
Ta-da! A wolf, just like I promised you, see?
Pretty cool, right? Go and tell all your friends.
]]

local refused = [[
Your loss! It was my very best trick, you know.
Come back here if you ever change your mind, okay?
]]

local idle, talking = 0x01000000, 0x01000002

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 say(handle, body, onDone)
    if not dialog.amese.open {
            speaker = "NPCKit 0005",
            body = body,
            queue = true,
            onClose = onDone or function() handle.finish() end,
            onError = function() handle.finish() end
        } then
        handle.finish()
    end
end

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

        init = function()
            npc.setautorelax(1);
            npc.hidecomplete();
            npc.usecharhit(0);
            npc.bindp2_d4(0x006D0001, 4, 3);
            npc.stdmotionread(1);
            npc.stdmotionreadsync();
            npc.stdmotionplay_2c2(idle, 0);
            npc.usemapid(1);
            npc.motionloop(1);
            npc.setpos2(34.9, -9.0, 63.0);
            npc.dir(0.0);
            npc.fetchambient();
            npc.rgbatrans(1, 1, 1, 0, 0);
        end,

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

    npc.add {
        id = "npckit_0005",
        map = 290,
        name = "NPCKit 0005",

        init = function()
            placeNpc(0x006E0012, 34.9, -9.0, 65.0, 3.1416);
        end,

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

        summon = function()
            local wolf = npc.on("npckit_0010")
            npc.stdmotionplay_2c2(0x01000010, 20);
            wolf.clearhidecomplete();
            wolf.show();
            wolf.rgbatrans(1, 1, 1, 1, 10);
            npc.wait(10);
            npc.sebsoundplay(0, 46);
            npc.common2effectplay(npc.actor("npckit_0010"), 11);
            npc.wait(150);
            npc.sebsoundplay(0, 38);
            npc.common2effectplay(npc.actor("npckit_0010"), 4);
            npc.wait(30);
            wolf.rgbatrans(1, 1, 1, 0, 15);
            npc.wait(15);
            wolf.hidecomplete();
            npc.stdmotionplay_2c2(idle, 20);
        end,

        talk = function()
            talkOpen();
            npc.lua(function(handle)
                if not dialog.aaske.open {
                        speaker = "NPCKit 0005",
                        body = offer,
                        choice = offerChoices,
                        cancel = 1,
                        queue = true,
                        onClose = function(index, reason)
                            if reason == "dismissed" and index == 0 then
                                say(handle, watch, function()
                                    handle.run("summon", function()
                                        say(handle, tada)
                                    end)
                                end)
                            else
                                say(handle, refused)
                            end
                        end,
                        onError = function() handle.finish() end
                    } then
                    handle.finish()
                end
            end);
            talkClose();
        end,

        talkterm = talkTerm
    }
end

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

The wolf, NPCKit 0010, is declared in the same script and is on the map from the start: hidden with `hidecomplete` and fully transparent with `rgbatrans(1, 1, 1, 0, 0)`. `summon` reveals it the way vanilla fades an actor in, `clearhidecomplete` then `rgbatrans(1, 1, 1, 1, 10)`, and fades it out again with `rgbatrans(1, 1, 1, 0, 15)` before hiding it. While it summons, NPCKit 0005 plays its joyful motion (`0x01000010`). A sound (`sebsoundplay`) and a common effect mark each moment: `common2effectplay(actor, effect)` plays the effect on the actor it is given, here the wolf through `npc.actor`, as The Archadian Alchemist plays effects 11 and 4 on the party with sounds 46 and 38. `npc.on` reaches it because both NPCs are in one script. A monster model plays its motions from bank 1 (`stdmotionread(1)`), people from 16. `dialog.aaske` returns the picked index from 0, and `cancel = 1` makes Cancel pick the second answer.
