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

Conversation NPC

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
I want a 'NPC' conversation, he asks the questions and if I answer correctly I win a prize.

I wish it was easy to configure it.
An example of how I would:

Code:
{
 {
  --questions(NPC)--
   [1] = "Do you like food?",
    [2] = "Can you swim?"
     },
     {
    --responses(PLAYER)--
   [1] = "yes i like food.",
  [2] = "unfortunately i can not swim."
 }
}

If have any simple way to configure, I thank ... and much!
random questions, please!
I need urgent mind this 'NPC'.

Sorry for my English!
 
Basic version..
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local conv = {
	{
		[1] = "Do you like food?",
		[2] = "Can you swim?"
	},
	{
		[1] = "yes",
		[2] = "no"
	}
}

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
			npcHandler:say("Congratulations, you have answered correctly!", cid)
		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())
 
Back
Top