Ir para conteúdo
  • Cadastre-se

(Resolvido)HELP NPC


Ir para solução Resolvido por Elwyn,

Posts Recomendados

galera, to com um erro num npc que estou fazendo...

pq num pedido ali ninguem me ajudou, to tentando me virar....

ele simplesmente não dá o item pro player e também nao fala os textos...

quando eu falo yes pela segunda vez

segue o script.

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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end

local player = Player(cid)

if msgcontains(msg, "help") then
if npcHandler.topic[cid] == 0 then
npcHandler.topic[cid] = 1
npcHandler:say("Yeah yeah, you can help me actually. You know, I feel some bad vibes coming out of the earth, recently. I think there's something wrong with the creatures of the deep. Care to join me?", cid)
else
npcHandler:say('I don\'t know what you are talking about.', cid)
end
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 2
npcHandler:say({
'Great, great. There is something going on, you know? I can feel it in my bones. There really are some bad spirits down there. ...',
'See, a long time ago I acquired these nets. They are called soul nets. Do you know what they can do? Neither do I. ...',
'What I know is they vibrate when evil is near. Yeah, vibration man. ...',
'They also let evil glow in a deep red. Glowing red stuff. So next time you go down there, just take one with you and when you find evil spirits - catch them with the net. ...',
'They will vanish in an instant. But - you will have to take care that all bad spirits in the near vicinity vanish almost instantaneously or they will regenerate. ...',
'So you might need some help down there, my friend. Ready to do this?'
}, cid)
end
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 2 then
player:setStorageValue(15433, 1)
player:addItem(15433, 1)
npcHandler:say("Good, I hope this will help you keeping the spirits away.", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hi there |PLAYERNAME|, and welcome to the gray island.")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_500.gif

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

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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if msgcontains(msg, "help") then
        if npcHandler.topic[cid] == 0 then
            npcHandler.topic[cid] = 1
            npcHandler:say("Yeah yeah, you can help me actually. You know, I feel some bad vibes coming out of the earth, recently. I think there's something wrong with the creatures of the deep. Care to join me?", cid)
        else
            npcHandler:say('I don\'t know what you are talking about.', cid)
        end
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 1 then
        npcHandler.topic[cid] = 2
        npcHandler:say({
        'Great, great. There is something going on, you know? I can feel it in my bones. There really are some bad spirits down there. ...',
        'See, a long time ago I acquired these nets. They are called soul nets. Do you know what they can do? Neither do I. ...',
        'What I know is they vibrate when evil is near. Yeah, vibration man. ...',
        'They also let evil glow in a deep red. Glowing red stuff. So next time you go down there, just take one with you and when you find evil spirits - catch them with the net. ...',
        'They will vanish in an instant. But - you will have to take care that all bad spirits in the near vicinity vanish almost instantaneously or they will regenerate. ...',
        'So you might need some help down there, my friend. Ready to do this?'
        }, cid)
        elseif npcHandler.topic[cid] == 2 and player:getStorageValue(15433) ~= 1 then
            player:setStorageValue(15433, 1)
            player:addItem(15433, 1)
            npcHandler:say("Good, I hope this will help you keeping the spirits away.", cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hi there |PLAYERNAME|, and welcome to the gray island.")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

 

Você tinha dois elseifs iguais, então o segundo nunca era checado na prática.

Link para o post
Compartilhar em outros sites

Pode fechar o topico?

YDmXTU2.png

 

Entenda tudo sobre VPS, DEDICADOS & HOSPEDAGENS. => Clique aqui

Global Full Download 10.9x - TFS 1.2/FERUMBRAS/KRAILOS. => Clique aqui

 

Muitos querem aquilo que você tem, 
mas vão desistir quando souberem o preço que você pagou.

 

skype-favicon.png lu.lukinha

message-16.png [email protected]

Link para o post
Compartilhar em outros sites

se tu quiser, eu marquei a opção melhor resposta, mas não foi, agora foi, você quem sabe em :)

 

? Quando você quiser fechar algum tópico relate no próprio tópico ou denuncie-o pedindo para fechar.

YDmXTU2.png

 

Entenda tudo sobre VPS, DEDICADOS & HOSPEDAGENS. => Clique aqui

Global Full Download 10.9x - TFS 1.2/FERUMBRAS/KRAILOS. => Clique aqui

 

Muitos querem aquilo que você tem, 
mas vão desistir quando souberem o preço que você pagou.

 

skype-favicon.png lu.lukinha

message-16.png [email protected]

Link para o post
Compartilhar em outros sites

agora estou com um outro npc aqui

com o mesmo erro...

alguem pode arrumar?

 

local keywordHandler = KeywordHandler:new()


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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end

local player = Player(cid)

if msgcontains(msg, "flou") then
if npcHandler.topic[cid] == 0 then
npcHandler.topic[cid] = 1
npcHandler:say("Lhnjei gouthn naumpi! I know why you are here. I can explain everything.", cid)
else
npcHandler:say('I don\'t know what you are talking about.', cid)
end
elseif msgcontains(msg, 'explain') then
if npcHandler.topic[cid] == 1 then
npcHandler.topic[cid] = 2
npcHandler:say({
'By entering this place, you have earned the right to learn what this is all about. This is a long story. Are you sure you want to hear this?'
}, cid)
elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 2 then
npcHandler.topic[cid] = 3
npcHandler:say({
'I was once captain of a ship, the Skyflare. We were traders for King Tibianus and on our way home when we got into a storm. We fought hard to escape the cold grip of the sea. ...',
'I myself did what I could to navigate the Skyflare out of this mess. They depended on me. Me, the navigator. And I succeeded. ...',
'However, when the sea calmed down and the rain was finally gone, we recognised that our ship wouldn't move. It wasn't my fault. ...',
'There was a strong gale and we could already see this island on the horizon. There were seagulls all around the Skyflare to lead us to dry land. But the ship did not move a single inch. It was NOT my fault. ...',
'We dived under the bow and saw that it was stuck right on the tip of a sharp rock. The world below us was treacherous, we could see large underwater mountains and a labyrinthine system of caves and holes. ...',
'Some of my men panicked and hijacked the dinghies to reach the island, others tried to swim. I remained on the ship. It was not my FAULT. It was not. ...',
'Do you have enough, can I stop?'
}, cid)
elseif msgcontains(msg, 'no') then
if npcHandler.topic[cid] == 2 then
npcHandler.topic[cid] = 3
npcHandler:say({
'When none of my men returned, I forced myself to make a decision. Either dying on this dead ship or plunging into the liquid black beneath. ...',
'In my desperation my thoughts fell onto a strange armor - a gift from a trader we dealt with just before the storm. Strange ornaments and fish-like elements decorated this armor. We thought it would fit just perfectly into the captain's cabin. ...',
'He said something like a 'blessed breath' and 'to subdue the drift'. We thought he wanted to sell us worthless decoration and make it look interesting. If I had only listened to what he said. ...',
'I figured that this thing would have something to do with diving or at least protect me from the icy water. I put it on, grabbed a shimmer glower from our storage to light my path and jumped in. ...',
'Do you want me to go on?'
}, cid)

elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 3 then
npcHandler.topic[cid] = 4
npcHandler:say({
'Hmpf. The armor was working. After some time I was surrounded by darkness and could only see as far as my shimmer glower would me allow to. But I didn't feel the cold - I could even breathe through that helmet. ...',
'I dived into the deep black. Across rugged mountains, vast fields of kelp, swarms of strange fish. ...',
'And then I laid my eyes on a creature I have never seen before. I now know that they call themselves Njey. You would call them the 'Creatures of the Deep' or 'Deeplings'. ...',
'I am now convinced that when they first saw me descending in that suit with the light of the shimmer glower encompassing me, they took me for their God King Qjell. And that's when it all started to make sense. Don't you agree?'
}, cid)

elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 4 then
npcHandler.topic[cid] = 5
npcHandler:say({
'Of course you do. And they did, too. They obeyed me. They adored me. They followed me. ...',
'I learnt everything about their culture, their life, their goals and their problems. I found out about vile insect-like creatures inhabiting the surface of the island. And their waiting for the return of Qjell. ...',
'I practically rewrote their history. I WAS THE SECOND COMING. I WAS QJELL. I, THE NAVIGATOR. ...',
' And I navigated them out of their miserable lives. Away from their petty interests. I led them to a greater purpose - to form chaos out of order, to bring back the storm to the seas and to make THINGS MOVE. Do you want to hear the rest as well?'
}, cid)

elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 5 then
npcHandler.topic[cid] = 6
npcHandler:say({
'I control EVERYTHING from this room, navigating the fate of this land for more than a century now. Can you see all these funnels? My voice travels through them and throughout everything down here! ...'
}, cid)

elseif msgcontains(msg, 'helmet') then
if npcHandler.topic[cid] == 6 then
npcHandler.topic[cid] = 7
npcHandler:say({
'NAAAAARGH. If you promise to leave me alone and NOT TO TELL MY SECRET to anyone - you can have one. ...',
'NO! Not the one I'm wearing. I am BOUND to this device. This suit has granted me a longer life. However, once you have spent a certain time with this - there is no turning back if you know what I mean. ... ',
'The armor will merge with your very body. Holding you captive, holding your life in its hands like a ransom. ... ',
' Using Deepling craft and various components from down here, I created several spare helmets - just in case this one gets damaged. If you return that small golden anchor to me, you can have one. Will you? '
}, cid)

elseif msgcontains(msg, 'yes') then
if npcHandler.topic[cid] == 7 then
npcHandler.topic[cid] = 8
player:addOutfit(463)
player:addOutfit(464)
player:setStorageValue(15434, 1)
npcHandler:say({
'Then take this one. And remember: DO NOT TELL ANYONE ABOUT ME OR ANYTHING YOU HAVE HEARD HERE TODAY. '
}, cid)
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hello there!")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

 

PS: não vou criar outro tópico, pq ja tem esse huehue

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_500.gif

Link para o post
Compartilhar em outros sites

(O código está no "Spoiler", se quiser entender o que você errou leia abaixo)

 

Mesmo erro que o anterior. Vário elseifs iguais, logo nunca vai passar do primeiro.

Ajuda bastante para você pode procurar erros se você identar o código, fica mais perceptível o que cada bloco do código faz.

 

O que estou falando de vários elseif iguais é isso que você está fazendo:

 

if msgconstains(msg, 'yes') then
    -- Código
elseif msgcontains(msg, 'yes') then
    -- Segundo Código
end

 

Se você fizer isso, ele nunca vai entrar no bloco do "Segundo Código", sempre parando no primeiro.

 

Você tem que fazer assim, por exemplo:

 

if msgcontains(msg, 'yes') then
    if npcHandler.topic[cid] == 1 then
        -- Código
    elseif npcHandler.topic[cid] == 2 then
        -- Segundo Código
    end
end

 

Lembrando que os if npcHandler.topic tem que ser elseif, se não o player pode falar um yes e acabar percorrendo o diálogo inteiro do npc sem querer.

Ah, e nos seus dois códigos agora o player pode pegar o item várias vezes apenas repetindo "yes", é bom você por uma restrição nos ifs para isso não acontecer. Nos dois códigos eu tomei a liberdade e fiz isso, adicionando o "and player:getStorageValue(value) ~= 1"

E quando o player já tem esse storage e mesmo assim falar "yes" é bom você fazer o npc falar algo tipo "Você já esteve aqui" ou "Você já aceitou a quest" e derivados, para o player não ficar no vento sem saber se ele pegou tudo que podia ou não.

 

local keywordHandler = KeywordHandler:new()
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if msgcontains(msg, "flou") then
        if npcHandler.topic[cid] == 0 then
            npcHandler.topic[cid] = 1
            npcHandler:say("Lhnjei gouthn naumpi! I know why you are here. I can explain everything.", cid)
        else
            npcHandler:say('I don\'t know what you are talking about.', cid)
        end
    elseif msgcontains(msg, 'explain') then
        if npcHandler.topic[cid] == 1 then
        npcHandler.topic[cid] = 2
        npcHandler:say({
        'By entering this place, you have earned the right to learn what this is all about. This is a long story. Are you sure you want to hear this?'
        }, cid)
    elseif msgcontains(msg, 'yes') then
        if npcHandler.topic[cid] == 2 then
            npcHandler.topic[cid] = 3
            npcHandler:say({
            'I was once captain of a ship, the Skyflare. We were traders for King Tibianus and on our way home when we got into a storm. We fought hard to escape the cold grip of the sea. ...',
            'I myself did what I could to navigate the Skyflare out of this mess. They depended on me. Me, the navigator. And I succeeded. ...',
            'However, when the sea calmed down and the rain was finally gone, we recognised that our ship wouldn't move. It wasn't my fault. ...',
            'There was a strong gale and we could already see this island on the horizon. There were seagulls all around the Skyflare to lead us to dry land. But the ship did not move a single inch. It was NOT my fault. ...',
            'We dived under the bow and saw that it was stuck right on the tip of a sharp rock. The world below us was treacherous, we could see large underwater mountains and a labyrinthine system of caves and holes. ...',
            'Some of my men panicked and hijacked the dinghies to reach the island, others tried to swim. I remained on the ship. It was not my FAULT. It was not. ...',
            'Do you have enough, can I stop?'
            }, cid)
        elseif npcHandler.topic[cid] == 4 then
            npcHandler.topic[cid] = 5
            npcHandler:say({
            'Of course you do. And they did, too. They obeyed me. They adored me. They followed me. ...',
            'I learnt everything about their culture, their life, their goals and their problems. I found out about vile insect-like creatures inhabiting the surface of the island. And their waiting for the return of Qjell. ...',
            'I practically rewrote their history. I WAS THE SECOND COMING. I WAS QJELL. I, THE NAVIGATOR. ...',
            ' And I navigated them out of their miserable lives. Away from their petty interests. I led them to a greater purpose - to form chaos out of order, to bring back the storm to the seas and to make THINGS MOVE. Do you want to hear the rest as well?'
            }, cid)
        elseif npcHandler.topic[cid] == 5 then
            npcHandler.topic[cid] = 6
            npcHandler:say({
            'I control EVERYTHING from this room, navigating the fate of this land for more than a century now. Can you see all these funnels? My voice travels through them and throughout everything down here! ...'
            }, cid)
        elseif npcHandler.topic[cid] == 7 and player:getStorageValue(15434, 1) ~= 1 then
            npcHandler.topic[cid] = 8
            player:addOutfit(463)
            player:addOutfit(464)
            player:setStorageValue(15434, 1)
            npcHandler:say({
            'Then take this one. And remember: DO NOT TELL ANYONE ABOUT ME OR ANYTHING YOU HAVE HEARD HERE TODAY. '
            }, cid)
        end
    elseif msgcontains(msg, 'no') then
        if npcHandler.topic[cid] == 2 then
            npcHandler.topic[cid] = 3
            npcHandler:say({
            'When none of my men returned, I forced myself to make a decision. Either dying on this dead ship or plunging into the liquid black beneath. ...',
            'In my desperation my thoughts fell onto a strange armor - a gift from a trader we dealt with just before the storm. Strange ornaments and fish-like elements decorated this armor. We thought it would fit just perfectly into the captain's cabin. ...',
            'He said something like a 'blessed breath' and 'to subdue the drift'. We thought he wanted to sell us worthless decoration and make it look interesting. If I had only listened to what he said. ...',
            'I figured that this thing would have something to do with diving or at least protect me from the icy water. I put it on, grabbed a shimmer glower from our storage to light my path and jumped in. ...',
            'Do you want me to go on?'
            }, cid)

            elseif msgcontains(msg, 'yes') then
            if npcHandler.topic[cid] == 3 then
            npcHandler.topic[cid] = 4
            npcHandler:say({
            'Hmpf. The armor was working. After some time I was surrounded by darkness and could only see as far as my shimmer glower would me allow to. But I didn't feel the cold - I could even breathe through that helmet. ...',
            'I dived into the deep black. Across rugged mountains, vast fields of kelp, swarms of strange fish. ...',
            'And then I laid my eyes on a creature I have never seen before. I now know that they call themselves Njey. You would call them the 'Creatures of the Deep' or 'Deeplings'. ...',
            'I am now convinced that when they first saw me descending in that suit with the light of the shimmer glower encompassing me, they took me for their God King Qjell. And that's when it all started to make sense. Don't you agree?'
            }, cid)
        end
    elseif msgcontains(msg, 'helmet') then
        if npcHandler.topic[cid] == 6 then
            npcHandler.topic[cid] = 7
            npcHandler:say({
            'NAAAAARGH. If you promise to leave me alone and NOT TO TELL MY SECRET to anyone - you can have one. ...',
            'NO! Not the one I\'m wearing. I am BOUND to this device. This suit has granted me a longer life. However, once you have spent a certain time with this - there is no turning back if you know what I mean. ... ',
            'The armor will merge with your very body. Holding you captive, holding your life in its hands like a ransom. ... ',
            ' Using Deepling craft and various components from down here, I created several spare helmets - just in case this one gets damaged. If you return that small golden anchor to me, you can have one. Will you? '
            }, cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Hello there!")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

Link para o post
Compartilhar em outros sites

entendi, muito obrigado pela explicação adequada, mas em, no caso do addon que este npc dá, o player só irá falar com ele uma vez na vida :O

vou arrumar um action que entra na sala só uma vez 

isso é facil..

 

mas e esse seu spoiler é o script funcional correto ?

 

mas cara, mesmo assim, se eu fizer só

elseif npcHandler.topic[cid] == 2 then
        -- Segundo Código
   
end
end

 

ele não vai pegar a segunda parte do código com a mesma palavra da primeira parte

no exemplo ali...

"yes"...

tem que ser words diferentes

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

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_500.gif

Link para o post
Compartilhar em outros sites

entendi, muito obrigado pela explicação adequada, mas em, no caso do addon que este npc dá, o player só irá falar com ele uma vez na vida :O

vou arrumar um action que entra na sala só uma vez 

isso é facil..

 

mas e esse seu spoiler é o script funcional correto ?

 

mas cara, mesmo assim, se eu fizer só

elseif npcHandler.topic[cid] == 2 then

        -- Segundo Código

    end

end

 

ele não vai pegar a segunda parte do código com a mesma palavra da primeira parte

no exemplo ali...

"yes"...

tem que ser words diferentes

 

Desculpa, não entendi direito sua duvida. Você quis dizer que ele não vai entrar em "Segundo Código" com a keyword 'yes'? Se for o caso, ele deverá entrar se você na primeira parte mudar o npc.Handler.topic[cid] para 2 e ele falar 'yes' novamente.

Link para o post
Compartilhar em outros sites

Desculpa, não entendi direito sua duvida. Você quis dizer que ele não vai entrar em "Segundo Código" com a keyword 'yes'? Se for o caso, ele deverá entrar se você na primeira parte mudar o npc.Handler.topic[cid] para 2 e ele falar 'yes' novamente.

desculpe...

eu consegui arrumar... segue ele feito ...

local keywordHandler = KeywordHandler:new()

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 function creatureSayCallback(cid, type, msg)

if not npcHandler:isFocused(cid) then

return false

end

local player = Player(cid)

if msgcontains(msg, "flou") then

if npcHandler.topic[cid] == 0 then

npcHandler.topic[cid] = 1

npcHandler:say("Lhnjei gouthn naumpi! I know why you are here. I can explain everything.", cid)

else

npcHandler:say('I don\'t know what you are talking about.', cid)

end

elseif npcHandler.topic[cid] == 1 and msgcontains(msg, "explain") then

npcHandler.topic[cid] = 2

npcHandler:say("By entering this place, you have earned the right to learn what this is all about. This is a long story. Are you sure you want to hear this?", cid)

elseif npcHandler.topic[cid] == 2 and msgcontains(msg, "yes") then

npcHandler.topic[cid] = 3

npcHandler:say({

'I was once captain of a ship, the Skyflare. We were traders for King Tibianus and on our way home when we got into a storm. We fought hard to escape the cold grip of the sea. ...',

'I myself did what I could to navigate the Skyflare out of this mess. They depended on me. Me, the navigator. And I succeeded. ...',

'However, when the sea calmed down and the rain was finally gone, we recognised that our ship wouldn\'t move. It wasn\'t my fault. ...',

'There was a strong gale and we could already see this island on the horizon. There were seagulls all around the Skyflare to lead us to dry land. But the ship did not move a single inch. It was NOT my fault. ...',

'We dived under the bow and saw that it was stuck right on the tip of a sharp rock. The world below us was treacherous, we could see large underwater mountains and a labyrinthine system of caves and holes. ...',

'Some of my men panicked and hijacked the dinghies to reach the island, others tried to swim. I remained on the ship. It was not my FAULT. It was not. ...',

'Do you have enough, can I stop?'

}, cid)

elseif npcHandler.topic[cid] == 3 and msgcontains(msg, "no") then

npcHandler.topic[cid] = 4

npcHandler:say({

'When none of my men returned, I forced myself to make a decision. Either dying on this dead ship or plunging into the liquid black beneath. ...',

'In my desperation my thoughts fell onto a strange armor - a gift from a trader we dealt with just before the storm. Strange ornaments and fish-like elements decorated this armor. We thought it would fit just perfectly into the captain\'s cabin. ...',

'He said something like a \'blessed breath\' and \'to subdue the drift\'. We thought he wanted to sell us worthless decoration and make it look interesting. If I had only listened to what he said. ...',

'I figured that this thing would have something to do with diving or at least protect me from the icy water. I put it on, grabbed a shimmer glower from our storage to light my path and jumped in. ...',

'Do you want me to go on?'

}, cid)

elseif npcHandler.topic[cid] == 4 and msgcontains(msg, "yes") then

npcHandler.topic[cid] = 5

npcHandler:say({

'Hmpf. The armor was working. After some time I was surrounded by darkness and could only see as far as my shimmer glower would me allow to. But I didn\'t feel the cold - I could even breathe through that helmet. ...',

'I dived into the deep black. Across rugged mountains, vast fields of kelp, swarms of strange fish. ...',

'And then I laid my eyes on a creature I have never seen before. I now know that they call themselves Njey. You would call them the \'Creatures of the Deep\' or \'Deeplings\'. ...',

'I am now convinced that when they first saw me descending in that suit with the light of the shimmer glower encompassing me, they took me for their God King Qjell. And that\'s when it all started to make sense. Don\'t you agree?'

}, cid)

elseif npcHandler.topic[cid] == 4 and msgcontains(msg, "yes") then

npcHandler.topic[cid] = 5

npcHandler:say({

'Of course you do. And they did, too. They obeyed me. They adored me. They followed me. ...',

'I learnt everything about their culture, their life, their goals and their problems. I found out about vile insect-like creatures inhabiting the surface of the island. And their waiting for the return of Qjell. ...',

'I practically rewrote their history. I WAS THE SECOND COMING. I WAS QJELL. I, THE NAVIGATOR. ...',

' And I navigated them out of their miserable lives. Away from their petty interests. I led them to a greater purpose - to form chaos out of order, to bring back the storm to the seas and to make THINGS MOVE. Do you want to hear the rest as well?'

}, cid)

elseif npcHandler.topic[cid] == 5 and msgcontains(msg, "yes") then

npcHandler.topic[cid] = 6

npcHandler:say({

'I control EVERYTHING from this room, navigating the fate of this land for more than a century now. Can you see all these funnels? My voice travels through them and throughout everything down here! ...'

}, cid)

elseif npcHandler.topic[cid] == 6 and msgcontains(msg, "helmet") then

npcHandler.topic[cid] = 7

npcHandler:say({

'NAAAAARGH. If you promise to leave me alone and NOT TO TELL MY SECRET to anyone - you can have one. ...',

'NO! Not the one I\'m wearing. I am BOUND to this device. This suit has granted me a longer life. However, once you have spent a certain time with this - there is no turning back if you know what I mean. ... ',

'The armor will merge with your very body. Holding you captive, holding your life in its hands like a ransom. ... ',

' Using Deepling craft and various components from down here, I created several spare helmets - just in case this one gets damaged. If you return that small golden anchor to me, you can have one. Will you? '

}, cid)

elseif npcHandler.topic[cid] == 7 and msgcontains(msg, "yes") then

npcHandler.topic[cid] = 0

player:addOutfit(463, 2)

player:addOutfit(464, 2)

player:setStorageValue(15432, 1)

player:removeItem(15432, 1)

npcHandler:say({

'Then take this one. And remember: DO NOT TELL ANYONE ABOUT ME OR ANYTHING YOU HAVE HEARD HERE TODAY. '

}, cid)

end

return true

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:setMessage(MESSAGE_GREET, "Hello there!")

npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")

npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")

npcHandler:addModule(FocusModule:new())

 

se quiser ver se tem algum erro...

mas rodou, fez tudo certinho :D

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_500.gif

Link para o post
Compartilhar em outros sites

ah sim, mas não importa, como eu lhe falei, vou colocar um action pra o player só ir uma vez nesse npc...

ele vai ganhar um item x, vai usar em outro, e esse outro vai ter um storage, que se ele ja tiver o addon ele não vai poder entrar...

simples.

to com um bug num outro aqui :S

local keywordHandler = KeywordHandler:new()


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 function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end

local player = Player(cid)

if msgcontains(msg, "help") then
if npcHandler.topic[cid] == 0 then
npcHandler.topic[cid] = 1
npcHandler:say("If you want anything, you should talk to Old Rock Boy over there. I do collect stuff, though. So just ask if you\'re interested in helping me.", cid)
else
npcHandler:say('I don\'t know what you are talking about.', cid)
end
elseif npcHandler.topic[cid] == 1 and msgcontains(msg, "collect") then
npcHandler.topic[cid] = 2
npcHandler:say({
'I collect everything that reflects light in strange ways. However, I am bored by my collection. And there wasn\'t anything new to add for years. ...',
'I like pearls for example - but I have already enough. I also like shells - but I can\'t even count how many I already own. ...',
'If you find anything of REAL VALUE - bring it to me. I will reward you well. You don\'t already have something for me by chance?'
}, cid)
player:setStorageValue(15434, 1)
elseif npcHandler.topic[cid] == 2 and msgcontains(msg, "yes") then
if player:getStorageValue(15434) == 1 and player:getItemCount(15435) > 0 then
npcHandler.topic[cid] = 0
npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
player:setStorageValue(15434, 2)
player:removeItem(15435, 1)
else
npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)

end
elseif msgcontains(msg, "collect") then
npcHandler.topic[cid] = 3
npcHandler:say("Have you got anything for me today?", cid)
elseif npcHandler.topic[cid] == 3 and msgcontains(msg, "yes") then
if player:getStorageValue(15434) == 2 and player:getItemCount(15436) > 0 then
npcHandler.topic[cid] = 0
npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
player:setStorageValue(15434, 3)
player:removeItem(15436, 1)
else
npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)

end
elseif msgcontains(msg, "collect") then
npcHandler.topic[cid] = 4
npcHandler:say("Have you got anything for me today?", cid)


elseif npcHandler.topic[cid] == 4 and msgcontains(msg, "yes") then
if player:getStorageValue(15434) == 3 and player:getItemCount(15434) > 0 then
npcHandler.topic[cid] = 0
npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
player:setStorageValue(15434, 4)
player:removeItem(15434, 1)
else
npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)

end


elseif msgcontains(msg, "collect") then
if player:getStorageValue(15434) == 4 then
npcHandler.topic[cid] = 0
player:addAchievement('Spolium Profundis')
player:addOutfitAddon(463, 1)
player:addOutfitAddon(464, 1)
player:setStorageValue(15434, 5)
player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
npcHandler:say({
'Have you got anything... what? You want what? A reward? HAHAHAHAAAA!! ...',
'No I\'m just teasing you. I\'m really happy about my collection now. ... ',
'Well, I found some kind of weapon a long time ago. I believe it may be especially helpful underwater as it is from the deep folk. In any case it is of more use for you than it would be for me.'
}, cid)
else
npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Need help? Or are you only here for some news. Either way, make it short.")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

 

 

nas duas primeiras vezes que eu falo collect/yes ele pega os items, nas na terceira ele diz que eu não tenho nada valioso pra ele, o que será que pode ser?

esse npc funciona assim...

fala "hi / help" === ele vai dar um storage

"collect / yes" === ele vai pegar um item e agradecer, e dar o segundo storage.

dai falando "collect / yes" === ele vai pegar outro item e dar o terceiro storage

dai falando "collect / yes" === ele vai pegar outro item e dar o quarto storage

 

falando "collect" novamente ele vai ver se o player tem o quarto storage, e vai dar o addon....

e também não sei como colocar a verificação se ele ja te o storage do addon pra ele não pegar os items novamente

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

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_500.gif

Link para o post
Compartilhar em outros sites

(O código está no "Spoiler", se quiser entender o que eu fiz, leia abaixo)

 

Então, dessa vez existiam muitos erros de lógica então eu fiz um novo.

 

Eu percebi que quando você fala "collect" pela primeira vez, tem um texto, da segunda em diante outra. E que você usa um storage para saber onde da quest está o player, então eu fiz o seguinte:

 

if msgcontains(msg, "collect") then
        npcHandler.topic[cid] = 2

        if player:getStorageValue(15434) < 1 then
            npcHandler:say({
            'I collect everything that reflects light in strange ways. However, I am bored by my collection. And there wasn\'t anything new to add for years. ...',
            'I like pearls for example - but I have already enough. I also like shells - but I can\'t even count how many I already own. ...',
            'If you find anything of REAL VALUE - bring it to me. I will reward you well. You don\'t already have something for me by chance?'
            }, cid)
        else
            npcHandler:say("Have you got anything for me today?", cid)
        end
end

 

Se a storage que você está usando ainda não tiver sido inicializada, ele fala a mensagem inicial, se não, a segunda. Para entrar em "collect" eu botei para não precisar falar "help" para poupar tempo do player.

 

Agora sobre o tratamento da mensagem "yes", eu fiz o seguinte:

 

Ele só vai entrar no bloco de código para o "yes" se já tiver passado pelo "collect", ou seja, o npcHandler.topic[cid] == 2.

E dentro do bloco de código para o "yes" eu verifiquei com if e elseif em qual parte da quest o player está para dar o storage correto ao player. Dessa forma:

 

    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        if player:getStorageValue(15434) < 1 then
            if player:getItemCount(15435) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 2)
                player:removeItem(15435, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 2 then
            if player:getItemCount(15436) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 3)
                player:removeItem(15436, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 3 then
            if player:getItemCount(15434) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 4)
                player:removeItem(15434, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 4 then
            npcHandler.topic[cid] = 0
            player:addAchievement('Spolium Profundis')
            player:addOutfitAddon(463, 1)
            player:addOutfitAddon(464, 1)
            player:setStorageValue(15434, 5)
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            npcHandler:say({
            'Have you got anything... what? You want what? A reward? HAHAHAHAAAA!! ...',
            'No I\'m just teasing you. I\'m really happy about my collection now. ... ',
            'Well, I found some kind of weapon a long time ago. I believe it may be especially helpful underwater as it is from the deep folk. In any case it is of more use for you than it would be for me.'
            }, cid)
        elseif player:getStorageValue(15434) == 5 then
            npcHandler:say("You already got your reward.", cid)
        end
    end

 

Botei um detalhe também no final, para quando o player já pegou o reward dele, o npc avisar se ele falar outro "collect / yes"

 

local keywordHandler = KeywordHandler:new()
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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)

    if msgcontains(msg, "help") then
        if npcHandler.topic[cid] == 0 then
            npcHandler.topic[cid] = 1
            npcHandler:say("If you want anything, you should talk to Old Rock Boy over there. I do collect stuff, though. So just ask if you\'re interested in helping me.", cid)
        else
            npcHandler:say('I don\'t know what you are talking about.', cid)
        end
    elseif msgcontains(msg, "collect") then
        npcHandler.topic[cid] = 2

        if player:getStorageValue(15434) < 1 then
            npcHandler:say({
            'I collect everything that reflects light in strange ways. However, I am bored by my collection. And there wasn\'t anything new to add for years. ...',
            'I like pearls for example - but I have already enough. I also like shells - but I can\'t even count how many I already own. ...',
            'If you find anything of REAL VALUE - bring it to me. I will reward you well. You don\'t already have something for me by chance?'
            }, cid)
        else
            npcHandler:say("Have you got anything for me today?", cid)
        end
    elseif msgcontains(msg, "yes") and npcHandler.topic[cid] == 2 then
        if player:getStorageValue(15434) < 1 then
            if player:getItemCount(15435) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 2)
                player:removeItem(15435, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 2 then
            if player:getItemCount(15436) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 3)
                player:removeItem(15436, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 3 then
            if player:getItemCount(15434) > 0 then
                npcHandler.topic[cid] = 0
                npcHandler:say("Great! Let me see. Amazing! I will take this, thank you!", cid)
                player:setStorageValue(15434, 4)
                player:removeItem(15434, 1)
            else
                npcHandler:say("You don\'t have anything with a REAL VALUE for me!", cid)
            end
        elseif player:getStorageValue(15434) == 4 then
            npcHandler.topic[cid] = 0
            player:addAchievement('Spolium Profundis')
            player:addOutfitAddon(463, 1)
            player:addOutfitAddon(464, 1)
            player:setStorageValue(15434, 5)
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE)
            npcHandler:say({
            'Have you got anything... what? You want what? A reward? HAHAHAHAAAA!! ...',
            'No I\'m just teasing you. I\'m really happy about my collection now. ... ',
            'Well, I found some kind of weapon a long time ago. I believe it may be especially helpful underwater as it is from the deep folk. In any case it is of more use for you than it would be for me.'
            }, cid)
        elseif player:getStorageValue(15434) == 5 then
            npcHandler:say("You already got your reward.", cid)
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, "Need help? Or are you only here for some news. Either way, make it short.")
npcHandler:setMessage(MESSAGE_FAREWELL, "See you, |PLAYERNAME|.")
npcHandler:setMessage(MESSAGE_WALKAWAY, "See you, |PLAYERNAME|.")
npcHandler:addModule(FocusModule:new())

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

parece estar funcionando corretamente, muito obrigado, me salvou nesse script em :)

tu é o cara dos npcs em 

:P

boa sorte no projeto Kiltera também :) obrigadooo 

Se Ajudei Rep+ pra mim ^^

tumblr_lyd1xtGgx81qf9l6uo1_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.

  • 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