npc:
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
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 santana_doll = 3434 -- id do item que será removido
local surprise_box = 5878 -- id da surprise box
if(msgcontains(msg, 'natal') or msgcontains(msg, 'NATAL')) then
selfSay('Ho,ho,ho. Quer trocar um Santana Doll por um Surprise Box? {yes}', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerItemCount(cid,santana_doll) >= 1 then
doPlayerRemoveItem(cid,santana_doll,1)
doPlayerAddItem(cid, surprise_box, 1)
selfSay('Aqui está seu presente,Feliz Natal!', cid)
doSendMagicEffect(getPlayerPosition(cid), 2)
else
selfSay('Você não possui nenhum santana doll!.', cid)
talkState[talkUser] = 0
end
elseif msg == "no" and talkState[talkUser] >= 1 then
selfSay("Volte no próximo natal então!", cid)
talkState[talkUser] = 0
npcHandler:releaseFocus(cid)
end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())