• 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!

Necroman

Godely

Member
Joined
Aug 19, 2007
Messages
233
Reaction score
16
Code:
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



--function
local perguntas = {'Ok, so answer me: What the name of the mountain that we are? Derzi Mountain, Deg\'Hills, Den Hills or Dex\'Hills.', 'Ok. What the name of the dungeon on west of Dargor. West Drafia, West Dradia, West Drefia, Old West.', 'The last question is: What the name of the biggest place of wyverns? Wyverns Mountain, Wyverns Camp, Wyverns Fortress, Wyverns Castle.'}

function confirmAction(cid, message, keywords, parameters)
	if(cid ~= npcHandler.focus) then
        return false
    end
	
	action = parameters.id
	if action == 1 then
		if doPlayerRemoveMoney(cid, 1000) == TRUE then
			selfSay('Let\'s go to the first question, are you ready?')
			return true
		else
			selfSay("You don\'t have any money!")
			return false
		end
	elseif action == 2 then
		questao = parameters.questao
		selfSay(perguntas[questao])
		return true
	elseif action == 3 then
		questao = parameters.questao
		if questao == 3 then
			selfSay('Right! Ready for the last question?')
		else
			selfSay('Correctly! Ready for the next question?')
		end
		selfSay('Chega aqui?')
		return true
	elseif action == 4 then
		selfSay('Correctly! Now, open the wooden coffin on your left.')
		setPlayerStorageValue(cid,2113,1)
		return true
	end
	
	return false
end

local node = keywordHandler:addKeyword({'key'}, StdModule.say, {npcHandler = npcHandler, text = 'Do you want the permission to take the key? If you answer my questions correctly, you will can open the wooden coffin. But beware with your money.'}, true)
local node2 = node:addChildKeyword({'yes'}, confirmAction, {id = 1})
node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Ok then!'}, true)

local node3 = node2:addChildKeyword({'yes'}, confirmAction, {id = 2, questao = 1})
node2:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Ok then!'}, true)

node3:addChildKeyword({'Derzi Mountain'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
local node4 = node3:addChildKeyword({'Deg\'Hills'}, confirmAction, {id = 3, questao = 2})
node3:addChildKeyword({"Dex'Hills"}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
node3:addChildKeyword({'Den Hills'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)

node4:addChildKeyword({'West Drafia'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
local node5 = node4:addChildKeyword({'West Drefia'}, confirmAction, {id = 3, questao = 3})
node4:addChildKeyword({'West Dradia'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
node4:addChildKeyword({'Old West'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)

node5:addChildKeyword({'West Drafia'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
node5:addChildKeyword({'West Drefia'}, confirmAction, {id = 4})
node5:addChildKeyword({'West Dradia'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)
node5:addChildKeyword({'Old West'}, StdModule.say, {npcHandler = npcHandler, text = 'Wrong!'}, true)

npcHandler:addModule(FocusModule:new())


This script is not totally working. I hope someone helps me to find the bug, 'cause after that I'm gonna post on the board.

PS.: this script is about a NPC that asks you 3 questions. If you get the 3 right, he gives you the permission to get a key on a chest (by adding a storage value)

See ya
 
Try this code instead, should work. Just change the answers to the correct ones.

Code:
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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
        
function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

local questdone = getPlayerStorageValue(cid, 2113)


    if msgcontains(msg, 'key') then
        selfSay('Do you want the permission to take the key? If you answer my questions correctly, you will can open the wooden coffin. But beware with your money.')
        talkNode = 1
    end

    if msgcontains(msg,'questions') then
        if talkNode == 1 then
            if questdone < 1 then
                if doPlayerRemoveMoney(cid, 1000) == TRUE then
                    selfSay('Let\'s go to the first question, are you ready?')
                    talkNode = 2
                else
                    selfSay('You don\'t have enough money.')
                end
            end
        end
    end
    
    if msgcontains(msg, 'yes') then
        if talkNode == 2 then
            selfSay('Ok, so answer me: What the name of the mountain that we are? Derzi Mountain, Deg\'Hills, Den Hills or Dex\'Hills.')
            talkNode = 3
        elseif talkNode == 4 then
            selfSay('Ok. What the name of the dungeon on west of Dargor. West Drafia, West Dradia, West Drefia, Old West.')
            talkNode = 5
        elseif talkNode == 6 then
            selfSay('The last question is: What the name of the biggest place of wyverns? Wyverns Mountain, Wyverns Camp, Wyverns Fortress, Wyverns Castle.')
            talkNode = 7
        end
    end
    
    if talkNode == 3 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Ready for the next question?')
            talkNode = 4
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    elseif talkNode == 5 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Ready for the last question?')
            talkNode = 6
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    elseif talkNode == 7 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Now, open the wooden coffin on your left.')
            setPlayerStorageValue(cid, 2113, 1)
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    end
    return TRUE
end
npcHandler:addModule(FocusModule:new())

P.S
Don't make it harder than it has to be;)
D.S
 
I'll try to fix it tomorrow, right now I'm a little stressed out with my own project. So I'll fix it for ya tomorrow.
 
if msgcontains(msg, 'key') then
selfSay('Do you want the permission to take the key? If you answer my questions correctly, you will can open the wooden coffin. But beware with your money.')
talkNode = 1
end
The player don't need to answer 'yes' here?

if msgcontains(msg,'questions') then
Shouldn't be elseif?
I got a little confuse reading the script :S
 
cherife, this script works like this:

If you say "key", he will ask you this question. You just have to say yes after that.
 
Tested, this one works.
Code:
local talk_state = 0
local queststorage = getPlayerStorageValue(cid, 45000)

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

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    if(npcHandler.focus ~= cid) then
        return false
    end

local questdone = getPlayerStorageValue(cid, 2113)


    if msgcontains(msg,'key') then
        if questdone < 1 then
            selfSay('Do you want the permission to take the key? If you answer my questions correctly, you will can open the wooden coffin. But beware with your money.')
            talkNode = 1
        end
    end

    if msgcontains(msg,'questions') then
        if talkNode == 1 then
            if questdone < 1 then
                if doPlayerRemoveMoney(cid, 1000) == TRUE then
                    selfSay('Let\'s go to the first question, are you ready?')
                    talkNode = 2
                else
                    selfSay('You don\'t have enough money.')
                end
            end
        end
    end
    
    if msgcontains(msg, 'yes') then
        if talkNode == 2 then
            selfSay('Ok, so answer me: What the name of the mountain that we are? Derzi Mountain, Deg\'Hills, Den Hills or Dex\'Hills.')
            talkNode = 3
        elseif talkNode == 4 then
            selfSay('Ok. What the name of the dungeon on west of Dargor. West Drafia, West Dradia, West Drefia, Old West.')
            talkNode = 5
        elseif talkNode == 6 then
            selfSay('The last question is: What the name of the biggest place of wyverns? Wyverns Mountain, Wyverns Camp, Wyverns Fortress, Wyverns Castle.')
            talkNode = 7
        end  
    end
    if talkNode == 3 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Ready for the next question?')
            talkNode = 4
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    elseif talkNode == 5 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Ready for the last question?')
            talkNode = 6
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    elseif talkNode == 7 then
        if msgcontains(msg, 'RIGHT ANSWER') then --answer 1
            selfSay('Correctly! Now, open the wooden coffin on your left.')
            setPlayerStorageValue(cid, 2113, 1)
        elseif msgcontains(msg, 'WRONG ANSWER1') then --answer 2
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER2') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        elseif msgcontains(msg, 'WRONG ANSWER3') then
            selfSay('You were wrong... Too bad')
            talkNode = 0
        end
    end
    return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
bugzc6.png


I'm getting this bug when I open it, so the NPC doesn't answer to "yes" when you ask him about "key".

Edit: Forgot about that, already fixed.

By the way, thank you so much for the help ^^
You can delete the second line of the script
Code:
local queststorage = getPlayerStorageValue(cid, 45000)
 
Last edited:
Back
Top