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

# Charging Gil

**NPCKit 0003 sells a tip for 100 gil. The gil window opens with your gil while it asks, and counts the payment down if you accept.**

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

Download: [charge-gil.lua](https://github.com/FelipeJulio/NPC-Kit/tree/main/examples/charge-gil.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 = [[
I know a secret about this bazaar, a good one.
Yours for %d gil, friend. Do we have a deal?
]]

local offerChoices = { "Deal", "No, thanks" }

local thanks = [[
Thank you! Listen: the merchant by the stairs
sells all his potions cheaper right before dusk.
]]

local refused = [[
Suit yourself. Secrets don't get any cheaper,
but they do have a way of going stale very fast.
]]

local tooPoor = [[
That's %d gil, and I don't give tips on credit.
Come back when your purse feels a bit heavier.
]]

local idle, talking = 0x01000000, 0x01000002

local price = 100

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 0003",
            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_0003",
        map = 290,
        name = "NPCKit 0003",

        init = function()
            placeNpc(0x006E0013, 30.9, -9.0, 66.0, 3.1416);
        end,

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

        openGil = function()
            npc.gillwinopen(npc.havegill());
        end,

        pay = function()
            npc.gillwinstart(-price);
            npc.gillwinsync();
            npc.subgill(price);
            npc.wait(20);
            npc.gillwinclose();
        end,

        closeGil = function()
            npc.gillwinclose();
        end,

        talk = function()
            talkOpen();
            npc.lua(npc.havegill(), function(handle, gil)
                if gil < price then
                    say(handle, tooPoor:format(price))
                    return
                end
                handle.run("openGil", function()
                    if not dialog.aaske.open {
                            speaker = "NPCKit 0003",
                            body = offer:format(price),
                            choice = offerChoices,
                            cancel = 1,
                            queue = true,
                            onClose = function(index, reason)
                                if reason == "dismissed" and index == 0 then
                                    handle.run("pay", function()
                                        say(handle, thanks)
                                    end)
                                else
                                    handle.run("closeGil", function()
                                        say(handle, refused)
                                    end)
                                end
                            end,
                            onError = function() handle.finish() end
                        } then
                        handle.finish()
                    end
                end)
            end);
            talkClose();
        end,

        talkterm = talkTerm
    }
end

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

`npc.havegill()` hands your gil to Lua, where the price is checked. The gil window is three actor functions run with `handle.run`, as vanilla does it: `openGil` shows your gil before the question, `pay` counts the price down and takes it, `closeGil` closes the window when you refuse.
