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

need help on NPC

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hey,

I need some help on this npc script.
the begin works but when my topic[cid] == 1 then it doesn't do anything else.

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 creatureSayCallback(cid, type, msg)
local Topic = {}
	if msgcontains(msg,'help') then
		local v = getPlayerStorageValue(cid,100)
			if v < 1 then
				npcHandler:say('Finally someone who is able to help.. you do gain bad reputation though, are you sure?',cid)
				Topic[cid] = 1
			elseif v == 1 then
				npcHandler:say('Have you got the key yet?',cid)
				Topic[cid] = 3
			elseif v == 2 then
				npcHandler:say('I don\'t need any moe help..',cid)
				Topic[cid] = 0
				npcHandler:releaseFocuse(cid)
			end
	elseif Topic[cid] == 1 then
		if msgcontains(msg,'yes') then
			npcHandler:say('Ok, good.. could you get me the key from the barrel outside the jail?',cid)
			Topic[cid] = 2
		else
			npcHandler:say('Oh, I see... goodbye..',cid)
			Topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif Topic[cid] == 2 then
		if msgcontains(msg,'yes') then
			npcHandler:say('Ok.. talk to me when you get the key.',cid)
			Topic[cid] = 0
			setPlayerStorageValue(cid,100,1)
			npcHandler:releaseFocus(cid)
		else
			npcHandler:say('Oh, I see... goodbye then..',cid)
			Topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif Topic[cid] == 3 then
		if msgcontains(msg,'yes') then
			if doRemoveItem(cid,2087,1) then
				npcHandler:say('good god.. thank you! once the time is right, I\'ll leave here!',cid)
				doPlayerAddExperience(cid,500)
				doPlayerSendTextMessage(cid,19,'[Quest] You gained 500 experience points.')
				Topic[cid] = 0
				setPlayerStorageValue(cid,100,2)
			else
				npcHandler:say('You don\'t have it yet..., go get it!',cid)
				Topic[cid] = 0
				npcHandler:releaseFocuse(cid)
			end
		else
			npcHandler:say('Oh, I see... goodbye then..',cid)
			Topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	return true
	end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Argh, goodbye..")
npcHandler:setMessage(MESSAGE_FAREWELL, "Goodbye..")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Full fix here.
topic = {} needs to be outside of npc function.
Also you once had doRemoveItem instead of doPlayerRemoveItem

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 msgcontains(msg,'help') then
		local v = getPlayerStorageValue(cid,100)
			if v < 1 then
				npcHandler:say('Finally someone who is able to help.. you do gain bad reputation though, are you sure?',cid)
				topic[cid] = 1
			elseif v == 1 then
				npcHandler:say('Have you got the key yet?',cid)
				topic[cid] = 3
			elseif v == 2 then
				npcHandler:say('I don\'t need any moe help..',cid)
				topic[cid] = 0
				npcHandler:releaseFocuse(cid)
			end
	elseif topic[cid] == 1 then
		if msgcontains(msg,'yes') then
			npcHandler:say('Ok, good.. could you get me the key from the barrel outside the jail?',cid)
			topic[cid] = 2
		else
			npcHandler:say('Oh, I see... goodbye..',cid)
			topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif topic[cid] == 2 then
		if msgcontains(msg,'yes') then
			npcHandler:say('Ok.. talk to me when you get the key.',cid)
			topic[cid] = 0
			setPlayerStorageValue(cid,100,1)
			npcHandler:releaseFocus(cid)
		else
			npcHandler:say('Oh, I see... goodbye then..',cid)
			topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif topic[cid] == 3 then
		if msgcontains(msg,'yes') then
			if doPlayerRemoveItem(cid,2087,1) then
				npcHandler:say('good god.. thank you! once the time is right, I\'ll leave here!',cid)
				doPlayerAddExperience(cid,500)
				doPlayerSendTextMessage(cid,19,'[Quest] You gained 500 experience points.')
				doSendAnimatedText(getPlayerPosition(cid),500,COLOR_WHITE)
				topic[cid] = 0
				setPlayerStorageValue(cid,100,2)
			else
				npcHandler:say('You don\'t have it yet..., go get it!',cid)
				topic[cid] = 0
				npcHandler:releaseFocus(cid)
			end
		else
			npcHandler:say('Oh, I see... goodbye then..',cid)
			topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	return true
	end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Argh, goodbye..")
npcHandler:setMessage(MESSAGE_FAREWELL, "Goodbye..")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top