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

NPC problem while doing quest

Darqneez

ShaC-Ohhhh
Joined
Dec 30, 2009
Messages
72
Reaction score
2
Location
Poland/Wroclaw
Hi, I did today a simple script for npc. It should work so: Player says "quest", NPC asks Player, if he wants to do quest. Then let's say Player says "yes", but later when Player says "quest" he didnt get the message 'Did you bring me 10 orc teeth?', but the first one ('Do you want to do a quest for me?'). I dont really know where is bug, I can only guess it, and it can be that lines which contains this
Lua:
talkState[talkUser] = [number]
something's wrong there, I'll rep someone who tells me where did I make mistake, here's whole code:
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)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(not npcHandler:isFocused(cid)) then
		return false
	end

if getPlayerStorageValue(cid,59990) == -1 then
	if msgcontains(msg, 'quest') then
		selfSay('Do you want to do a quest for me?', cid)
		talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
	    selfSay('Very good, we, green dragons, hate orcs. They understimate our power, bring me 10 orc teeth and I will reward You.', cid)
	    talkState[talkUser] = 2
    elseif msgcontains(msg, 'no') then
        selfSay('Then go away!', cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, 'quest') and talkState[talkUser] == 2 then
		selfSay('Did you bring me 10 orc teeth?', cid)
		talkState[talkUser] = 3
	elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
	        if getPlayerItemCount(cid, 11109) >= 10 then
	        doPlayerRemoveItem(cid, 11109, 10)
	        doPlayerAddItem(cid, 2152, 50)
	        setPlayerStorageValue(cid, 59990, 1)
	           if getPlayerStorageValue(cid,59999) == -1 then
	           setPlayerStorageValue(cid, 59999, 1)
	           else
	           setPlayerStorageValue(cid,59999,(getPlayerStorageValue(cid,59999))+1)
	           end
		    selfSay('Great job, Here you are, 5000 gold pieces. I will inform Eulopem about your loyalty towards green dragons.', cid)
		    talkState[talkUser] = 0
		    else
		    selfSay('Don\'t lie to me!', cid)
		    talkState[talkUser] = 2
		    end
    end
else
selfSay('I don\'t have more quests for You.', cid)
end
return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Edit: #2

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 Topic = {}
 
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
 
	if getPlayerStorageValue(cid,59990) == -1 then
		if msgcontains(msg, 'quest') then
			npcHandler:say('Do you want to do a quest for me?', cid)
			Topic[cid] = 1
		elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
			npcHandler:say('Very good, we, green dragons, hate orcs. They understimate our power, bring me 10 orc teeth and I will reward You.', cid)
			Topic[cid] = 2
		elseif msgcontains(msg, 'no') then
			npcHandler:say('Then go away!', cid)
			Topic[cid] = 0
		end
	else
		npcHandler:say('Sorry, you did not complete the first task.', cid)
		Topic[cid] = 0
	end
	
	if msgcontains(msg, 'quest') and Topic[cid] == 2 then
		npcHandler:say('Did you bring me 10 orc teeth?', cid)
		Topic[cid] = 3
	elseif msgcontains(msg, 'yes') and Topic[cid] == 3 then
		if getPlayerItemCount(cid, 11109) >= 10 then
			if doPlayerRemoveItem(cid, 11109, 10) then
				doPlayerAddItem(cid, 2152, 50)
				setPlayerStorageValue(cid, 59990, 1)	
				if getPlayerStorageValue(cid,59999) == -1 then
					setPlayerStorageValue(cid, 59999, 1)
				else
					setPlayerStorageValue(cid, 59999, 2)
				end
				
				npcHandler:say('Great job, Here you are, 5000 gold pieces. I will inform Eulopem about your loyalty towards green dragons.', cid)
				Topic[cid] = 0
			else
				npcHandler:say('Don\'t lie to me!', cid)
				Topic[cid] = 2
			end
		end
	end
	
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
still same problem, here's my and npc talk:
Code:
22:10 GOD Darqneez [120]: hi
22:10 Rumoreth: Welcome to my cave, traveller!
22:10 GOD Darqneez [120]: quest
22:10 Rumoreth: Do you want to do a quest for me?
22:10 GOD Darqneez [120]: yes
22:10 Rumoreth: Very good, we, green dragons, hate orcs. They understimate our power, bring me 10 orc teeth and I will reward You.
22:10 GOD Darqneez [120]: bye
22:10 Rumoreth: Good bye, GOD Darqneez!
22:10 GOD Darqneez [120]: hi
22:10 Rumoreth: Welcome to my cave, traveller!
22:10 GOD Darqneez [120]: quest
22:10 Rumoreth: Do you want to do a quest for me?

Ps. You made little mistake in line 33 (didnt place 'then' at the end)
Please help me :\
 
Yes, it still doesnt work. I have an idea, but I am beginner, it's just a guess. Maybe we should reset
Code:
Topic[cid]
value before setting it to another? for example if
Code:
Topic[cid] = 2
we have to make it 0 than do
Code:
Topic[cid] = 3
. What do you think?
 
just check for that in the first msg
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)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
    if(not npcHandler:isFocused(cid)) then
		return false
	end
 
if getPlayerStorageValue(cid,59990) == -1 then
	if msgcontains(msg, 'quest') and talkState[talkUser] ~= 2 then
		selfSay('Do you want to do a quest for me?', cid)
		talkState[talkUser] = 1
    elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
	    selfSay('Very good, we, green dragons, hate orcs. They understimate our power, bring me 10 orc teeth and I will reward You.', cid)
	    talkState[talkUser] = 2
    elseif msgcontains(msg, 'no') then
        selfSay('Then go away!', cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, 'quest') and talkState[talkUser] == 2 then
		selfSay('Did you bring me 10 orc teeth?', cid)
		talkState[talkUser] = 3
	elseif msgcontains(msg, 'yes') and talkState[talkUser] == 3 then
	        if getPlayerItemCount(cid, 11109) >= 10 then
	        doPlayerRemoveItem(cid, 11109, 10)
	        doPlayerAddItem(cid, 2152, 50)
	        setPlayerStorageValue(cid, 59990, 1)
	           if getPlayerStorageValue(cid,59999) == -1 then
	           setPlayerStorageValue(cid, 59999, 1)
	           else
	           setPlayerStorageValue(cid,59999,(getPlayerStorageValue(cid,59999))+1)
	           end
		    selfSay('Great job, Here you are, 5000 gold pieces. I will inform Eulopem about your loyalty towards green dragons.', cid)
		    talkState[talkUser] = 0
		    else
		    selfSay('Don\'t lie to me!', cid)
		    talkState[talkUser] = 2
		    end
    end
else
selfSay('I don\'t have more quests for You.', cid)
end
return TRUE
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top