• 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 - focus if XX storage value and XX keyword

d4rkbl0od

Member
Joined
Mar 21, 2008
Messages
160
Reaction score
7
Hello people,
I'm kinda noob in npc scripting and I'm having big problems with this npc's ( Sniffler, Queen Eloise). ( I'm doing Real Map npcs)


An example of this is the npc Sniffler , that only focus to you if have XX storage and talk XX keyword ( the problem I'm having now is that NPC keeps focusing with hi or hello, and not with the correct words like, Sniffler or Hail the queen.
Like queen eloise , if a player say hi she would say : If you want to talk with me , adress me correctly. ( focus 0)
and if player say : hail the queen of sometin like that, she focuses.

Hope you guys can help me with this big trouble,

Thanks,
peace.:peace:
 
Here's a sample Queen Eloise script. You should get the idea.
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

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 (msgcontains(msg, 'hail') or msgcontains(msg, 'hello') or msgcontains(msg, 'salutations')) and msgcontains(msg, 'queen') and (not npcHandler:isFocused(cid)) then
		npcHandler:say('I greet thee, my loyal subject.', cid, TRUE)
		npcHandler:addFocus(cid)
		Topic[cid] = 0
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Farewell, '..getCreatureName(cid)..'!', cid, TRUE)
		Topic[cid] = nil
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'promot') then
		npcHandler:say('Do you want to be promoted in your vocation for 20000 gold?', cid)
		Topic[cid] = 1
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		if getPlayerPromotionLevel(cid) >= 1 then
			npcHandler:say('You are already promoted.', cid)
		elseif getPlayerLevel(cid) < 20 then
			npcHandler:say('You need to be at least level 20 in order to be promoted.', cid)
		elseif getPlayerMoney(cid) < 20000 then
			npcHandler:say('You do not have enough money.', cid)
		elseif isPremium(cid) then
			npcHandler:say('Congratulations! You are now promoted. Visit the sage Eremo for new spells.', cid)
			setPlayerPromotionLevel(cid, 1)
			doPlayerRemoveMoney(cid, 20000)
		else
			npcHandler:say('You need a premium account in order to promote.', cid)
		end
		Topic[cid] = 0
	elseif Topic[cid] == 1 then
		npcHandler:say('Ok, whatever.', cid)
		Topic[cid] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
 
EDIIT-----
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

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 (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'salutations')) and (getPlayerStorageValue(cid, 11015) < 1) and (not npcHandler:isFocused(cid)) then
		npcHandler:say('Welcome on board, ' .. getCreatureName(cid) .. '.', cid, TRUE)
		npcHandler:addFocus(cid)
		Topic[cid] = 0
		
		elseif (msgcontains(msg, 'hi') or msgcontains(msg, 'hello') or msgcontains(msg, 'salutations')) and (getPlayerStorageValue(cid, 11015) == 1) and (not npcHandler:isFocused(cid)) then
		npcHandler:say('By the gods! You must be that intruder the good brothers were talking about! Begone!', cid, TRUE)		
		Topic[cid] = 0
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, 'bye') or msgcontains(msg, 'farewell') then
		npcHandler:say('Farewell, '..getCreatureName(cid)..'!', cid, TRUE)
		Topic[cid] = nil
		npcHandler:releaseFocus(cid)
	elseif msgcontains(msg, 'tibia') then
		npcHandler:say('Do you want a passage to the mainland for free?', cid)
		Topic[cid] = 1
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		 doTeleportThing(cid, {x=32205, y=31756, y=6}) 
		 doSendMagicEffect({x=32205, y=31756, y=6}, CONST_ME_TELEPORT)
			npcHandler:say('Have a nice trip!', cid)
		           		Topic[cid] = 0 
		           	
	elseif Topic[cid] == 1 then
		npcHandler:say('Ok, whatever.', cid)
		Topic[cid] = 0
	end
	
	return true
end  

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)


whats wrong with this code? :S
whey i say yes, npc says : have a nive trip, but dont teleport the player!
 
Last edited:

Similar threads

  • Question Question
Replies
0
Views
190
Back
Top