Ir para conteúdo
  • Cadastre-se

(Resolvido)Erro npc


Ir para solução Resolvido por Bruno Carvalho,

Posts Recomendados

Olá galera, editei um npc aqui para oque eu precisava, e agora ele ta dando erro, será que alguém conseguiria me ajudar? tfs 1.2

 

 

Script do npc

 



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 item = {{21699, 1} {24301, 1} {21699, 1}} --id do item, quantidade

function creatureSayCallback(cid, type, msg)
    local msg, player = string.lower(msg), Player(cid)
    if not npcHandler:isFocused(cid) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            if player:getStorageValue(56473) == -1 then
                if player:getStorageValue(56473) == -1 then
                    npcHandler:say("Hi, ".. player:getName().."! hello young warrior, I realized that you are looking for some adventures, if you can {help} me I can ask one of my servants to take you to a mysterious island.?", cid)
                    npcHandler.topic[cid] = 1
                elseif
                    npcHandler:say("help, ".. player:getName().."! So you are interested? well, what I ask is simple, I have lost 3 chests with personal treasures through the forest, manholes and building, can you bring me the items that they contain??", cid)
                    npcHandler.topic[cid] = 2
                else
                    npcHandler:say("Hi, ".. player:getName().."! Can you find my treasures?", cid)
                    npcHandler.topic[cid] = 3
                end
            else
                npcHandler:say("I have already told my servant that I can help you to reach such an island.", cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
            end
        else
            return false 
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
        player:setStorageValue(56473, 1)
        npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        player:setStorageValue(56473, 1)
        npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 3 then
        if player:removeItem(items[1], items[2]) then
            player:setStorageValue(56473, 1)
            npcHandler:say("Thanks! I'll tell my servant that I can take you to the island.", cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("Sorry, but you still have not found all my treasures.", cid)
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
        npcHandler:say("Ok, I will wait a bit more.", cid)
         npcHandler.topic[cid] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("What?", cid)
         npcHandler.topic[cid] = 0
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Link para o post
Compartilhar em outros sites

Qual erro ocorre? 

Bruno de Carvalho Câmara / Administrador TibiaKing

[email protected]


 

btn_donateCC_LG.gif

 

Em 26/12/2016 em 03:47, Spraypaint disse:

A força da alienação vem dessa fragilidade dos indivíduos, quando apenas conseguem identificar o que os separa e não o que os une.

-miltinho

 

wMwSJFE.png?1

 

Link para o post
Compartilhar em outros sites

@Bruno Carvalho esse aqui, tentei mudar ou tirar e acaba dando erro em outra parte

 


[Warning - NpcScript::NpcScript] Can not load script: Archery.lua
data/npc/scripts/Archery.lua:6: '}' expected near '{'

 

 

Link para o post
Compartilhar em outros sites

@hallanehallex  São 2 npcs na verdade, esse ai ao receber esses items, da storage pro player assim liberando pra poder falar com o 2 npc.

Link para o post
Compartilhar em outros sites

@FaaSouzax  mano configurei um script bem meio boca aqui pois não sei muito sobre LUA

caso te agrade ta ai o script \/ \/

 

local cfg = {
    watergem = 21699,
    watergemqnt = 1,    
    batwing = 24301,
    batwingqnt = 1,    
    applebite = 21699,
    applebiteqnt = 1,    
    reward2 = 0,
    reward2qnt = 0,
    reward3 = 0,
    reward3qnt = 0,
    palavra = "yes",
    mensagem = "Você precisa ter os itens e quantidades corretos.",
    concluir = "Obrigado! Pegue essa cruz e essa caixa como forma de gratidão!"
}
 
local messenge = {
errormsg = "Você ja me entregou os itens necessarios"
}
 
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 playerHaveItems(cid, itemid)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
if getPlayerItemCount(cid, items) <= 0 then
return false
end
end
return true
end
 
function doPlayerRemoveItems(cid, itemid, count)
local items = type(itemid) == "table" and itemid or {itemid}
for i = 1, #items do
doPlayerRemoveItem(cid, items, count ~= nil and count or 1)
end
return nil
end
 
function creatureSayCallback(cid, type, msg)
 
if(not npcHandler:isFocused(cid)) then
return false
end

if getPlayerStorageValue(cid, 56473) == 1 then
selfsay(messenge.errormsg)
return true
end 
 
if msgcontains(msg, cfg.palavra) then
if getPlayerStorageValue(cid, 56473) == -1 then
if getPlayerItemCount(cid, cfg.watergem) >= 1 and getPlayerItemCount(cid, cfg.batwing) >= 1 and getPlayerItemCount(cid, cfg.applebite) >= 1 then
doPlayerRemoveItem(cid, cfg.watergem, cfg.watergemqnt)
doPlayerRemoveItem(cid, cfg.batwing, cfg.batwingqnt)
doPlayerRemoveItem(cid, cfg.applebite, cfg.applebiteqnt)
doPlayerRemoveItem(cid, cfg.eggs, cfg.eggsqnt)
doPlayerAddItem(cid, cfg.reward2, cfg.reward2qnt)
doPlayerAddItem(cid, cfg.reward3, cfg.reward3qnt)
setPlayerStorageValue(cid, 56473, 1)
selfSay(cfg.concluir)
else
selfSay(cfg.mensagem)
end
end 
end
return true
 
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

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

Tenta esse código meu chapa, modifiquei alguns erros que notei por cima:

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 items = {{21699, 1},{24301, 1}} --id do item, quantidade 

function creatureSayCallback(cid, type, msg)
	local msg, player = string.lower(msg), Player(cid)
	if not npcHandler:isFocused(cid) then
		if isInArray({"hi", "hello"}, msg) then
			npcHandler:addFocus(cid)
			if player:getStorageValue(56473) == -1 then
				if player:getStorageValue(56473) == -1 then
					npcHandler:say("Hi, ".. player:getName().."! hello young warrior, I realized that you are looking for some adventures, if you can {help} me I can ask one of my servants to take you to a mysterious island.?", cid)
					npcHandler.topic[cid] = 1
				elseif
				npcHandler:say("help, ".. player:getName().."! So you are interested? well, what I ask is simple, I have lost 3 chests with personal treasures through the forest, manholes and building, can you bring me the items that they contain??", cid)
				npcHandler.topic[cid] = 2
			else
				npcHandler:say("Hi, ".. player:getName().."! Can you find my treasures?", cid)
				npcHandler.topic[cid] = 3
			end
		else
			npcHandler:say("I have already told my servant that I can help you to reach such an island.", cid)
			npcHandler.topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 3 then
		if player:removeItem(items[1][1], items[1][2]) then
			player:setStorageValue(56473, 1)
			npcHandler:say("Thanks! I'll tell my servant that I can take you to the island.", cid)
			npcHandler.topic[cid] = 0
		else
			npcHandler:say("Sorry, but you still have not found all my treasures.", cid)
			npcHandler.topic[cid] = 0
		end
	elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
		npcHandler:say("Ok, I will wait a bit more.", cid)
		npcHandler.topic[cid] = 0
	elseif msgcontains(msg, "bye") then
		npcHandler:say("Bye.", cid)
		npcHandler:releaseFocus(cid)
	else
		npcHandler:say("What?", cid)
		npcHandler.topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

Você utilizou de modo errado a matriz (array dentro de array), você colocou 3 items dentro do array "items", sendo que o primeiro e o terceiro são iguais, então acho que o último é desnecessário.

OBS: Você tem dois items ainda dentro do array, mas só usa um, vou lhe explicar como funciona a matriz:

items = {
	{"a",1},
  	{"b",2}
}

Se você digitar:
 

print(items[1])

Retornará apenas o valor da tabela (matriz), mas se digitar:
 

print(items[1][2])

Resultará o segundo valor ([2]) da primeira ([1]) casa do array items:

1


 

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

Programador PHP, Lua, Java, database administrator.

 

"Nada é verdade, tudo é permitido."

Requiescat in pace.

Link para o post
Compartilhar em outros sites

@Nazo Sim, esqueci de editar o primeiro item ali como disse, coloquei 2 iguais, eu coloquei seu script e tudo mais, só que o erro persistiu ainda.

 


[Warning - NpcScript::NpcScript] Can not load script: Archery.lua
data/npc/scripts/Archery.lua:6: '}' expected near '{'
[Warning - NpcScript::NpcScript] Can not load script: Archery.lua
data/npc/scripts/Archery.lua:6: '}' expected near '{'
 

 

Eu tentei o que voce me mandou e dps tentei modificando só adicionando um item a mais.



 


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 items = {{21699, 1},{24301, 1}, {23495, 1}} --id do item, quantidade 

function creatureSayCallback(cid, type, msg)
    local msg, player = string.lower(msg), Player(cid)
    if not npcHandler:isFocused(cid) then
        if isInArray({"hi", "hello"}, msg) then
            npcHandler:addFocus(cid)
            if player:getStorageValue(56473) == -1 then
                if player:getStorageValue(56473) == -1 then
                    npcHandler:say("Hi, ".. player:getName().."! hello young warrior, I realized that you are looking for some adventures, if you can {help} me I can ask one of my servants to take you to a mysterious island.?", cid)
                    npcHandler.topic[cid] = 1
                elseif
                npcHandler:say("help, ".. player:getName().."! So you are interested? well, what I ask is simple, I have lost 3 chests with personal treasures through the forest, manholes and building, can you bring me the items that they contain??", cid)
                npcHandler.topic[cid] = 2
            else
                npcHandler:say("Hi, ".. player:getName().."! Can you find my treasures?", cid)
                npcHandler.topic[cid] = 3
            end
        else
            npcHandler:say("I have already told my servant that I can help you to reach such an island.", cid)
            npcHandler.topic[cid] = 0
            npcHandler:releaseFocus(cid)
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
        player:setStorageValue(56473, 1)
        npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        player:setStorageValue(56473, 1)
        npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
        npcHandler.topic[cid] = 0
        npcHandler:releaseFocus(cid)
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 3 then
        if player:removeItem(items[1][1], items[1][2]) then
            player:setStorageValue(56473, 1)
            npcHandler:say("Thanks! I'll tell my servant that I can take you to the island.", cid)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("Sorry, but you still have not found all my treasures.", cid)
            npcHandler.topic[cid] = 0
        end
    elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
        npcHandler:say("Ok, I will wait a bit more.", cid)
        npcHandler.topic[cid] = 0
    elseif msgcontains(msg, "bye") then
        npcHandler:say("Bye.", cid)
        npcHandler:releaseFocus(cid)
    else
        npcHandler:say("What?", cid)
        npcHandler.topic[cid] = 0
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

E agradeço a explicação depois irei dar uma estudada a mais nisso

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

De nada, haha ^^
Se sua dúvida estiver sanada, marque a melhor resposta para você no botão esquerdo aos posts aqui.

Programador PHP, Lua, Java, database administrator.

 

"Nada é verdade, tudo é permitido."

Requiescat in pace.

Link para o post
Compartilhar em outros sites

@Nazo Então eu tentei ali, e arrumei a linha 6 que estava dando erro e apareceu esse outro

 


[Warning - NpcScript::NpcScript] Can not load script: Archery.lua
data/npc/scripts/Archery.lua:19: 'then' expected near 'npcHandler'
 

Link para o post
Compartilhar em outros sites
4 horas atrás, FaaSouzax disse:

@Nazo Então eu tentei ali, e arrumei a linha 6 que estava dando erro e apareceu esse outro

 


[Warning - NpcScript::NpcScript] Can not load script: Archery.lua
data/npc/scripts/Archery.lua:19: 'then' expected near 'npcHandler'
 

Tente isso:

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 items = {{21699, 1},{24301, 1}, {23495, 1}} --id do item, quantidade 

function creatureSayCallback(cid, type, msg)
	local msg, player = string.lower(msg), Player(cid)
	if not npcHandler:isFocused(cid) then
		if isInArray({"hi", "hello"}, msg) then
			npcHandler:addFocus(cid)
			if player:getStorageValue(56473) == -1 then
				if player:getStorageValue(56473) == -1 then
					npcHandler:say("Hi, ".. player:getName().."! hello young warrior, I realized that you are looking for some adventures, if you can {help} me I can ask one of my servants to take you to a mysterious island.?", cid)
					npcHandler.topic[cid] = 1
				else
					npcHandler:say("help, ".. player:getName().."! So you are interested? well, what I ask is simple, I have lost 3 chests with personal treasures through the forest, manholes and building, can you bring me the items that they contain??", cid)
					npcHandler.topic[cid] = 2
				end	
			else
				npcHandler:say("Hi, ".. player:getName().."! Can you find my treasures?", cid)
				npcHandler.topic[cid] = 3
			end
		else
			npcHandler:say("I have already told my servant that I can help you to reach such an island.", cid)
			npcHandler.topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 3 then
		if player:removeItem(items[1][1], items[1][2]) then
			player:setStorageValue(56473, 1)
			npcHandler:say("Thanks! I'll tell my servant that I can take you to the island.", cid)
			npcHandler.topic[cid] = 0
		else
			npcHandler:say("Sorry, but you still have not found all my treasures.", cid)
			npcHandler.topic[cid] = 0
		end
	elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
		npcHandler:say("Ok, I will wait a bit more.", cid)
		npcHandler.topic[cid] = 0
	elseif msgcontains(msg, "bye") then
		npcHandler:say("Bye.", cid)
		npcHandler:releaseFocus(cid)
	else
		npcHandler:say("What?", cid)
		npcHandler.topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

Programador PHP, Lua, Java, database administrator.

 

"Nada é verdade, tudo é permitido."

Requiescat in pace.

Link para o post
Compartilhar em outros sites

@Nazo Sem nenhum erro quando dei reload, mas por causa dos outros erro o npc no server save nao apareceu, e agora quando vou cria-lo aparece esse erro.

 


Lua Script Error: [Npc interface]
data/npc/scripts/Archery.lua
data/npc/scripts/Archery.lua:62: attempt to index global 'npcHandler' (a nil value)
stack traceback:
[C]: in function '__index'
data/npc/scripts/Archery.lua:62: in main chunk
[C]: in function 'createNpc'
data/talkactions/scripts/place_npc.lua:11: in function
[Warning - NpcScript::NpcScript] Can not load script: Archery.lua

 

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

Sem criar a função não vai funcionar mesmo...

 

Spoiler

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

local items = {{21699, 1},{24301, 1}, {23495, 1}} --id do item, quantidade 

function creatureSayCallback(cid, type, msg)
	local msg, player = string.lower(msg), Player(cid)
	if not npcHandler:isFocused(cid) then
		if isInArray({"hi", "hello"}, msg) then
			npcHandler:addFocus(cid)
			if player:getStorageValue(56473) == -1 then
				if player:getStorageValue(56473) == -1 then
					npcHandler:say("Hi, ".. player:getName().."! hello young warrior, I realized that you are looking for some adventures, if you can {help} me I can ask one of my servants to take you to a mysterious island.?", cid)
					npcHandler.topic[cid] = 1
				else
					npcHandler:say("help, ".. player:getName().."! So you are interested? well, what I ask is simple, I have lost 3 chests with personal treasures through the forest, manholes and building, can you bring me the items that they contain??", cid)
					npcHandler.topic[cid] = 2
				end	
			else
				npcHandler:say("Hi, ".. player:getName().."! Can you find my treasures?", cid)
				npcHandler.topic[cid] = 3
			end
		else
			npcHandler:say("I have already told my servant that I can help you to reach such an island.", cid)
			npcHandler.topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
		player:setStorageValue(56473, 1)
		npcHandler:say("Ok, now I will wait for you. Be careful!", cid)
		npcHandler.topic[cid] = 0
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 3 then
		if player:removeItem(items[1][1], items[1][2]) then
			player:setStorageValue(56473, 1)
			npcHandler:say("Thanks! I'll tell my servant that I can take you to the island.", cid)
			npcHandler.topic[cid] = 0
		else
			npcHandler:say("Sorry, but you still have not found all my treasures.", cid)
			npcHandler.topic[cid] = 0
		end
	elseif msgcontains(msg, "no") and npcHandler.topic[cid] == 2 then
		npcHandler:say("Ok, I will wait a bit more.", cid)
		npcHandler.topic[cid] = 0
	elseif msgcontains(msg, "bye") then
		npcHandler:say("Bye.", cid)
		npcHandler:releaseFocus(cid)
	else
		npcHandler:say("What?", cid)
		npcHandler.topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Tem um puta erro aqui:

image.png

 

Mas deixo isso com vocês...

Bruno de Carvalho Câmara / Administrador TibiaKing

[email protected]


 

btn_donateCC_LG.gif

 

Em 26/12/2016 em 03:47, Spraypaint disse:

A força da alienação vem dessa fragilidade dos indivíduos, quando apenas conseguem identificar o que os separa e não o que os une.

-miltinho

 

wMwSJFE.png?1

 

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.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo