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

DanneZ

Web-Scripting-Design-Host
Joined
Jan 16, 2010
Messages
84
Reaction score
2
Location
Sweden
I used this npc script made by Cykotitan, but i want it like if u answer all questions correctly you get an storage.

Script by Cykotitan.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
local conv = {
	{
		[1] = "What genre are tibia?"

	},
	{
		[1] = "mmorpg"

	}
}
 
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 greetCallback(cid)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	Topic[talkUser] = 0
	return true
end
 
function creatureSayCallback(cid, type, msg)
 
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
	if Topic[talkUser] > 0 then
		if msgcontains(msg, conv[2][Topic[talkUser]]) then
		          local storage = 133341
			npcHandler:say("Congratulations, you have answered correctly!", cid)
			npcHandler:say("Now go to the leader and get your reward!", cid)
			setPlayerStorageValue(cid, storage, 1)
		else
			npcHandler:say("Sorry, but that wasn't the correct answer.", cid)
		end
		Topic[talkUser] = 0
	elseif msgcontains(msg, "question") then
		local random = math.random(#conv[1])
		npcHandler:say(conv[1][random], cid)
		Topic[talkUser] = random
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Thanks for ur time, Yours DanneZ.
 
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
local Topic = {}
local t = {
	[1] = {"What genre is Tibia?", "mmorpg"},
}
 
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 greetCallback(cid)
	Topic[cid] = nil
	return true
end
 
function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif Topic[cid] then
		if msgcontains(msg, t[Topic[cid]][2]) then
			npcHandler:say("Congratulations, you have answered correctly!", cid)
			if Topic[cid] == #t then
				npcHandler:say("Now go to the leader and get your reward!", cid)
				setPlayerStorageValue(cid, 133341, 1)
				Topic[cid] = nil
			else
				npcHandler:say(t[Topic[cid] + 1][1], cid)
				Topic[cid] = Topic[cid] + 1
			end
		else
			npcHandler:say("Sorry, but that wasn't the correct answer.", cid)
			Topic[cid] = nil
		end
	elseif msgcontains(msg, 'question') then
		npcHandler:say(t[1][1], cid)
		Topic[cid] = 1
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thanks Cykotitan but i got this error when i used it.
[23/03/2011 14:41:34] [Error - Npc interface]
[23/03/2011 14:41:34] (Unknown script file)
[23/03/2011 14:41:34] Description:
[23/03/2011 14:41:34] attempt to call a nil value
[23/03/2011 14:41:34] stack traceback:
[23/03/2011 14:41:35] [Error - LuaScriptInterface::loadFile] data/npc/scripts/question.lua:48: ')' expected near '<eof>'
[23/03/2011 14:41:35] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/question.lua
[23/03/2011 14:41:35] data/npc/scripts/question.lua:48: ')' expected near '<eof>'
 
Back
Top