local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local t = {}
local c = {
amount = 100, -- Cap to add.
price = 10000, -- Price of it in gp.
storage = 100001,
amount2 = 200, -- Cap to add.
price2 = 20000,
}
function creatureSayCallback(cid, type, msg)
local str = math.max(0, getCreatureStorage(cid, c.storage))
if not npcHandler:isFocused(cid) then
return false
elseif msgcontains(msg, 'cap') then
selfSay("For ".. (str == 0 and c.price or c.price2) .." gold I will add ".. (str == 0 and c.amount or c.amount2) .." capacity, would you like that?", cid)
t[cid] = 1
elseif t[cid] == 1 and msgcontains(msg, 'yes') then
if str ~= 2 then
if getPlayerMoney(cid) >= (str == 0 and c.amount or c.amount2) then
doPlayerSave(cid)
local q = db.getResult("SELECT `cap` FROM `players` WHERE `id` = ".. getPlayerGUID(cid) .." LIMIT 1;"):getDataInt("cap")
doPlayerRemoveMoney(cid, (str == 0 and c.amount or c.amount2))
doPlayerSetMaxCapacity(cid, q+(str == 0 and c.amount or c.amount2))
doCreatureSetStorage(cid, c.storage, math.max(0, getCreatureStorage(cid, c.storage)) + 1)
selfSay("Pleasant doing business with you!", cid)
t[cid] = nil
else
selfSay("Sorry, you don't have enough money!", cid)
t[cid] = nil
end
else
selfSay('Sorry, you can\'t buy more cap', cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())