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

Simple Talking Npc

  • Thread starter Thread starter Deleted member 49793
  • Start date Start date
D

Deleted member 49793

Guest
Hey so im looking for a super simple script (I want it to be easy to modify too)

Basicly just an npc who you say hi and he says hey wondering about something about the server? say any of these words for more info >>> then have like a few key words
When you say those key words he will say a short bit about them. Making 2-3 examples would be awesome then i can add/modify more :D


Thank you!
~Moist
 
You can use this:
LUA:
local loop = {
[1] = {"keyword"},
[2] = {"keyword"},
[3] = {"keyword"}
}
for i = 1,#loop do
if msgcontains(msg, loop[i][1]) then
--execute
end
end

It is an easy example.
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local keywords = {
[B]	['[COLOR="blue"]foo[/COLOR]'] = "[COLOR="blue"]Response to foo.[/COLOR]",
	['[COLOR="green"]bar[/COLOR]'] = "[COLOR="green"]Response to bar.[/COLOR]",[/B]
}

npcHandler:setMessage(MESSAGE_GREET, '[B][COLOR="red"]Hey, |PLAYERNAME|! Wondering about something about the server?[/COLOR][/B]')

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

	for k, v in pairs(keywords) do
		if msgcontains(msg, k) then
			npcHandler:say(v, cid)
			break
		end
	end

	return true
end

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