local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local Topic = {}
local items = {
[{2670,10}] = 10000
}
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
function creatureSayCallback(cid, type, msg)
for v, x in ipairs(items) do
if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
if getPlayerItemCount(cid, v[1]) >= v[2] then
npcHandler:say("Hello " .. getCreatureName(cid) .. ". Would you like to {exchange} 10 shrimp for some experience?", cid)
Topic[cid] = 1
else
npcHandler:say("Hmm...don't think I can help you.", cid)
Topic[cid] = 0
end
npcHandler:addFocus(cid)
elseif(not npcHandler:isFocused(cid)) then
return false
elseif Topic[cid] == 1 then
if msgcontains(msg, "exchange") then
npcHandler:say("Are you sure you want to exchange " .. v[2] .. "x " .. getItemInfo(v[1]).name .. " for " .. x .. " experience points?", cid)
Topic[cid] = 2
else
npcHandler:say("What was that? I don't understand you.", cid)
Topic[cid] = 1
end
elseif Topic[cid] == 2 then
if msgcontains(msg, "yes") then
if doPlayerRemoveItem(cid, v[1], v[2] or 1) then
npcHandler:say("Great! Here you are.", cid)
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
doPlayerAddExperience(cid, x)
Topic[cid] = 0
else
npcHandler:say("You do not have the item with you.", cid)
Topic[cid] = 0
end
elseif msgcontains(msg, "no") then
npcHandler:say("Well, then leave.", cid)
Topic[cid] = 0
end
elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
npcHandler:say("Good bye.", cid, TRUE)
Topic[cid] = nil
npcHandler:releaseFocus(cid)
end
return true
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a good day!")