Ir para conteúdo
  • Cadastre-se

(Resolvido)Npc com erro


Ir para solução Resolvido por Naze,

Posts Recomendados

 

Criei um npc, mas quando eu digo missão ele não faz nada. Também não dá nenhum erro no console, sei apenas o básico do básico em lua, mesmo assim resolvi tentar criar.

Este é o script:

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local npcTopic = {}
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              npcHandler:onThink()
local npcTopic = {}

    function creatureSayCallback(cid, type, msg)
    local talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg)
    if(not npcHandler:isFocused(cid)) then
        if isInArray({"hi", "hello", "Oi"}, msg) then
        if getPlayerStorageValue(cid, 12101) >= 2 then
        selfSay("Você já completou todas as Missões!", cid)
        else
        if getPlayerStorageValue(cid, 13256) >= 2 then 
        npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois
        else
        npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?.", cid)
        if msgcontains(msg, "missao") and npcTopic[talkUser] == 1 then
            npcHandler:say("vá e me traga os itens!.", cid)
            setPlayerStorageValue(cid, 1456,1)
            npcTopic[talkUser] = 0
        end
            if getPlayerStorageValue(cid, 1456) and npcTopic[talkUser] == 1 then
            npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja entregar os {itens} para aprender a nova magia?.", cid)
            if msgcontains(msg, "itens") and npcTopic[talkUser] == 1 then
            doPlayerRemoveItem(cid, 2160, 20) 
            setPlayerStorageValue(cid, 13256, 1)
            npcHandler:say("Você completou a primeira missão.", cid)
            npcTopic[talkUser] = 0
            else
            npcHandler:say("Você ainda não tem os itens necessários!", cid)
            npcTopic[talkUser] = 0
            end
        end
    return true
    end
    end
    end
    end
    end


npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

o codigo parece meio "podre" ao meu ver, perdão.

Link para o post
Compartilhar em outros sites

@MarkCharlotte Tenta assim:

 

Spoiler

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 talkUser, msg = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid, string.lower(msg)
	if(not npcHandler:isFocused(cid)) then
		if isInArray({"hi", "hello", "Oi"}, msg) then
			if getPlayerStorageValue(cid, 12101) >= 2 then
				selfSay("Você já completou todas as Missões!", cid)
			else
				if getPlayerStorageValue(cid, 13256) >= 2 then 
					npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois
				else
					npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?.", cid)
					if msgcontains(msg, "missao") and talkState[talkUser] == 0 then
						npcHandler:say("vá e me traga os itens!.", cid)
						setPlayerStorageValue(cid, 1456,1)
						talkState[talkUser] = 1
					end
					if getPlayerStorageValue(cid, 1456) and talkState[talkUser] == 1 then
						npcHandler:say("Olá, "..getPlayerName(cid)..". você deseja entregar os {itens} para aprender a nova magia?.", cid)
						if msgcontains(msg, "itens") and talkState[talkUser] == 1 then
							doPlayerRemoveItem(cid, 2160, 20) 
							setPlayerStorageValue(cid, 13256, 1)
							npcHandler:say("Você completou a primeira missão.", cid)
							talkState[talkUser] = 0
						else
							npcHandler:say("Você ainda não tem os itens necessários!", cid)
							talkState[talkUser] = 1
						end
					end
					return true
				end
			end
		end
	end
end

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

 

 

Link para o post
Compartilhar em outros sites

@Vikachu @MarkCharlotte 

Só não da bola pras coisas que eu escrevi, acordei inspirado kkk

Quote

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 doCreatureSayWithDelay(cid,text,type,delay,e)
   if delay<=0 then
      doCreatureSay(cid,text,type)
   else
      local func=function(pars)
                    doCreatureSay(pars.cid,pars.text,pars.type)
                    pars.e.done=TRUE
                 end
      e.done=FALSE
      e.event=addEvent(func,delay,{cid=cid, text=text, type=type, e=e})
   end
end


function cancelNPCTalk(events)
  local ret=1
  for aux=1,table.getn(events) do
     if events[aux].done==FALSE then
        stopEvent(events[aux].event)
     else
        ret=ret+1
     end
  end
  events=nil
  return(ret)
end


function doNPCTalkALot(msgs,interval)
  local e={}
  local ret={}
  if interval==nil then interval=3000 end --3 seconds is default time between messages
  for aux=1,table.getn(msgs) do
      e[aux]={}
      doCreatureSayWithDelay(getNpcCid(),msgs[aux],TALKTYPE_PRIVATE_NP,(aux-1)*interval,e[aux])
      table.insert(ret,e[aux])
  end
  return(ret)
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


    if(msgcontains(msg, 'hi') or msgcontains(msg, 'oi')) and getPlayerStorageValue(cid,1001) == -1 then
    selfSay('Olá, "..getPlayerName(cid)..". você deseja fazer a {missao} para aprender a nova magia?', cid)
talkState[talkUser] = 1


elseif((msgcontains(msg, 'quest') or msgcontains(msg, 'missao')) and talkState[talkUser] == 1) then
selfSay('anda logo entao traste, vai e me tras uns 20 item do id 2160, se vira ai pra achar', cid)


talkState[talkUser] = 0
setPlayerStorageValue(cid, 1001, 1)
setPlayerStorageValue(cid, 1002, 1)


elseif(msgcontains(msg, 'hi') or msgcontains(msg, 'oi')) and getPlayerStorageValue(cid,1002) == 1 then
selfSay('Conseguiu pegar essas merda ae, ja ta quase noite', cid)
talkState[talkUser] = 2


elseif(msgcontains(msg, 'Yes') or msgcontains(msg, 'sim')) and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2160) < 1 then
selfSay('tu nem tem nada, vai tmc mlk, rala.', cid)
talkState[talkUser] = 0


elseif((msgcontains(msg, 'No') or msgcontains(msg, 'nao')) and talkState[talkUser] == 2) then
selfSay('bah,imprestavel mesmo.', cid)
talkState[talkUser] = 0


elseif(msgcontains(msg, 'Yes') or msgcontains(msg, 'sim')) and getPlayerStorageValue(cid,1002) == 1 and talkState[talkUser] == 2 and getPlayerItemCount(cid, 2160) == 1 then
selfSay('Vlw ae, e nois truta!', cid)


doPlayerAddItem(cid, 2160, 100) -- Se quiser add mais algum item junto, ou deleta essa linha
doPlayerRemoveItem(cid, 2160, 20)
setPlayerStorageValue(cid, 13256, 1)

end 
return TRUE
end


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

 

Editado por Hologram (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

@Hologram O npc ainda não me responde. Não sei qual o problema... a versão do server é 8.6

 

Parte xml do npc:

Spoiler

<?xml version="1.0" encoding="UTF-8"?>
<npc name="Jiraya2" script="data/npc/scripts/Novas Missões/Jiraya2.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="66"/>
</npc>

 

E o script está praticamente igual oque você comentou, removi apenas a linha de adcionar o item. Eu digo "quest" ou "missao" mas ele n responde nada de volta

Link para o post
Compartilhar em outros sites
  • Solução

@MarkCharlotte Cara esse script seu tem muito erro, se funcionasse, o player nem precisaria entregar os itens pq ele ta setando a storagem so de falar items. E as storage tão tudo diferente, fica melhor vc mudar o valor delas. Refiz ele pra você mas tem uma parte que não entendi oq queria com isso. Mas so posta que ajeito, não consigo testa ele pq to no trampo. Se retorna algum erro so posta ele.

 

Deixei as storage que ta no script original (1456 e 13256) pq não sei onde usa mais, mas ela nao utiliza em nada pro funcionamento do npc

 

 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 onCreatureSay(cid, type, msg)
 if getPlayerStorageValue(cid, 12101) >= 2 then
	npcHandler:setMessage(MESSAGE_GREET, "Olá "..getCreatureName(cid)..", Você já completou todas as Missões.")
	npcHandler:setMessage(MESSAGE_WALKAWAY, "Que rude.")
	npcHandler:setMessage(MESSAGE_FAREWELL, "Até... "..getCreatureName(cid)..".")
elseif getPlayerStorageValue(cid, 12101) < 1 then
	npcHandler:setMessage(MESSAGE_GREET, "Olá "..getCreatureName(cid)..", você deseja fazer a {missao} para aprender a nova magia?")
	npcHandler:setMessage(MESSAGE_WALKAWAY, "Que rude.")
	npcHandler:setMessage(MESSAGE_FAREWELL, "Até... "..getCreatureName(cid)..".")
elseif getPlayerStorageValue(cid, 12101) == 1 then
	npcHandler:setMessage(MESSAGE_GREET, "Olá "..getCreatureName(cid)..", você deseja entregar os {itens} para aprender a nova magia?.")
	npcHandler:setMessage(MESSAGE_WALKAWAY, "Que rude.")
	npcHandler:setMessage(MESSAGE_FAREWELL, "Até... "..getCreatureName(cid)..".")
	end
	npcHandler:onCreatureSay(cid, type, msg)		
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
	if getPlayerStorageValue(cid,12101) < 1 then
		if isInArray({"missao", "missoes"}, msg) then
				selfSay("vá e me traga os itens!",cid)
				setPlayerStorageValue(cid, 1456,1)
				setPlayerStorageValue(cid, 12101,1)
				talkState[talkUser] = 0
		end
	end
	
if getPlayerStorageValue(cid, 12101) == 1 then
	if isInArray({"itens", "item"}, msg) then
		if doPlayerRemoveItem(cid, 2160, 20) then
			setPlayerStorageValue(cid, 13256, 1)
			setPlayerStorageValue(cid, 12101, 2)
		else
			selfSay("Você ainda não tem os itens necessários!", cid)
		end
	end
end
return true
end


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

Retirei essa parte, depois me explica oq queria com isso que coloco pra você

if getPlayerStorageValue(cid, 13256) >= 2 then 
        npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois

 

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

Discord: Naze#3578

 

Ter Linux Dentro de Windows com Acesso 'localhost' para testes e +

AutoLoot Otimizado Direto na Source (tfs 0.4/otx)

 

// Pirataria é crime, original é roubo, compartilhar é legal.

 

tumblr_muk78tEwDQ1qah4nko1_500.gif

Link para o post
Compartilhar em outros sites

@Naze Testei e deu o seguinte erro:

Spoiler

1.thumb.PNG.942686cf98044d0236086944843df275.PNG

 

Vou tentar explicar melhor como seria o script, achei que dava pra entender, mas vendo agora tá bem confuso.

Seria um script onde o npc passaria uma missão (que seria para entregar 20 itens) ao completar ele setaria a storage para 16356 (podem colocar qualquer número, posso mudar dps) dps ao falar com ele novamente ele verificaria a storage, pra ver se completou a primeira missão, se sim ele passaria outra, e agora que vem essa parte:

if getPlayerStorageValue(cid, 13256) >= 2 then 
        npcHandler:say("Você vai para a ultima missão!.", cid) -- configurar depois

nessa parte eu mesmo iria configurar depois, pois era pra lutar com um npc. Dps do player aceitar a missão de ir lutar,  ele iria e lutava com o outro npc que setaria a storage dele para 12564 (número de testes, podem colocar outro se quiserem) quando voltasse ao npc do tópico, o npc iria dizer "Você derrou tal npc?" se o player disesse "derrotei" então se o player tivesse a storage que o npc de luta setou pra ele, então a missão estaria completa, e o npc do tópico verificaria ela pra ver se ele completou. Esse npc de luta já tenho o script pronto, o problema é esse npc do tópico.

Link para o post
Compartilhar em outros sites

@MarkCharlotte Erro meu não completei o elseif, copia la de novo que arrumei.

 

Bro, quiser essa parte é a frase inicial, ai verifica a storage e responde quando ele fala 'hi', so ir mudando o valor, mas o primeiro if ta verificando o valor 2, entao vc vai ter que troca la para mais.

elseif getPlayerStorageValue(cid, 12101) == 1 then
	npcHandler:setMessage(MESSAGE_GREET, "Olá "..getCreatureName(cid)..", você deseja entregar os {itens} para aprender a nova magia?.")
	npcHandler:setMessage(MESSAGE_WALKAWAY, "Que rude.")
	npcHandler:setMessage(MESSAGE_FAREWELL, "Até... "..getCreatureName(cid)..".")

@edit, tinha editando mas nao salvado, se copio antes de eu salva copia de novo q agr foi.

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

Discord: Naze#3578

 

Ter Linux Dentro de Windows com Acesso 'localhost' para testes e +

AutoLoot Otimizado Direto na Source (tfs 0.4/otx)

 

// Pirataria é crime, original é roubo, compartilhar é legal.

 

tumblr_muk78tEwDQ1qah4nko1_500.gif

Link para o post
Compartilhar em outros sites

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

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo