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

rpg chainquest request

waterland

God of the mf Sea
Joined
Mar 16, 2010
Messages
92
Reaction score
16
I have been having trouble linking together two+ npcs to create a RPG style chain of quests.
one npc sends you on quest to get X items, when you turn in the items, he tells you to go talk to next npc, and next npc gives task, you finish task and he tells you to go to next npc... and so on.

cant seem to get it right! >.< something with the storages... need some help ^^... using 9.6 client.
 
Can you make a conversation example of the 2 NPCs?
So how it will look like ingame when you talk to the NPCs, to understand what you want exactly.
 
I think it's something like this :)
P-player
N-npc

P:hi
N:hello
P:mission
N:Bring me 100 chicken feathers
Afer you get required items:
P:hi
N:hello
P:mission
N:do you have all required items ?
P:yes
N:Great, you have completed my mission. Please visit NPC number 2 now for next task.
P:bye
And now you have to go to another npc to get second mission. But it's still the same quest. It's like In service of yalahar, you know ? One quest but 10 missions.
 
yes just as Astamor said,
with each quest completed the next npc has a more challenging quest for you... whether its a item-collecting mission, monster-killing assignment, or both :O

and if you havnt finished, npc 1's mission, you cant get npc 2+'s missions untill you do finish...
 
You can do this with storage, the storagevalue you set in the NPC after completing the mssion, use that in the next NPC.
If you already made NPCs, you can post them and I can show you how to do it.
Or if you don't know how to make the NPCs, make something like astamor did, also what the next NPCs should do, so I know what you want exactly.

Also add which server you use, to know which functions I can use.
 
npc1 (hero's wife) sends you on a mission to get 20 roses, turn it in to npc1. As a confirmation of completion npc1 sends you to npc2. (thats where the storagevalue goes?)
npc2 (who is a hero) tells you to kill 50 black knights, when completed he tells you to go to next npc... havnt thought of next npcs after this one but for an example ill say: npc3 sends youto kill 50 witches and collect 10 of their capes and 10 of their brooms from them. then any future npcs will be similar to npc3 with more sets of items to collect..~

if i had a little example, i shouldd be able to expand on it. :)
 
Last edited:
Can you make a conversation example how it will look like ingame when talking to the NPCs?
And post which server you are using (you can see this at the top of your console), so I know which functions I can use.
 
P=player N=npc1,2,or 3
in the script, npc names can be: n1= "One" , n2= "Two" , n3= "Three",
TFS 0.4/9.6 client
P: hi
N1: Hello[PLAYERNAME], i need your help
P: help
N1: can you bring me 20 roses?
P: yes
N1: hurry please.
------------------------------------------
P: hi
N1: have you brought what i asked?
P: yes
N1: oh thank you! Please go find [NPC2NAME], he needs your help.
(if P doesnt have items) N1: you dont have what i asked! you still need {items left}
P: bye
N1: goodbye
now you can talk to npc2

(if you didnt finish npc1 quest):
P: hi
N2: I have no business with you.
(lose focus on player)
-otherwise
P: Hi
N2: Hello[PLAYERNAME], i need your help
P: help
N2: can you help me kill 50 black knights?
P: yes
N2: hurry please.
----------------------
P: hi
N2: have you finished what i asked?
P: yes
N2: Thank you for your help! Please go find [NPC3NAME], he needs your help.
(if P didnt kill all monsters) N2: you didnt even kill all of them! you still have {monsters left} left!
P: bye
N2: goodbye
now you can talk to NPC3
(if you didnt finish npc2 quest):
P: hi
N3: I have no business with you.
(lose focus on player)
-otherwise
P: Hi
N3: Hello[PLAYERNAME], i need your help
P: help
N3: i need you to kill 50 witches and collect 10 brooms and 10 capes from them. Are you up for it?
P: yes
N3: Make haste.
----------------------
P: hi
N3: have you finished what i asked?
P: yes
N3: Good job. Maybe [NPC3NAME] has some work for you now.
(if P didnt finish) N3: you didnt finish what i asked. you still have {monsters left/items} left!
P: bye
N3: goodbye
now you can talk to NPC4 ~and so on.
 
NPC1
Lua:
--NPC1
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 storage = 6800

function creatureSayCallback(cid, type, msg)

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(not npcHandler:isFocused(cid)) then
		if(msg == 'hi' or msg == 'hello') then
			if(getPlayerStorageValue(cid, storage) == -1) then 
				selfSay('Hello '..getPlayerName(cid)..', I need your {help}.', cid)
				talkState[talkUser] = 1
			elseif(getPlayerStorageValue(cid, storage) == 1) then 
				selfSay('Have you brought what I asked?', cid)
				talkState[talkUser] = 2
			else
				selfSay('Thanks again for the roses.', cid) 
			end
			npcHandler:addFocus(cid)
		else
			return false
		end
	end

	if(msgcontains(msg, 'help') and talkState[talkUser] == 1) then
		selfSay('Can you bring me 20 roses?', cid)
		talkState[talkUser] = 2 
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getPlayerStorageValue(cid, storage) == -1) then 
			selfSay('Hurry please.', cid)
			setPlayerStorageValue(cid, storage, 1)
		else
			if(doPlayerRemoveItem(cid, 2744, 20)) then 
				selfSay('Oh thank you! Please go find NPC2, he needs your help.', cid)
				doPlayerAddExp(cid, 5000) -- reward?
				setPlayerStorageValue(cid, storage, 2)
			else 
				local count = 20 - getPlayerItemCount(cid, 2744)
				selfSay('You don\'t have what I asked! You still need '..count..' '..(count > 1 and 'roses' or 'rose')..'.', cid)
			end
		end
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
		selfSay('Ok then.', cid)
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'bye')) then
		selfSay('Bye.', cid)
		npcHandler:releaseFocus(cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
NPC2
Lua:
--NPC2
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 storage = 6800

function creatureSayCallback(cid, type, msg)

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(not npcHandler:isFocused(cid)) then
		if(msg == 'hi' or msg == 'hello') then
			if(getPlayerStorageValue(cid, storage) < 2) then 
				selfSay('I have no business with you.', cid)
				return false
			elseif(getPlayerStorageValue(cid, storage) == 2) then 
				selfSay('Hello '..getPlayerName(cid)..', I need your {help}.', cid)
				talkState[talkUser] = 1
			elseif(getPlayerStorageValue(cid, storage) == 3) then 
				selfSay('Have you finished what I asked?', cid)
				talkState[talkUser] = 2
			else
				selfSay('Thanks again for killing the monsters.', cid) 
			end
			npcHandler:addFocus(cid)
		else
			return false
		end
	end

	if(msgcontains(msg, 'help') and talkState[talkUser] == 1) then
		selfSay('Can you help me kill 50 black knights?', cid)
		talkState[talkUser] = 2 
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getPlayerStorageValue(cid, storage) == 2) then 
			selfSay('Hurry please.', cid)
			setPlayerStorageValue(cid, storage, 3)
		else
			if(getPlayerStorageValue(cid, 19800) == 50) then 
				selfSay('Thank you for your help. Please go find NPC3, he needs your help.', cid)
				doPlayerAddExp(cid, 5000) -- reward?
				setPlayerStorageValue(cid, storage, 4)
			else 
				local count = 50 - (getPlayerStorageValue(cid, 19800)+1)
				selfSay('You didn\'t even kill all of them! You still have '..count..' '..(count > 1 and 'Black Knights' or 'Black knight')..' left.', cid)
			end
		end
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
		selfSay('Ok then.', cid)
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'bye')) then
		selfSay('Bye.', cid) 
		npcHandler:releaseFocus(cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
NPC3
Lua:
--NPC3
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 c = {
	items = {
		{id = 2324, count = 10},
		{id = 2654, count = 10}
	},
	monster = {storage = 19801, amount = 50}
}

local storage = 6800

function creatureSayCallback(cid, type, msg)

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(not npcHandler:isFocused(cid)) then
		if(msg == 'hi' or msg == 'hello') then
			if(getPlayerStorageValue(cid, storage) < 4) then 
				selfSay('I have no business with you.', cid)
				return false
			elseif(getPlayerStorageValue(cid, storage) == 4) then 
				selfSay('Hello '..getPlayerName(cid)..', I need your {help}.', cid)
				talkState[talkUser] = 1
			elseif(getPlayerStorageValue(cid, storage) == 5) then 
				selfSay('Have you finished what I asked?', cid)
				talkState[talkUser] = 2
			else
				selfSay('Thanks again for items and killing the monsters.', cid) 
			end
			npcHandler:addFocus(cid)
		else
			return false
		end
	end

	if(msgcontains(msg, 'help') and talkState[talkUser] == 1) then
		selfSay('I need you to kill 50 Witches and collect 10 brooms and 10 capes from them. Are you up for it?', cid)
		talkState[talkUser] = 2 
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
		if(getPlayerStorageValue(cid, storage) == 4) then 
			selfSay('Make haste.', cid)
			setPlayerStorageValue(cid, storage, 5)
		else
			amount = 0 
			for i = 1, #c.items do
				if(getPlayerItemCount(cid, c.items[i].id) >= c.items[i].count) then
					amount = amount + 1
				end
			end
			if(getPlayerStorageValue(cid, 19801) == 50 and amount == #c.items) then 
				for i = 1, #c.items do
					doPlayerRemoveItem(cid, c.items[i].id, c.items[i].count)
				end
				selfSay('Good job, maybe NPC4 has some word for you now.', cid)
				doPlayerAddExp(cid, 5000) -- reward?
				setPlayerStorageValue(cid, storage, 6)
			else 
				local n = 0
				for i = 1, #c.items do
					if getPlayerItemCount(cid, c.items[i].id) < c.items[i].count then
						n = n + 1 
					end
				end
				local text = ""
				local a = 0
				for v = 1, #c.items do	
					count, info = c.items[v].count - getPlayerItemCount(cid, c.items[v].id), getItemInfo(c.items[v].id)
					if(getPlayerItemCount(cid, c.items[v].id) < c.items[v].count) then
						a = a + 1
						local ret = ", "
						if a == 1 then
							ret = ""
						elseif a == n then
							ret = " and "
						end
						text = text .. ret
						text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
					end
				end
				if(text ~= "") then
					text = ' '..text..''
				end
				local count = c.monster.amount - (getPlayerStorageValue(cid, c.monster.storage)+1)
				local mtext = ''
				if(c.monster.amount > (getPlayerStorageValue(cid, c.monster.storage)+1)) then
					mtext = ' '..count..' '..(count > 1 and 'Witches' or 'Witch')..''..(a == 1 and ' and' or (a == 0 and '' or ','))..''
				end
				selfSay('You didn\'t finish what I asked. You still have'..mtext..''..text..' left.', cid)
			end
		end
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
		selfSay('Ok then.', cid)
		talkState[talkUser] = 0 
	elseif(msgcontains(msg, 'bye')) then
		selfSay('Bye.', cid) 
		npcHandler:releaseFocus(cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
Creaturescript
Lua:
local config = {
	["black knight"] = {amount = 50, storage = 19800, startstorage = 6800, startvalue = 3}, 
	["witch"] = {amount = 50, storage = 19801, startstorage = 6800, startvalue = 5}
}
function onKill(cid, target)
 
	local monster = config[getCreatureName(target):lower()]
 
	if(isPlayer(target) or not monster) then
		return true
	end
  
	if(getPlayerStorageValue(cid, monster.storage) >= -1 and (getPlayerStorageValue(cid, monster.storage)+1) < monster.amount and getPlayerStorageValue(cid, monster.startstorage) >= monster.startvalue) then	
		setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Task '..getCreatureName(target)..': '..(getPlayerStorageValue(cid, monster.storage)+1)..'/'..monster.amount..'.')
	end
	if((getPlayerStorageValue(cid, monster.storage)+1) == monster.amount) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have completed the '..getCreatureName(target)..' mission.')
		setPlayerStorageValue(cid, monster.storage, getPlayerStorageValue(cid, monster.storage) + 1)
	end
	return true
end
 
Last edited:
thank you so much! this is very helpful :D
so if i wanted npc4 i would need to change the storages [4,5 and 6] to [6,7 and 8] right?
and if i wanted another hunting mission, i just add something like this in the creaturescript?
Code:
["dragon"] = {amount = 5, storage = 19802, startstorage = 6800, startvalue = 7}
 
Back
Top