local STORAGE = 5021 -- Storage necessária
local ITEM = 0000 -- ID Do Item
local REWARD = 0000 -- ID Do Item que irá ganhar
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:lower()) end
function onThink() npcHandler:onThink() end
local talkState = {}
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if msgcontains(msg, "Trocar") then
selfSay("Você deseja trocar o Item X por outro item comigo?", cid)
talkState[talkUser] = 1
elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
if getPlayerStorageValue(cid, STORAGE) > 0 then
if getPlayerItemCount(cid, ITEM) > 0 then
selfSay("Aí está!", cid)
doPlayerRemoveItem(cid, ITEM, 1) -- Remove Item
doPlayerAddItem(cid,REWARD, 1) -- Adiciona Item
doSendMagicEffect(getThingPos(cid), 10)
npcHandler:releaseFocus(cid)
else
selfSay("Desculpe, mas você não tem o Item que eu quero.", cid)
talkState[talkUser] = 0
end
else
selfSay("Desculpe, mas você não é digno de realizar trocas comigo.", cid)
talkState[talkUser] = 0
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())