• 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 greeting in lua file

Xyzyk

RudziutOTS Maker
Joined
Jun 14, 2008
Messages
39
Reaction score
0
Location
Poland
I need know how make that npc reacts for hi etc. which is put in lua file. This is part of my script which doesn't work
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
----------------------------------------------- Greeting ------------------------------------------------
	if (msgcontains(msg, 'hi')) then
		if (getPlayerSex(cid) == 0) then
			npcHandler:say('Hello beautyful lady, welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass to throne room of {Pumin}, the Lord of Despair?', cid, true)
		else
			npcHandler:say('Hello sir, welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass to throne room of {Pumin}, the Lord of Despair?', cid, true)
		end
     npcHandler:addFocus(cid)

[I][B]My code[/B][/I]
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I have in xml file nothing about greeting. NPC reacts with default greeting (TFS 0.3.6). Could somebody repair it?
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}

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)
	npcHandler:setMessage(MESSAGE_GREET, 'Hello ' .. (getPlayerSex(cid) == 0 and 'beautyful lady' or 'sir') .. ', welcome to the atrium of Pumin\'s Domain. We require some information from you before we can let you pass to throne room of {Pumin}, the Lord of Despair?')
	talkState[cid] = 0
	return true
end
		
function creatureSayCallback(cid, type, msg)
	local talkUser = cid

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

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top