• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Change greet word for 1 npc

rudger

Active Member
Joined
Oct 1, 2010
Messages
273
Solutions
1
Reaction score
45
Location
The Netherlands
Instead of saying 'hi', say 'charach' to let the npc focus on you.

Instead of saying 'bye', say 'yyyy' to let the npc unfocus on you.

I don't want to add more greeting keywords to npcsystem.lua (FOCUS_GREETWORDS = {'hi', 'hello'}) or to FOCUS_FAREWELLWORDS
And I didn't find a solution with searching either.
 
Last edited:
This works for me:

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcHandler:setFocusKeywords("[COLOR="#FF0000"]enter your word here[/COLOR]")
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


--Insert functions here


npcHandler:addModule(FocusModule:new())
 
Last edited:
Thank you guys for the help so far, I found your post too, and I'm getting a nil value of SetFocusKeywords.

Do I miss a function in the npc system or is my distro outdated?
 
Oh yeah, here it is:

LUA:
-- This file contains a default npc script based on Jiddo's npc system
-- NPCs that are made only in XML can use this file as their Lua file

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end


function creatureSayCallback(cid, type, msg)
	if(npcHandler.focus ~= cid) then
		return false
	end
	
if msgcontains(msg, "ikem") or msgcontains(msg, "goshak") then
selfSay('Ikem pashak porak, bata, dora. Ba goshak maruk?')
talk_state = 0

elseif msgcontains(msg, "porak") then
selfSay ('Ikem pashak charcha, burka, burka bata, hakhak. Ba goshak maruk?')
talk_state = 0

end
return true
end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

--Do you want to buy a

--dagger
shopModule:addBuyableItem({'charcha'},		2385, 25,		'charcha')


npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Alright, here is everything you need, I just tested it, works perfectly:

In npc/lib/modules.lua, replace this:
Code:
	-- Inits the module and associates handler to it.
	function FocusModule:init(handler)
		self.npcHandler = handler
		for i, word in pairs(FOCUS_GREETWORDS) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = FOCUS_GREETWORDS.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onGreet, {module = self})
		end

		for i, word in pairs(FOCUS_FAREWELLWORDS) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = FOCUS_FAREWELLWORDS.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onFarewell, {module = self})
		end
	end

with this:
Code:
	[COLOR="#FF8C00"]-- Inits the module and associates handler to it.
	function FocusModule:init(handler)
		self.npcHandler = handler
		local focusGreetwords = self.npcHandler:getFocusGreetKeywords() and self.npcHandler:getFocusGreetKeywords() or FOCUS_GREETWORDS
		local focusFarewellwords = self.npcHandler:getFocusFarewellKeywords() and self.npcHandler:getFocusFarewellKeywords() or FOCUS_FAREWELLWORDS

		for i, word in pairs(focusGreetwords ) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = focusGreetwords.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onGreet, {module = self})
		end

		for i, word in pairs(focusFarewellwords) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = focusFarewellwords.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onFarewell, {module = self})
		end
	end[/COLOR]


In npchandler.lua , somewhere by the beginning of the file, find this:
Code:
 focusKeywords = nil,
and replace with:
Code:
[COLOR="#FF8C00"]focusGreetKeywords = nil,
focusFarewellKeywords = nil, [/COLOR]

also, find this:
Code:
	function NpcHandler:getFocusKeywords()
			return self.focusGreetKeywords
	end
	function NpcHandler:setFocusKeywords(...)
			self.focusKeywords = arg
	end
and replace with:
Code:
	[COLOR="#FF8C00"]function NpcHandler:getFocusGreetKeywords()
			return self.focusGreetKeywords
	end
	function NpcHandler:setFocusGreetKeywords(...)
		 self.focusGreetKeywords = arg
		 
	end
	function NpcHandler:getFocusFarewellKeywords()
			return self.focusFarewellKeywords
	end
	function NpcHandler:setFocusFarewellKeywords(...)
		 self.focusFarewellKeywords = arg
		 
	end[/COLOR]

Now, the npc's lua file should look this:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
npcHandler:setFocusGreetKeywords("[COLOR="#FF0000"]enter greeting word here[/COLOR]") -- you can add multiple if you wish, same for below
npcHandler:setFocusFarewellKeywords("[COLOR="#FF0000"]enter farewell word here[/COLOR]")
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

-- Functions here

npcHandler:addModule(FocusModule:new())

Tell me if there's any errors.

All credits related to this change go to Tarjei.
 
Back
Top