Ir para conteúdo
  • Cadastre-se

(Resolvido)Erro ao tentar colocar loja no npc djin


Ir para solução Resolvido por Dwarfer,

Posts Recomendados

tfs 0.4 / 8.60

Ola, preciso fazer com que meu npc venda itens apartir da storage 100032, alguem poderia me ajudar?

 

 

 

Citar

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


local Topic = {}
local storage = 100057
local storage2 = 100032
 
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 greetCallback(cid)
    Topic[cid] = 0
    return true
end
 
function creatureSayCallback(cid, type, msg)
    local p = getCreatureName(cid) 
   local v = getPlayerStorageValue(cid, storage)
   if npcHandler:isFocused(cid) then
    if msgcontains(msg, 'no') and Topic[cid] == 2 then
        npcHandler:say("Dont disturb me then.",cid)
        Topic[cid] = 1
    elseif msgcontains(msg, 'no') and Topic[cid] >= 4 then
        npcHandler:say("Dont disturb me then.",cid)
        Topic[cid] = 3
        end
    end
    if (msgcontains(msg, "DJANNI'HAH")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == -1 then
    if  getPlayerStorageValue(cid, 100054) == 2 and getPlayerStorageValue(cid, 9030) == 1 then
        npcHandler:say("What do you want from me, "..p.."?", cid)
        npcHandler:addFocus(cid)
        Topic[cid] = 1 
    end 
    elseif Topic[cid] == 1 then
        if msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == -1  then
            npcHandler:say("So Baa'leal thinks you are up to do a mission for us? ...",cid)
            npcHandler:say("I think he is getting old, entrusting human scum such as you are with an important mission like that. ...",cid, 1000)
            npcHandler:say("I don't understand why you haven't been slaughtered right at the gates. ...",cid, 2500)
            npcHandler:say("Are you prepared to embark on a dangerous mission for us?",cid, 3500)
            Topic[cid] = 2
        end
    elseif Topic[cid] == 2 then
        if msgcontains(msg, 'yes') and getPlayerStorageValue(cid, storage) == -1  then
            npcHandler:say("All right then, human. Have you ever heard of the {Tears of Daraman}? ...",cid)
            npcHandler:say("They are precious gemstones made of some unknown blue mineral and possess enormous magical power. ...",cid, 1000)
            npcHandler:say("If you want to learn more about these gemstones don't forget to visit our library. ...",cid, 2000)
            npcHandler:say("Anyway, one of them is enough to create thousands of our mighty djinn blades. ...",cid, 3000)
            npcHandler:say("Unfortunately my last gemstone broke and therefore I'm not able to create new blades anymore. ...",cid, 4000)
            npcHandler:say("To my knowledge there is only one place where you can find these gemstones - I know for a fact that the Marid have at least one of them. ...",cid, 5000)
            npcHandler:say("Well... to cut a long story short, your mission is to sneak into Ashta'daramai and to steal it. ...",cid, 6000)
            npcHandler:say("Needless to say, the Marid won't be too eager to part with it. Try not to get killed until you have delivered the stone to me.",cid, 7000)

            setPlayerStorageValue(cid, 100062, 6)
        end
        Topic[cid] = 0
    end
    if (msgcontains(msg, "DJANNI'HAH")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == 1 then
    if getPlayerStorageValue(cid, storage) == 1 and getPlayerStorageValue(cid, 9030) == 1 then
        npcHandler:say("What do you want from me, "..p.."?", cid)
        npcHandler:addFocus(cid)
        Topic[cid] = 3 
    end 
    elseif Topic[cid] == 3 then
        if msgcontains(msg, 'mission') then
            npcHandler:say("Did you find the tear of Daraman?",cid)
            Topic[cid] = 4
        end
    elseif Topic[cid] == 4 then
        if msgcontains(msg, 'yes') and doPlayerTakeItem(cid, 2346, 1) then
            npcHandler:say("So you have made it? You have really managed to steal a Tear of Daraman? ...",cid)
            npcHandler:say("Amazing how you humans are just impossible to get rid of. Incidentally, you have this character trait in common with many insects and with other vermin. ...",cid, 1000)
            npcHandler:say("Nevermind. I hate to say it, but it you have done us a favour, human. That gemstone will serve us well. ...",cid, 3000)
            npcHandler:say("Baa'leal, wants you to talk to {Malor} concerning some {new mission.} ...",cid, 4500)
            npcHandler:say("Looks like you have managed to extended your life expectancy - for just a bit longer.",cid, 5500)
            setPlayerStorageValue(cid,storage, 1)
            setPlayerStorageValue(cid, 100062, ?
            setPlayerStorageValue(cid,100159, 3)
        else
            npcHandler:say("You better don't return here until you've got the Tear.", cid)
            end
        Topic[cid] = 0
        end
    if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
        npcHandler:say("Finally.",cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        Topic[cid] = 0
        end
    return true
end
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

 

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

Bem, @bpm91, existem algumas maneiras de fazer isso. Vamos fazer pela forma mais completa até para que você possa utilizar em outros scripts depois, caso necessite.

É só seguir o passo a passo abaixo, você é um rapaz esperto, saudável, eu sei que você vai conseguir. EU OUVI UM AMÉM? Além do mais, parece que tá precisando do script já que comentou "up" no tópico (não comente "up", isso é considerado flood, use o botão "Subir este tópico" no canto superior direito - Leia as regras: https://tibiaking.com/forums/forum/101-regras-e-informações/)

 

Em data/npc/lib/npc/npcsystem, abra o arquivo npchandler.lua:

 

Abaixo da linha:

CALLBACK_ONSELL			= 11

Adicione:

CALLBACK_ONTRADEREQUEST = 15

Encontre as linhas:

elseif(id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil) then
	tmpRet = module:callbackOnFarewell(unpack(arg))

E adicione, logo abaixo, o seguinte:

elseif id == CALLBACK_ONTRADEREQUEST and module.callbackOnTradeRequest ~= nil then
	tmpRet = module:callbackOnTradeRequest(unpack(arg))

Procure pela função NpcHandler:onSell (caso a função tenha algumas diferenças em relação ao que eu coloquei abaixo, sem desespero, inspire, expire e siga):

function NpcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
  local callback = self:getCallback(CALLBACK_ONSELL)
  if(callback == nil or callback(cid, itemid, subType, amount, ignoreCap, inBackpacks)) then
    if(self:processModuleCallback(CALLBACK_ONSELL, cid, itemid, subType, amount, ignoreCap, inBackpacks)) then
      --
    end
  end
end

Adicione, logo abaixo:

function NpcHandler:onTradeRequest(cid)
  local callback = self:getCallback(CALLBACK_ONTRADEREQUEST)
  if callback == nil or callback(cid) then
    if self:processModuleCallback(CALLBACK_ONTRADEREQUEST, cid) then
      return true
    end
  end
  return false
end

Tá vendo, não foi tão difícil.

Calma aí, tem mais.

 

Em data/npc/lib/npc/npcsystem, abra o arquivo modules.lua:

 

Procure por:

function ShopModule.requestTrade(cid, message, keywords, parameters, node)
  local module = parameters.module
  if(not module.npcHandler:isFocused(cid)) then
    return false
  end

Logo abaixo, adicione:

if not module.npcHandler:onTradeRequest(cid) then
	return false
end

Em seguida, procure por:

function ShopModule.tradeItem(cid, message, keywords, parameters, node)
  local module = parameters.module
  if(not module.npcHandler:isFocused(cid)) then
    return false
  end

Logo abaixo, adicione:

if not module.npcHandler:onTradeRequest(cid) then
	return true
end

Pronto, eu sempre soube que você conseguiria...

 

Agora, seu NPC. Primeiramente, a linha abaixo tem um erro, acredito que foi ao colar aqui no fórum e a formatação modificou, dá uma olhada aí. Como não sei qual valor estava, deixei comentado no script final.

 

Linha: 

setPlayerStorageValue(cid, 100062, ?

 

Script do NPC com a verificação se o storage do player storage2 é diferente de -1 para poder dar "trade":

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)


local Topic = {}
local storage = 100057
local storage2 = 100032
 
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 greetCallback(cid)
    Topic[cid] = 0
    return true
end
 
function creatureSayCallback(cid, type, msg)
    local p = getCreatureName(cid) 
    local v = getPlayerStorageValue(cid, storage)
    if npcHandler:isFocused(cid) then
        if msgcontains(msg, 'no') and Topic[cid] == 2 then
            npcHandler:say("Dont disturb me then.",cid)
            Topic[cid] = 1
        elseif msgcontains(msg, 'no') and Topic[cid] >= 4 then
            npcHandler:say("Dont disturb me then.",cid)
            Topic[cid] = 3
        end
    end
    if (msgcontains(msg, "DJANNI'HAH")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == -1 then
        if  getPlayerStorageValue(cid, 100054) == 2 and getPlayerStorageValue(cid, 9030) == 1 then
            npcHandler:say("What do you want from me, "..p.."?", cid)
            npcHandler:addFocus(cid)
            Topic[cid] = 1 
        end 
    elseif Topic[cid] == 1 then
        if msgcontains(msg, 'mission') and getPlayerStorageValue(cid, storage) == -1  then
            npcHandler:say("So Baa'leal thinks you are up to do a mission for us? ...",cid)
            npcHandler:say("I think he is getting old, entrusting human scum such as you are with an important mission like that. ...",cid, 1000)
            npcHandler:say("I don't understand why you haven't been slaughtered right at the gates. ...",cid, 2500)
            npcHandler:say("Are you prepared to embark on a dangerous mission for us?",cid, 3500)
            Topic[cid] = 2
        end
    elseif Topic[cid] == 2 then
        if msgcontains(msg, 'yes') and getPlayerStorageValue(cid, storage) == -1  then
            npcHandler:say("All right then, human. Have you ever heard of the {Tears of Daraman}? ...",cid)
            npcHandler:say("They are precious gemstones made of some unknown blue mineral and possess enormous magical power. ...",cid, 1000)
            npcHandler:say("If you want to learn more about these gemstones don't forget to visit our library. ...",cid, 2000)
            npcHandler:say("Anyway, one of them is enough to create thousands of our mighty djinn blades. ...",cid, 3000)
            npcHandler:say("Unfortunately my last gemstone broke and therefore I'm not able to create new blades anymore. ...",cid, 4000)
            npcHandler:say("To my knowledge there is only one place where you can find these gemstones - I know for a fact that the Marid have at least one of them. ...",cid, 5000)
            npcHandler:say("Well... to cut a long story short, your mission is to sneak into Ashta'daramai and to steal it. ...",cid, 6000)
            npcHandler:say("Needless to say, the Marid won't be too eager to part with it. Try not to get killed until you have delivered the stone to me.",cid, 7000)
            setPlayerStorageValue(cid, 100062, 6)
        end
        Topic[cid] = 0
    end
    if (msgcontains(msg, "DJANNI'HAH")) and (not npcHandler:isFocused(cid)) and getPlayerStorageValue(cid, storage) == 1 then
        if getPlayerStorageValue(cid, storage) == 1 and getPlayerStorageValue(cid, 9030) == 1 then
            npcHandler:say("What do you want from me, "..p.."?", cid)
            npcHandler:addFocus(cid)
            Topic[cid] = 3 
        end 
    elseif Topic[cid] == 3 then
        if msgcontains(msg, 'mission') then
            npcHandler:say("Did you find the tear of Daraman?",cid)
            Topic[cid] = 4
        end
    elseif Topic[cid] == 4 then
        if msgcontains(msg, 'yes') and doPlayerTakeItem(cid, 2346, 1) then
            npcHandler:say("So you have made it? You have really managed to steal a Tear of Daraman? ...",cid)
            npcHandler:say("Amazing how you humans are just impossible to get rid of. Incidentally, you have this character trait in common with many insects and with other vermin. ...",cid, 1000)
            npcHandler:say("Nevermind. I hate to say it, but it you have done us a favour, human. That gemstone will serve us well. ...",cid, 3000)
            npcHandler:say("Baa'leal, wants you to talk to {Malor} concerning some {new mission.} ...",cid, 4500)
            npcHandler:say("Looks like you have managed to extended your life expectancy - for just a bit longer.",cid, 5500)
            setPlayerStorageValue(cid,storage, 1)
            --setPlayerStorageValue(cid, 100062, ??)
            setPlayerStorageValue(cid,100159, 3)
        else
            npcHandler:say("You better don't return here until you've got the Tear.", cid)
            end
        Topic[cid] = 0
        end
    if msgcontains(msg, "bye") or msgcontains(msg, "farewell") then
        npcHandler:say("Finally.",cid)
        npcHandler:releaseFocus(cid)
        npcHandler:resetNpc(cid)
        Topic[cid] = 0
    end
    return true
end

local function onTradeRequest(cid)
    if getPlayerStorageValue(cid, storage2) == -1 then
        npcHandler:say('Dwarfer did not give you the permission to trade with me.', cid)
        return false
    end
	return true
end

--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------
npcHandler:setCallback(CALLBACK_ONTRADEREQUEST, onTradeRequest)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

 

 

Se você fizer tudo certo, vai funcionar.

Contato:

 

Link para o post
Compartilhar em outros sites

mano huaehiauhe eu fiz o que vc fez, mas aconteceu isso, nao sei se errei em algum lugar

Screenshot_1.jpg

bugou todos npcs uaheuhae

 

dei ctrl z em tudo e vou tentar de novo, se liga,
quando eu ponho apenas ontrade request ele aparece isso na msg. < isso sem sua config. 

Screenshot_2.jpg

o storage que vc perguntou qual é, é 8

Link para o post
Compartilhar em outros sites

Aqui no TibiaKing mensagens como UP e BUMP são proibidas, utilize o botão subir este tópico. Esta é uma mensagem automática!
Pedimos que leia as regras do fórum!

Spoiler

Here in TibiaKing messages like UP and BUMP are prohibited, use the button raise this topic. This is an automated message!
Please read the forum rules.

 

Compre seus Scripts Agora totalmente seguro e de forma rápida, aceitamos também encomendas.

discord.gg/phJZeHa2k4

 

Projeto ATS (Naruto)

Informações Abaixo

Facebook

Youtube
Discord

 

Tutoriais / Conteúdos

Clique Aqui

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