• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua NPC Stories

hasbro

Member
Joined
Feb 15, 2009
Messages
286
Reaction score
6
I add summ system npc story, but npc have one error..
Npc answer the first yes, but second and third not..


LUA:
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 talkState = {}

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end                                                                                                  
	if msgcontains(msg,'machine') then
	if getPlayerStorageValue(cid,62338) == 1 then
	npcHandler:say('Ah, the machine you found at that island. Well, I built this thing to venture far beneath the very soil we walk on. I suspected something there. Something deep down below. Something evil. Even more so than the dreaded bugs which are crawling my study. ...',cid)
	npcHandler:say('Drilling hole after hole only to get stuck in another hard, unbreakable sediment again and again, I was about to quit this pointless enterprise. ...',cid)
	npcHandler:say('However, the very last day I lingered on that island, I finally fell into a large hollow right under the beach. My drill was shattered and the machine was not mobile anymore. ...',cid)
	npcHandler:say('I am well aware that this may sound laughable now - at this part all of my colleagues burst into laughter anyway - but suddenly there were stairs. Incredibly large stairs that led to the underworld. A world deep under the sea - can you believe this?',cid)
	 talk_state = 1
	else
	npcHandler:say('You\'re not allowed',cid)
	 talk_state = 0
	end
	elseif msgcontains(msg,'yes') then
    if  talk_state == 1  then
    npcHandler:say('You do? Well, the end of this story was that I had to leave the place. ...',cid)
    npcHandler:say('I couldn\'t explore what lies below the stairs as their was an unpredictable stream. Diving into these waters would have been an uncontrollable risk, even with the means to survive without any air. ...',cid)
    npcHandler:say('So I used the portable teleporting device I installed into my machine in case of an emergency and went home. I could only take the most important research documents with me and had to leave most of my equipment in the cave. ...',cid)
    npcHandler:say('Of course I also left my final notes with the coordinates there. And for the life of me I cannot remember where I dug that stupid hole. ...',cid)
    npcHandler:say('When I arrived at home I immediately started looking for a way to manoeuvre in these chaotic conditions once I rediscovered the lost entrance. I never remembered it, but it seems you found it as you indeed have my original notes. ...',cid)
    npcHandler:say('Oh and just in case you want to complete what I have started - feel free to do so. Up to it?',cid)
	 talk_state = 2
	else
	 talk_state = 0
	end
    elseif msgcontains(msg,'yes')then
    if  talk_state == 2 then
     npcHandler:say('Well, if you really want to delve into this - I could use some help. So you have found my machine on that island? And you found the notes with the coordinates? Then you can find the entrance! ...',cid)
      npcHandler:say('Just look for a large staircase with sprawling steps. There is an unpassable stream there that will prevent you from venturing further on. But fear not, you can indeed travel down there - with these small enhancements I created. ...',cid)
       npcHandler:say('At first, take this gold for the passage by ship and return to the Gray Island from where I started my expedition many years ago. From there you should find a way to reach the Gray Beach of Quirefang as no ordinary ship can land there. ...',cid)
        npcHandler:say('I will put this under your footgear. Here you go. And this in your nose. There. And there will be no further problems for you down there. Except- ah, well you\'ll find out yourself soon enough, won\'t you?',cid)
         talk_state = 3
        else
        talk_state = 0
        end
        elseif msgcontains(msg,'yes') then
        if talk_state == 3 then
        npcHandler:say('Then off you go! I\'m sorry that I cannot offer you any further help but I\'m sure you will find support along your way. And - be careful. The sea can appear pitch black down there.',cid)
        else
        talk_state = 0
        end
        end
        end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
LUA:
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 talkState = {}
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
	if msgcontains(msg,'machine') then
		if getPlayerStorageValue(cid,62338) == 1 then
			npcHandler:say('Ah, the machine you found at that island. Well, I built this thing to venture far beneath the very soil we walk on. I suspected something there. Something deep down below. Something evil. Even more so than the dreaded bugs which are crawling my study. ...',cid)
			npcHandler:say('Drilling hole after hole only to get stuck in another hard, unbreakable sediment again and again, I was about to quit this pointless enterprise. ...',cid)
			npcHandler:say('However, the very last day I lingered on that island, I finally fell into a large hollow right under the beach. My drill was shattered and the machine was not mobile anymore. ...',cid)
			npcHandler:say('I am well aware that this may sound laughable now - at this part all of my colleagues burst into laughter anyway - but suddenly there were stairs. Incredibly large stairs that led to the underworld. A world deep under the sea - can you believe this?',cid)
			talk_state = 1
		else
			npcHandler:say('You\'re not allowed',cid)
			talk_state = 0
		end
	elseif msgcontains(msg,'yes') and talk_state == 1 then
			npcHandler:say('You do? Well, the end of this story was that I had to leave the place. ...',cid)
			npcHandler:say('I couldn\'t explore what lies below the stairs as their was an unpredictable stream. Diving into these waters would have been an uncontrollable risk, even with the means to survive without any air. ...',cid)
			npcHandler:say('So I used the portable teleporting device I installed into my machine in case of an emergency and went home. I could only take the most important research documents with me and had to leave most of my equipment in the cave. ...',cid)
			npcHandler:say('Of course I also left my final notes with the coordinates there. And for the life of me I cannot remember where I dug that stupid hole. ...',cid)
			npcHandler:say('When I arrived at home I immediately started looking for a way to manoeuvre in these chaotic conditions once I rediscovered the lost entrance. I never remembered it, but it seems you found it as you indeed have my original notes. ...',cid)
			npcHandler:say('Oh and just in case you want to complete what I have started - feel free to do so. Up to it?',cid)
			talk_state = 2
	elseif msgcontains(msg,'yes') and talk_state == 2 then
			npcHandler:say('Well, if you really want to delve into this - I could use some help. So you have found my machine on that island? And you found the notes with the coordinates? Then you can find the entrance! ...',cid)
			npcHandler:say('Just look for a large staircase with sprawling steps. There is an unpassable stream there that will prevent you from venturing further on. But fear not, you can indeed travel down there - with these small enhancements I created. ...',cid)
			npcHandler:say('At first, take this gold for the passage by ship and return to the Gray Island from where I started my expedition many years ago. From there you should find a way to reach the Gray Beach of Quirefang as no ordinary ship can land there. ...',cid)
			npcHandler:say('I will put this under your footgear. Here you go. And this in your nose. There. And there will be no further problems for you down there. Except- ah, well you\'ll find out yourself soon enough, won\'t you?',cid)
			talk_state = 3
    elseif msgcontains(msg,'yes') and talk_state == 3 then
			npcHandler:say('Then off you go! I\'m sorry that I cannot offer you any further help but I\'m sure you will find support along your way. And - be careful. The sea can appear pitch black down there.',cid)
    else
		talk_state = 0
    end
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

This works.

The problem was you have the script check for "yes" three times.
By default, it reaches the first one only. Then it checks for that talk_state, which fails, returning you back to the top.
 
Thanks Evan...

- - - Updated - - -

Hey Evan, can you solve one doubt me..after player complete one mission and he's back to talk npc and player say..
First Mission:
Jogador: hi
Spectulus: What... why... how?! Shock! What are you doing here?! Speak! Just tell me if you desire to rob me or just want my attention - if so, it is yours entirely now.
Jogador: machine
Second Mission:
Jogador: hi
Spectulus: Ah hello again Jogador! I still have one or two other missions for you. There are also some tasks someone needs to attend to.
Jogador: book
Spectulus: You found what? Well, you'll have to hand it over to me to help you with this, will you?

I need put this if msgcontains(msg,hi) and player have storage x he say
Spectulus: What... why... how?! Shock! What are you doing here?! Speak! Just tell me if you desire to rob me or just want my attention - if so, it is yours entirely now.
if player have storage y npc say:
Spectulus: Ah hello again Jogador! I still have one or two other missions for you. There are also some tasks someone needs to attend to.
Is correct make this?
 
Something like this? Don't forget to change X and Y

LUA:
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 talkState = {}
 

function greetCallback(cid)
	if getPlayerStorageValue(cid,X) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "What... why... how?! Shock! What are you doing here?! Speak! Just tell me if you desire to rob me or just want my attention - if so, it is yours entirely now.")
	elseif getPlayerStorageValue(cid,X) == 1 then
		npcHandler:setMessage(MESSAGE_GREET, "Ah hello again Jogador! I still have one or two other missions for you. There are also some tasks someone needs to attend to.")
	end
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
	if msgcontains(msg,'book') and talk_state == 0 then
		npcHandler:say('Test passed',cid)
	end
	
	if msgcontains(msg,'machine') and talk_state == 0 then
		if getPlayerStorageValue(cid,62338) == 1 then
			npcHandler:say('Ah, the machine you found at that island. Well, I built this thing to venture far beneath the very soil we walk on. I suspected something there. Something deep down below. Something evil. Even more so than the dreaded bugs which are crawling my study. ...',cid)
			npcHandler:say('Drilling hole after hole only to get stuck in another hard, unbreakable sediment again and again, I was about to quit this pointless enterprise. ...',cid)
			npcHandler:say('However, the very last day I lingered on that island, I finally fell into a large hollow right under the beach. My drill was shattered and the machine was not mobile anymore. ...',cid)
			npcHandler:say('I am well aware that this may sound laughable now - at this part all of my colleagues burst into laughter anyway - but suddenly there were stairs. Incredibly large stairs that led to the underworld. A world deep under the sea - can you believe this?',cid)
			talk_state = 1
		else
			npcHandler:say('You\'re not allowed',cid)
			talk_state = 0
		end
	elseif msgcontains(msg,'yes') and talk_state == 1 then
			npcHandler:say('You do? Well, the end of this story was that I had to leave the place. ...',cid)
			npcHandler:say('I couldn\'t explore what lies below the stairs as their was an unpredictable stream. Diving into these waters would have been an uncontrollable risk, even with the means to survive without any air. ...',cid)
			npcHandler:say('So I used the portable teleporting device I installed into my machine in case of an emergency and went home. I could only take the most important research documents with me and had to leave most of my equipment in the cave. ...',cid)
			npcHandler:say('Of course I also left my final notes with the coordinates there. And for the life of me I cannot remember where I dug that stupid hole. ...',cid)
			npcHandler:say('When I arrived at home I immediately started looking for a way to manoeuvre in these chaotic conditions once I rediscovered the lost entrance. I never remembered it, but it seems you found it as you indeed have my original notes. ...',cid)
			npcHandler:say('Oh and just in case you want to complete what I have started - feel free to do so. Up to it?',cid)
			talk_state = 2
	elseif msgcontains(msg,'yes') and talk_state == 2 then
			npcHandler:say('Well, if you really want to delve into this - I could use some help. So you have found my machine on that island? And you found the notes with the coordinates? Then you can find the entrance! ...',cid)
			npcHandler:say('Just look for a large staircase with sprawling steps. There is an unpassable stream there that will prevent you from venturing further on. But fear not, you can indeed travel down there - with these small enhancements I created. ...',cid)
			npcHandler:say('At first, take this gold for the passage by ship and return to the Gray Island from where I started my expedition many years ago. From there you should find a way to reach the Gray Beach of Quirefang as no ordinary ship can land there. ...',cid)
			npcHandler:say('I will put this under your footgear. Here you go. And this in your nose. There. And there will be no further problems for you down there. Except- ah, well you\'ll find out yourself soon enough, won\'t you?',cid)
			talk_state = 3
    elseif msgcontains(msg,'yes') and talk_state == 3 then
			npcHandler:say('Then off you go! I\'m sorry that I cannot offer you any further help but I\'m sure you will find support along your way. And - be careful. The sea can appear pitch black down there.',cid)
    else
		talk_state = 0
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top