Ir para conteúdo

Featured Replies

Postado

Estou utilizando OTX - TFS 1.X

 

O motivo da criação deste tópico e, tenho um NPC que pede que você mate uma certa quantia de criaturas "configuráveis", então resolvi tentar colocar pra que nesse mesmo npc se tenha a opção de escolar mais de 1 criaturar, assim não preciso estar criando um NPC pra cada criatura. Então conseguir fazer que me desse a opção com mais criaturas.

 

O erro que estou tendo e que quando, pego uma das criaturar sem ser o RAT, ele me da a recompensa da anterior e a tarefa escolhida pra mim executar, e na hora de entregar a tarefa escolhida finalizada, ele me entrega a recompensa de todas as tarefas configuradas. irei postar aqui os dois códigos, o original e o que eu fiz as minhas alterações, kkkkk... 

 

 

Código original

Citar

 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

local storage = 19230

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, "mission") then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("I have a mission for you to kill 10 rats, do you accept?", cid)
             talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, storage) == 1 then
             selfSay("Did you kill 10 rats?", cid)
             talkState[talkUser] = 1
         else
             selfSay("You already did the mission.", cid)
         end
     elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
         if getPlayerStorageValue(cid, storage) == -1 then
             selfSay("Good, come back when you killed them.", cid)
             setPlayerStorageValue(cid, storage, 1)
         else
             if getPlayerStorageValue(cid, 19400) == 10 then
                 selfSay("Good job, here is your reward.", cid)
                 doPlayerAddItem(cid, 2152, 1)
                 doPlayerAddExp(cid, 200)
                 setPlayerStorageValue(cid, storage, 2)
             else
                 selfSay("You didn't kill them all.", cid)
             end
         end
         talkState[talkUser] = 0
     elseif msgcontains(msg, "no") and talkState[talkUser] == 1 then
         selfSay("Ok then.", cid)
         talkState[talkUser] = 0
     end
     return true
end

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

 

 

 

Código com minhas alterações.

Citar

 


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

local storage = {
rat = 19230,
rotworm = 19231,
orc = 19232,
}

local function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	end

	local player = Player(cid)
	 
	if msgcontains(msg, "hello") or msgcontains(msg, "oi") or msgcontains(msg, "ola") or msgcontains(msg, "hi") then
		npcHandler:say(getPlayerSex(cid) == 0 and "Olá meu amigo, tem algumas {criaturas} que eu gostaria que você me ajudace a mata-las, você sera recompensado." or "Olá minha amiga, me ajude a matar algumas {criaturas} que eu lhe recompensarei.", cid)
		npcHandler.topic[cid] = 0
	elseif msgcontains(msg, "criaturas") or msgcontains(msg, "monstros") or msgcontains(msg, "matar") or msgcontains(msg, "ajudar") then
		selfSay("Aqui esta os montros: \n{Rat}, {Rotworm}, {Orc}, {Slime} ...", cid)
		npcHandler.topic[cid] = 0
		
    elseif msgcontains(msg, "rat") or msgcontains(msg, "ratos") then
         if getPlayerStorageValue(cid, storage.rat) == -1 then
             selfSay("Eu tenho a missão de você matar 10 ratos, você aceita ?", cid)
             npcHandler.topic[cid] = 1
         elseif getPlayerStorageValue(cid, storage.rat) == 1 then
             selfSay("Você matou os 10 ratos? ", cid)
             npcHandler.topic[cid] = 1
         else
             selfSay("Você já cumpriu a missão.", cid)
         end
    elseif msgcontains(msg, "yes") or msgcontains(msg, "sim") then
         if getPlayerStorageValue(cid, storage.rat) == -1 then
			npcHandler.topic[cid] = 1
             selfSay("Bom, volte quando você os matar.", cid)
             setPlayerStorageValue(cid, storage.rat, 1)
			 npcHandler.topic[cid] = 0
         else
             if getPlayerStorageValue(cid, 19400) == 10 then
				npcHandler.topic[cid] = 1
                 selfSay("Bom trabalho, aqui está sua recompensa.", cid)
                 doPlayerAddItem(cid, 2152, 1)
                 doPlayerAddExp(cid, 200)
                 setPlayerStorageValue(cid, storage.rat, 2)
				 npcHandler.topic[cid] = 0
             else
                 selfSay("Você não matou todos eles, retorne quando terminar. ", cid)
             end
			end
	    if msgcontains(msg, "rotworm") then
		if getPlayerStorageValue(cid, storage.rotworm) == -1 then
			npcHandler.topic[cid] = 2
             selfSay("Bom, volte quando você os matar.", cid)
             setPlayerStorageValue(cid, storage.rotworm, 1)
			 npcHandler.topic[cid] = 0
        else
            if getPlayerStorageValue(cid, 19401) == 50 then
				npcHandler.topic[cid] = 2
                 selfSay("Bom trabalho, aqui está sua recompensa.", cid)
                 doPlayerAddItem(cid, 2160, 1)
                 doPlayerAddExp(cid, 200)
                 setPlayerStorageValue(cid, storage.rotworm, 2)
				npcHandler.topic[cid] = 0
             else
                 selfSay("Você não matou todos eles, retorne quando terminar. ", cid)
             end
         end
		 end
	    if msgcontains(msg, "orc") then	
		if getPlayerStorageValue(cid, storage.orc) == -1 then
			npcHandler.topic[cid] = 3
             selfSay("Bom, volte quando você os matar.", cid)
             setPlayerStorageValue(cid, storage.orc, 1)
			 npcHandler.topic[cid] = 0
        else
            if getPlayerStorageValue(cid, 19402) == 60 then
				npcHandler.topic[cid] = 3
                 selfSay("Bom trabalho, aqui está sua recompensaaaa.", cid)
                 doPlayerAddItem(cid, 2160, 1)
                 doPlayerAddExp(cid, 200)
                 setPlayerStorageValue(cid, storage.orc, 2)
				 npcHandler.topic[cid] = 0
             else
                 selfSay("Você não matou todos eles, retorne quando terminar. ", cid)
             end
         end
		 end
		 
	elseif msgcontains(msg, "Rotworm") then
         if getPlayerStorageValue(cid, storage.rotworm) == -1 then
             selfSay("Você tem que matar 50 Rotworm, você aceita ?", cid)
        elseif getPlayerStorageValue(cid, storage.rotworm) == 1 then
             selfSay("Você matou os 50 Rotworm? ", cid)
			 npcHandler.topic[cid] = 2
        else
             selfSay("Você já cumpriu essa missão.", cid)
         end
    -- if msgcontains(msg, "yes") or msgcontains(msg, "sim") and talkState[talkUser] == 2 then

		 -- end
		 
	elseif msgcontains(msg, "orc") then
        if getPlayerStorageValue(cid, storage.orc) == -1 then
             selfSay("Você tem que matar 50 orc, você aceita ?", cid)
        elseif getPlayerStorageValue(cid, storage.orc) == 1 then
             selfSay("Você matou os 50 orc? ", cid)
			 npcHandler.topic[cid] = 3
        else
             selfSay("Você já cumpriu essa missão.", cid)
         end
    -- if msgcontains(msg, "yes") or msgcontains(msg, "sim") and talkState[talkUser] == 3 then

		 -- end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "no") or msgcontains(msg, "não") or msgcontains(msg, "nao") and talkState[talkUser] == 1 then
         selfSay("Ok, então.", cid)
         npcHandler.topic[cid] = 0
     end
	 
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:addModule(FocusModule:new())

 

Editado por amoxicilina
melhor formatação dos codigos (veja o histórico de edições)

Postado

Eu não entendi o erro.

                                                                                                               destinyshield.gif.9f031b59b026058f32a1c50da92ebe2a.gif  mídias sociais  destinyshield.gif.02fca81ab0615e050b2bcefd8a73a2e8.gif

                                                                                                                            talk to me              

                                                                                                                               vídeos           

                                                                                             

                                                                                                            LOGONORMAL.png.815b40b04ec583be88d8a1e2626fe430.png

                                                                                                           

                               

Postado
  • Autor

Dei uma lida sobre esses, (else, if e elseif) pra poder entender algo do assunto, ai esta a solução para o problema. Solicito também para que algum moderador feche o tópico. Peço desculpas, por criar o tópico pedindo a solução e eu mesmo a solucionar, mas a solução esta ai pra mais alguém que quiser ou que sirva de exemplo, sla.

 

Citar

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

local storage = {
rat = 19230,
rotworm = 19231,
orc = 19232,
slime = 19233,
}

function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
	 
	 local player = Player(cid)

	if msgcontains(msg, "hello") or msgcontains(msg, "oi") or msgcontains(msg, "ola") or msgcontains(msg, "hi") then
		npcHandler:say(getPlayerSex(cid) == 0 and "Olá meu amigo, tem algumas {criaturas} que eu gostaria que você me ajudace a mata-las, você sera recompensado." or "Olá minha amiga, me ajude a matar algumas {criaturas} que eu lhe recompensarei.", cid)
	elseif msgcontains(msg, "criaturas") or msgcontains(msg, "monstros") or msgcontains(msg, "matar") or msgcontains(msg, "ajudar") then
		selfSay("Aqui esta os montros: \n{Rat}, {Rotworm}, {Orc}, {Slime} ...", cid)
		
		elseif msgcontains(msg, "Rotworm") then
         if getPlayerStorageValue(cid, storage.rotworm) == -1 then
            selfSay("Você tem que matar 50 Rotworm, você aceita ?", cid)
        elseif getPlayerStorageValue(cid, storage.rotworm) == 1 then
            selfSay("Você matou os 50 Rotworm? ", cid)
			npcHandler.topic[cid] = 2
        else
            selfSay("Você já cumpriu essa missão.", cid)
         end
    -- if msgcontains(msg, "yes") or msgcontains(msg, "sim") and talkState[talkUser] == 2 then

		 -- end
		 
	elseif msgcontains(msg, "orc") then
        if getPlayerStorageValue(cid, storage.orc) == -1 then
			npcHandler.topic[cid] = 3
            selfSay("Você tem que matar 50 orc, você aceita ?", cid)
			npcHandler.topic[cid] = 3
        elseif getPlayerStorageValue(cid, storage.orc) == 1 then
            selfSay("Você matou os 50 orc? ", cid)
			npcHandler.topic[cid] = 3
        else
            selfSay("Você já cumpriu essa missão.", cid)
         end
		
			elseif msgcontains(msg, "slime") then
        if getPlayerStorageValue(cid, storage.slime) == -1 then
			npcHandler.topic[cid] = 4
            selfSay("Você tem que matar 5 slime, você aceita ?", cid)
			npcHandler.topic[cid] = 4
        elseif getPlayerStorageValue(cid, storage.slime) == 1 then
             selfSay("Você matou os 5 slime? ", cid)
			 npcHandler.topic[cid] = 4
        else
             selfSay("Você já cumpriu essa missão.", cid)
         end
		
    elseif msgcontains(msg, "rat") or msgcontains(msg, "ratos") then
         if getPlayerStorageValue(cid, storage.rat) == -1 then
             selfSay("Eu tenho a missão de você matar 10 ratos, você aceita?", cid)
             npcHandler.topic[cid] = 1
         elseif getPlayerStorageValue(cid, storage.rat) == 1 then
             selfSay("Você matou os 10 ratos? ", cid)
             npcHandler.topic[cid] = 1
         else
             selfSay("Você já cumpriu a missão.", cid)
         end
		 
    elseif msgcontains(msg, "yes") or msgcontains(msg, "sim") then
		if npcHandler.topic[cid] == 1 then
         if getPlayerStorageValue(cid, storage.rat) == -1 and npcHalndler.topic[cid] == 1 then
			npcHandler.topic[cid] = 1
             selfSay("Bom, volte quando você os matar.", cid)
             setPlayerStorageValue(cid, storage.rat, 1)
			npcHandler.topic[cid] = 1
         else
             if getPlayerStorageValue(cid, 19400) == 10 and npcHandler.topic[cid] == 1 then
				npcHandler.topic[cid] = 1
                selfSay("Bom trabalho, aqui está sua recompensa.", cid)
                doPlayerAddItem(cid, 2152, 1)
                doPlayerAddExp(cid, 200)
                setPlayerStorageValue(cid, storage.rat, 2)
				npcHandler.topic[cid] = 1
             else
                 selfSay("Você não matou todos eles, retorne quando terminar(rat). ", cid)
             end
			end
			
			---rotworm
	elseif npcHandler.topic[cid] == 2 then
			if getPlayerStorageValue(cid, storage.rotworm) == -1 then
			npcHandler.topic[cid] = 2
            selfSay("Bom, volte quando você os matar.", cid)
            setPlayerStorageValue(cid, storage.rotworm, 1)
			npcHandler.topic[cid] = 2
        else
            if getPlayerStorageValue(cid, 19401) == 50 and npcHandler.topic[cid] == 2 then
				npcHandler.topic[cid] = 2
                selfSay("Bom trabalho, aqui está sua recompensa.", cid)
                doPlayerAddItem(cid, 2160, 1)
                doPlayerAddExp(cid, 200)
                setPlayerStorageValue(cid, storage.rotworm, 2)
				npcHandler.topic[cid] = 2
             else
                selfSay("Você não matou todos eles, retorne quando terminar(rotworm). ", cid)
             end
			end
			
			 ---- orc ---
    elseif npcHandler.topic[cid] == 3 then
		if getPlayerStorageValue(cid, storage.orc) == -1 then
            selfSay("Bom, volte quando você os matar.", cid)
			npcHandler.topic[cid] = 3
            setPlayerStorageValue(cid, storage.orc, 1)
			npcHandler.topic[cid] = 3
        else
            if getPlayerStorageValue(cid, 19402) == 60 and npcHandler.topic[cid] == 3 then
				npcHandler.topic[cid] = 3
                selfSay("Bom trabalho, aqui está sua recompensaaaa.", cid)
                doPlayerAddItem(cid, 2160, 1)
                doPlayerAddExp(cid, 200)
                setPlayerStorageValue(cid, storage.orc, 2)
				npcHandler.topic[cid] = 3
             else
                selfSay("Você não matou todos eles, retorne quando terminar(orc). ", cid)
             end
			    return true
         end
		 
			 ---- slime ---
    elseif npcHandler.topic[cid] == 4 then
		if getPlayerStorageValue(cid, storage.slime) == -1 then
            selfSay("Bom, volte quando você os matar.", cid)
            setPlayerStorageValue(cid, storage.slime, 1)
        else
            if getPlayerStorageValue(cid, 19403) == 5 then
                selfSay("Bom trabalho, aqui está sua recompensaaaa.", cid)
                doPlayerAddItem(cid, 2088, 1)
                doPlayerAddExp(cid, 200)
                setPlayerStorageValue(cid, storage.slime, 2)
			 npcHandler.topic[cid] = 0
             else
                selfSay("Você não matou todos eles, retorne quando terminar(slime). ", cid)
             end
			    return true
         end
end
    -- if msgcontains(msg, "yes") or msgcontains(msg, "sim") and talkState[talkUser] == 3 then

		 -- end
         npcHandler.topic[cid] = 0
     elseif msgcontains(msg, "no") or msgcontains(msg, "não") or msgcontains(msg, "nao") and npcHandler.topic[cid] == 1 then
         selfSay("Ok, então.", cid)
         npcHandler.topic[cid] = 0
     end	 
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye.")
npcHandler:addModule(FocusModule:new())

 

 

 

Editado por amoxicilina (veja o histórico de edições)

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.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo