Postado Julho 28, 2015 9 anos Estou tentando montar esse NPC em que quando o player aceite ajudar, ele diga "Obrigada, você estará fazendo um grande favor.", depois que o player voltar e disser 'help' de novo, ela verificara se o player está com o item, e dará o novo item para o player e uma storage para ele não fazer a quest de novo. Só que não estou conseguindo fazer desta forma, quando o player diz que aceita ajudar, ela já faz a checagem dos itens. Segue o script: 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 FUNCAO_NOME(cid, message, keywords, parameters, node) if(not npcHandler:isFocused(cid)) then return false end local storage = 60080 if getPlayerStorageValue(cid, storage) ~= 1 then npcHandler:say('Obrigada, você estará fazendo um grande favor.', cid) -- MENSAGEM AO REMOVER O ITEM setPlayerStorageValue(cid, storage, 1) end if getPlayerStorageValue(cid, storage) ~= 2 then if getPlayerItemCount(cid,5944) >= 2 then -- SE TIVER 1 OU MAIS ITEM COM ID 2516 if doPlayerRemoveItem(cid,5944,2) then -- remove 1 ITEM DO ITEM COM ID 2516 npcHandler:say('Obrigao, ja fazia ideia de que isso iria acontecer. Pegue isso em forma de gratidao!', cid) -- MENSAGEM AO REMOVER O ITEM doPlayerAddItem(cid,5908,2) -- ADD 1 ITEM COM ID 5908 setPlayerStorageValue(cid, storage, 2) end else npcHandler:say('Isso nao eh do meu irmao, nao brinque comigo!', cid) end else npcHandler:say('Você ja me ajudou!', cid) end end local node2 = keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Meu irmao que se perdeu, pode encontra-lo e trazer alguma informaçao para mim?.'}) node2:addChildKeyword({'yes'}, FUNCAO_NOME, {npcHandler = npcHandler, onlyFocus = true, reset = true}) node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Até mais.', reset = true}) local node3 = keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Voce trouxe alguma informaçao dele?.'}) node3:addChildKeyword({'yes'}, FUNCAO_NOME, {npcHandler = npcHandler, onlyFocus = true, reset = true}) node3:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Até mais.', reset = true}) npcHandler:addModule(FocusModule:new())
Postado Julho 28, 2015 9 anos Solução Fiz um aqui pra você, veja se lhe serve: local t = { storage = 60080, -- Storage. reward = {5908, 1}, -- Reward e quantia. (Só funciona com agrupavel!) ineed = {5944, 2} -- Item necessário e quantia. } 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 msg = msg:lower(); local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'help') then if getPlayerStorageValue(cid, t.storage) <= 0 then selfSay('Meu irmao que se perdeu, pode encontra-lo e trazer alguma informaçao para mim?', cid) talkState[talkUser] = 1 elseif getPlayerStorageValue(cid, t.storage) == 2 then selfSay('Obrigado, mas você já me ajudou.', cid) elseif getPlayerStorageValue(cid, t.storage) == 1 then selfSay('Voce trouxe alguma informaçao dele?', cid) talkState[talkUser] = 2 end elseif msgcontains(msg, 'yes') then if talkState[talkUser] == 1 then selfSay('Obrigada, você estará fazendo um grande favor.', cid) setPlayerStorageValue(cid, t.storage, 1) talkState[talkUser] = 0 elseif talkState[talkUser] == 2 then if getPlayerStorageValue(cid, t.storage) == 1 then if doPlayerRemoveItem(cid, t.ineed[1], t.ineed[2]) then selfSay('Obrigado, ja fazia ideia de que isso iria acontecer. Pegue isso em forma de gratidao!', cid) doPlayerAddItem(cid, t.reward[1], t.reward[2]) setPlayerStorageValue(cid, t.storage, 2) talkState[talkUser] = 0 else selfSay('Você não tem nada sobre meu irmão, não brinque comigo!', cid) talkState[talkUser] = 0 end else selfSay('Obrigado, mas você já me ajudou.', cid) talkState[talkUser] = 0 end end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) ➥ Regras | Seções OTServ | Seções BOT
Postado Julho 28, 2015 9 anos Fiz um aqui pra você, veja se lhe serve: local t = { storage = 60080, -- Storage. reward = {5908, 1}, -- Reward e quantia. (Só funciona com agrupavel!) ineed = {5944, 2} -- Item necessário e quantia. } 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 msg = msg:lower(); local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid if msgcontains(msg, 'help') then if getPlayerStorageValue(cid, t.storage) <= 0 then selfSay('Meu irmao que se perdeu, pode encontra-lo e trazer alguma informaçao para mim?', cid) talkState[talkUser] = 1 elseif getPlayerStorageValue(cid, t.storage) == 2 then selfSay('Obrigado, mas você já me ajudou.', cid) talkState[talkUser] = 0 elseif getPlayerStorageValue(cid, t.storage) == 1 then selfSay('Voce trouxe alguma informaçao dele?', cid) talkState[talkUser] = 2 end elseif msgcontains(msg, 'yes') then if talkState[talkUser] == 1 then selfSay('Obrigada, você estará fazendo um grande favor.', cid) setPlayerStorageValue(cid, t.storage, 1) talkState[talkUser] = 0 elseif talkState[talkUser] == 2 then if getPlayerStorageValue(cid, t.storage) == 1 then if doPlayerRemoveItem(cid, t.ineed[1], t.ineed[2]) then selfSay('Obrigado, ja fazia ideia de que isso iria acontecer. Pegue isso em forma de gratidao!', cid) doPlayerAddItem(cid, t.reward[1], t.reward[2]) setPlayerStorageValue(cid, t.storage, 2) talkState[talkUser] = 0 else selfSay('Você não tem nada sobre meu irmão, não brinque comigo!', cid) talkState[talkUser] = 0 end else selfSay('Obrigado, mas você já me ajudou.', cid) talkState[talkUser] = 0 end end end end npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) npcHandler:addModule(FocusModule:new()) me impressiono com a quantidade de fera em lua aqui, mds ;x
Postado Julho 28, 2015 9 anos Autor Obrigado cara. Passei o dia todo quebrando a cabeça pra fazer isso, ser autodidata é bom, mas as vezes temos que buscar aprender com gente mais experiente.
Postado Julho 28, 2015 9 anos Obrigado cara. Passei o dia todo quebrando a cabeça pra fazer isso, ser autodidata é bom, mas as vezes temos que buscar aprender com gente mais experiente. É assim mesmo, antes eu também passava o dia inteiro tentando e não saia nada kk. ➥ Regras | Seções OTServ | Seções BOT
Participe da conversa
Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.