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

[Request] Quest NPC

Ecstacy

Mothafuckaaa
Joined
Dec 26, 2008
Messages
3,836
Reaction score
108
Location
The Netherlands
Hello,

I'd like to request a simple NPC script which will check values, storageValue, levels, etc..
I don't really have any experience regarding NPC scripting, so that's why I'm requesting this.

Also, how would I make it add an entry in the 'quest log'?

Thanks in advance,
unknown666
 
Just make every text 'example' or something, I'm sure I can edit it :)

I just need a script where I can code LUA so it does whatever I want, and I need to know how to add something to the quest log.

####
I can use a NPC which will give you items inexchange for another item.

Like 10 fur's == 1 rope.
 
Last edited:
Hmm,made a script but my script didn't work.
Code:
[30/05/2010 21:09:36] [Error - Npc interface] 
[30/05/2010 21:09:36] data/npc/scripts/quests/jashriel.lua:onCreatureSay
[30/05/2010 21:09:36] Description: 
[30/05/2010 21:09:36] data/npc/scripts/quests/jashriel.lua:15: attempt to index global 'talkState' (a nil value)
[30/05/2010 21:09:36] stack traceback:
[30/05/2010 21:09:36] 	data/npc/scripts/quests/jashriel.lua:15: in function 'callback'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/npchandler.lua:340: in function 'greet'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/npchandler.lua:506: in function 'onGreet'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/modules.lua:222: in function 'callback'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/keywordhandler.lua:40: in function 'processMessage'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/keywordhandler.lua:168: in function 'processNodeMessage'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/keywordhandler.lua:122: in function 'processMessage'
[30/05/2010 21:09:36] 	data/npc/lib/npcsystem/npchandler.lua:387: in function 'onCreatureSay'
[30/05/2010 21:09:36] 	data/npc/scripts/quests/jashriel.lua:6: in function <data/npc/scripts/quests/jashriel.lua:6>

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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

function greetCallback(cid)
	if getPlayerStorageValue(cid,1250) <= 0 then
		npcHandler:setMessage("Welcome traveler, I could use some {'help'}.")
		talkState[talkUser] = 1
	elseif getPlayerStorageValue(cid,1250) == 1 then
		npcHandler:say("Welcome back, do you have the items that I need help with?", cid)
		talkState[talkUser] = 2
	elseif getPlayerStorageValue(cid,1250) == 2 then
		npcHandler:say('Hello again, I don\'t need any more help.',cid)
	end
	return true
end

function creatureSayCallback(cid, type, msg)
	if talkState[talkUser] == 1 then
		npcHandler:say('I need help on collecting 25 blueberries, do you want to help me?',cid)
		talkState[talkUser] = 3
	elseif talkState[talkUser] == 2 then
		npcHandler:say('Have you gotten the blueberries yet?',cid)
		talkState[talkUser] = 4
	elseif talkState[talkUser] == 3 then
		if msgcontains(msg,'yes') then
			setPlayerStorageValue(cid,1250,1)
			npcHandler:say('Thank you, talk to me again when you have all the blueberries!',cid)
		elseif msgcontains(msg,'no') then
			npcHandler:say('Than not!',cid)
		return true
		end
	elseif talkState[talkUser] == 4 then
		if msgcontains(msg,'yes') then
			if doPlayerRemoveItem(cid,2677,25) then
				doPlayerAddExperience(cid,500)
				npcHandler:say('Thank you very much!',cid)
				setPlayerStorageValue(cid,1250,2)
			else
				npcHandler:say('You don\'t have enough blueberries!',cid)
			end
		elseif msgcontains(msg,'no') then
			npcHandler:say('Than not!',cid)
		return true
		end
	return true
	end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, traveler!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, traveler |PLAYERNAME|!")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
add:
local talkState = {}
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
or w/e u want
u can do this way ^ or:
talkState[cid] or w/e
 
I wan't it to be 'not focused' in this part.

Code:
if msgcontains(msg,'yes') then
			[b]setPlayerStorageValue(cid,1250,1)
			npcHandler:say('Thank you, talk to me again when you have all the blueberries!',cid)[/B]
		elseif msgcontains(msg,'no') then
			npcHandler:say('Than not!',cid)
		return true
		end

Should it be something like 'npcHandler:isFocused(cid) = false' ?
 
i dont understand still but if u want that the npc leaves him and dont talk to him do it like this:
talkState[talkUser] = 0
 
What's wrong in this script?

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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
local talkState = {}
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT

function creatureSayCallback(cid, type, msg)
	if msgcontains(msg,'help') then
		if getPlayerStorageValue(cid,1250) <= 0 then
			npcHandler:say('I need some help on collecting 25 blueberries, could you help me?',cid)
			talkState[talkUser] = 1
		elseif talkState[talkUser] == 1 then
			if msgcontains(msg,'yes') then
				npcHandler:say('Thank you, talk to me when you have the 25 blueberries.',cid)
				talkState[talkUser] = 0
				npcHandler:releaseFocus(cid)
				setPlayerStorageValue(cid,1250,1)
			else
				npcHandler:say('Some other than maybe...',cid)
				talkState[talkUser] = 0
				npcHandler:releaseFocus(cid)
			return true
			end
		elseif getPlayerStorageValue(cid,1250) == 1 then
			npcHandler:say('Have you collected the 25 blueberries yet?',cid)
			talkState[talkUser] = 2
		elseif talkState[talkUser] == 2 then
			if msgcontains(msg,'yes') then
				if doRemoveItem(cid,2677,25) then
					setPlayerStorageValue(cid,1250,2)
					doPlayerAddExperience(cid,500)
					npcHandler:say('Thank you, now I can finally finish my potion!',cid)
					npcHandler:releaseFocus(cid)
				else
					npcHandler:say('You don\'t have 25 blueberries yet!',cid)
					npcHandler:releaseFocus(cid) 
				end
			else
				npcHandler:say('Maybe later...',cid)
				npcHandler:releaseFocus(cid)
			end
		elseif getPlayerStorageValue(cid,1250) == 2 then
			npcHandler:say('Can\'t talk now.... too busy..',cid)
			npcHandler:releaseFocus(cid)
		return true
		end
	return true
	end
end
npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, traveler!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, traveler |PLAYERNAME|!")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

When I i.e. say 'help' with storageValue <= 0 it works, but then when I say 'yes', nothing happens.
No errors whatsoever
 
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,'help') then
		local v = getPlayerStorageValue(cid, 1250)
		if v < 1 then
			npcHandler:say('I need some help with collecting 25 blueberries, could you help me?', cid)
			Topic[cid] = 1
		elseif v == 1 then
			npcHandler:say('Have you collected the 25 blueberries yet?', cid)
			Topic[cid] = 2
		elseif v == 2 then
			npcHandler:say('Can\'t talk now.... too busy..', cid)
			Topic[cid] = 0
			npcHandler:releaseFocus(cid)
		end
	elseif Topic[cid] == 1 then
		if msgcontains(msg,'yes') then
			npcHandler:say('Thank you, talk to me when you have the 25 blueberries.', cid)
			setPlayerStorageValue(cid,1250,1)
		else
			npcHandler:say('Maybe next time...',cid)
		end
		npcHandler:releaseFocus(cid)
		Topic[cid] = 0
	elseif Topic[cid] == 2 then
		if msgcontains(msg,'yes') then
			if doPlayerRemoveItem(cid, 2677, 25) then
				setPlayerStorageValue(cid, 1250, 2)
				doPlayerAddExperience(cid,500)
				npcHandler:say('Thank you, now I can finally finish my potion!',cid)
			else
				npcHandler:say('You don\'t have 25 blueberries!',cid)
			end
		else
			npcHandler:say('Maybe later...',cid)
		end
		Topic[cid] = 0
		npcHandler:releaseFocus(cid)
	end
	return true
end

npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell, traveler!")
npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell, traveler |PLAYERNAME|!")
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
Back
Top