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

Looking for an npc

Elaney

Member
Joined
Jan 1, 2009
Messages
1,561
Reaction score
12
Location
Sweden
That you can ask several things and he answer several sentences (i can edit that part)

But the main object i want the npc to do is IF you ask Quest he will say do you want to join the army?

and If say yes then you join the "army" by getting etc storage value 19000.

Anyone can help with that?
 
LUA:
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

local function msgcontains(message, keyword)
	local a, b = string.find(string.lower(message), string.lower(keyword))
	if a == nil or b == nil then
		return false
	end
	return true
end

function greetCallback(cid)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	talkState[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

-- Keyword responses [Start]
	if msgcontains(msg, 'job') then
		npcHandler:say("I am a ..", cid)
	elseif msgcontains(msg, 'name')
		npcHandler:say("My name is ..", cid)
	elseif msgcontains(msg, 'help')
		npcHandler:say("I can give you some basic tips.", cid)
-- Keyword responses [End]	

	elseif (msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) and talkState[talkUser] == 0 then
		if getPlayerStorageValue(cid, 19000) <= 0 then
			npcHandler:say("Do you want to join the army?", cid)
			talkState[talkUser] = 1
		else
			npcHandler:say("You have already joined the army!", cid)
			talkState[talkUser] = 0
		end
	elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
		npcHandler:say("Congratulations |PLAYERNAME|, you have just joined the army!", cid)
		setPlayerStorageValue(cid, 19000, 1)
		talkState[talkUser] = 0
	elseif talkState[talkUser] == 1 then
		npcHandler:say("Then not.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end

npcHandler:setMessage(MESSAGE_GREET, 'Hello there, |PLAYERNAME|. If you\'re interested in joining the army, ask me about a quest.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Gone...')
npcHandler:setMessage(MESSAGE_FAREWELL, 'LONG LIVE THE KING!')

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Note that I've used creatureSayCallback instead of nodes
 
Last edited:
Back
Top