local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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 c = {
["crude umbral blade"] = {
id = 22398,
items = {
{id = 22397, count = 1},
{id = 22396, count = 20}
}
},
["something else"] = {
id = 2112,
items = {
{id = 2674, count = 1},
{id = 2675, count = 10}
}
}
}
local function getItemsFromTable(itemtable)
local text = ""
for v = 1, #itemtable do
count, info = itemtable[v].count, getItemDescriptions(itemtable[v].id)
local ret = ", "
if v == 1 then
ret = ""
elseif v == #itemtable then
ret = " and "
end
text = text .. ret
text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
end
return text
end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local player = Player(cid)
local x = c[msg:lower()]
if x then
selfSay("It will cost you "..getItemsFromTable(x.items).."...", cid)
talkState[talkUser] = 1
xmsg = msg
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
x = c[xmsg:lower()]
local n = 0
for z = 1, #x.items do
if player:getItemCount(x.items[z].id) >= x.items[z].count then
n = n + 1
end
end
if n == #x.items then
for r = 1, #x.items do
player:removeItem(x.items[r].id, x.items[r].count)
end
selfSay("There you go.", cid)
player:addItem(x.id, 1)
else
selfSay("You don't have the items.", cid)
end
talkState[talkUser] = 0
elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
selfSay("Ok then.", cid)
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())