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 turn = {}
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
local trade =
{ --id, amount
['player_item'] = {1212, 1},
['npc_item'] = {1515, 1},
}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local pid = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, 'trade') or msgcontains(msg, 'offer') then
selfSay('Do you want to trade your '.. getItemNameById(trade['player_item'][1]) ..' for my '..getItemNameById(trade['npc_item'][1])..'?', cid)
turn[pid] = 'trade'
elseif (turn[pid] == 'trade') and msgcontains(msg, 'yes') then
if not doPlayerRemoveItem(cid, trade['player_item'][1], trade['player_item'][2]) then
turn[pid] = nil
return selfSay('But you don\'t have the item...', cid)
end
doPlayerAddItem(cid, trade['npc_item'][1], trade['npc_item'][2])
turn[pid] = nil
return selfSay('Thanks!', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())