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
function creatureSayCallback(cid, type, msg)
if(npcHandler.focus ~= cid) then
return false
end
playertokens = getPlayerItemCount(cid,9020)
---- example of keyword->respond
if msgcontains(msg, 'offer') then
selfSay('I can offer you a plate armor and plate legs for vampire lord tokens.')
elseif msgcontains(msg, 'tokens') then
selfSay('Vampire lord tokens are very valuable. Many treasure hunters looks for them.')
---- first item in offer
elseif msgcontains(msg, 'plate armor') then
if getPlayerItemCount(cid,9020) >= 5 then
npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate armor?', cid)
talk_state = 1
else
npcHandler:say('I need 5 vampire lord tokens to exchange them to plate armor.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 1 then
talk_state = 0
if getPlayerItemCount(cid,9020) >= 5 then
if doPlayerTakeItem(cid,9020,5) == 0 then
selfSay('Here you are.')
doPlayerAddItem(cid,2463,1)
end
else
npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
end
---- /first item in offer
---- second item in offer
elseif msgcontains(msg, 'plate legs') then
if getPlayerItemCount(cid,9020) >= 5 then
npcHandler:say('Did you bring me 5 vampire lord tokens to exchange for plate legs?', cid)
talk_state = 2
else
npcHandler:say('I need 5 vampire lord tokens to exchange them to plate legs.', cid)
talk_state = 0
end
elseif msgcontains(msg, 'yes') and talk_state == 2 then
talk_state = 0
if getPlayerItemCount(cid,9020) >= 5 then
if doPlayerTakeItem(cid,9020,5) == 0 then
selfSay('Here you are.')
doPlayerAddItem(cid,2647,1)
end
else
npcHandler:say('You haven\'t enough vampire lord tokens!', cid)
end
---- /second item in offer
---- what happens if player say "no", if you are going to add more items, remember to change "talk_state <= 2"
elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 2) then
selfSay('Then not.')
talk_state = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())