Ir para conteúdo

Featured Replies

  • Respostas 12
  • Visualizações 522
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • Aqui está:     Npc.lua local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) local talkState = {} f

  • Opa, desculpa, burrice minha.   Agora ambos estão configuráveis: local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(n

Postado
  • Solução
  Em 13/11/2015 em 14:53, Gabrielk disse:

  local itemsp = {2666, 2671, 2681, 2695, 2667, 2676, 2675} -- os 7 items que precisam.

esse daqui que eu queria... por favor

 

Opa, desculpa, burrice minha.

 

Agora ambos estão configuráveis:

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 itemsp = {	
						[1] = {2666, 2}, 
						[2] = {2671, 2}, 
						[3] = {2681, 2}, 
						[4] = {2695, 2}, 
						[5] = {2667, 2}, 
						[6] = {2676, 2}, 
						[7] = {2675, 2},
	} -- os 7 items que precisam.
    
    
    s = ""
    for k, v in pairs(itemsp) do 
        s = s.."{"..v[2].." ".. getItemNameById(v[1]) .."}".. (#itemsp ~= k and ", " or "")
        
    end
    
    function pegaritems()
        for k, v in pairs(itemsp) do
            doPlayerRemoveItem(cid, v[1], v[2])
        end
    end
    
    function temitem()
        for k, v in pairs(itemsp) do 
            if not (getPlayerItemCount(cid, v[1]) >= v[2]) then
                return false
            end
        end
        return true
    end
    
    local tab = {	
		[2] = {7454, 1}, -- axe
        [3] = {2376, 1}, -- sword
        [4] = {2389, 1}, -- spear
    }
    	
    if (msgcontains(msg, "troca") or msgcontains(msg, "trocar") or msgcontains(msg, "yes")) and talkState[talkUser] == nil then
        npcHandler:say("Ok, preciso de {7 items} em troca de: ("..getItemArticleById(tab[2][1]).." {"..getItemNameById(tab[2][1]).."} - ID: "..tab[2][1].."), ("..getItemArticleById(tab[3][1]).." {"..getItemNameById(tab[3][1]).."} - ID: "..tab[3][1]..") ou ("..getItemArticleById(tab[4][1]).." {"..getItemNameById(tab[4][1]).."} - ID: "..tab[4][1]..")", cid)
        talkState[talkUser] = 1
    elseif (msgcontains(msg, tostring(getItemNameById(tab[2][1])))) and talkState[talkUser] == 1 then
        npcHandler:say("Voce quer trocar: ".. s .." por um {"..getItemNameById(tab[2][1]).."}?", cid)
        talkState[talkUser] = 2
    elseif (msgcontains(msg, tostring(getItemNameById(tab[3][1])))) and talkState[talkUser] == 1 then
        npcHandler:say("Voce quer trocar: ".. s .." por uma {"..getItemNameById(tab[3][1]).."}?", cid)
        talkState[talkUser] = 3
    elseif (msgcontains(msg, tostring(getItemNameById(tab[4][1])))) and talkState[talkUser] == 1 then
        npcHandler:say("Voce quer trocar: ".. s .." por uma {"..getItemNameById(tab[4][1]).."}?", cid)
        talkState[talkUser] = 4
    elseif (msgcontains(msg, "yes")) and tab[talkState[talkUser]]  then 
        for k, v in pairs(itemsp) do 
            if not temitem() then
                doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
                npcHandler:say("Voce nao tem todos os items, desculpe, nada feito.", cid)
                npcHandler:onCreatureDisappear(cid)
                talkState[talkUser] = nil
                return true
            elseif temitem() then 
                pegaritems()
				for i = 1, tab[talkState[talkUser]][2] do 
					doPlayerAddItem(cid, tab[talkState[talkUser]][1])
				end
                npcHandler:say("Uhuul, troca feita, obrigado.", cid)
                npcHandler:onCreatureDisappear(cid)
                talkState[talkUser] = nil
                return true
            end
        end
    end
end 

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

Se quiser sua dúvida tirada, mande PM com os links, e não com a dúvida (outros podem ter a mesma dúvida, e o fórum serve para ser usado).

 

Tópicos:


Mostrar conteúdo oculto

 

yNlhRVC.png

 

55px-Judo_yellow_belt.svg.png

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.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo