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

NPC Quest NPC example, with quests.xml example! (Gattaca's request)

Hermes

dziwki kola gramy w lola
Joined
Nov 17, 2007
Messages
1,867
Reaction score
14
Location
Poland
Hi there!

For Gattaca's request >HERE< I have made little quest NPC example.

It's supposed to give 20CC in exchange to 10CC, only once.
(EXAMPLE PLX!!!!)

Also take a closer look on talkStates, that's important in bigger NPCs.

@edit
Renusek asked me to add quests.xml example, and so I did. Remember to set "YOURSTORAGE" in both codes. These values MUST be the same ofcourse to work with each other.

Code:
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
function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = YOURSTORAGE
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'crystal')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Hey, I have super quest for you. Bring me please {10 crystal coins}.", cid)
			setPlayerStorageValue(cid, storage, 1)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Do you have 10 crystal coins for me?", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("Sorry, you have already done my super quest.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100000) == TRUE) then
			npcHandler:say("Thanks! As I said, here\'s 20 crystal coins!", cid)
			doPlayerAddItem(cid, 2160, 20)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("Sorry, you don\'t have enough money.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Then not.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

and quests.xml example for this quest:
Code:
<quest name="Super Quest" startstorageid="YOURSTORAGE" startstoragevalue="1">
	<mission name="Money deliver." storageid="YOURSTORAGE" startvalue="1" endvalue="2">
		<missionstate id="1" description="You've been asked to deliver 10 crystal coins to NPC. Perhaps you will have profit from this."/>
		<missionstate id="2" description="You have successfully delivered money. You earned 20 crystal coins for this task."/>
	</mission>
</quest>


Made really fast, I was hurryin' :f

Regards,
Hermes
 
Last edited:
THANK YOU ! I know you'll help another people that are wanting to make npc's quests :D and for those like real tibia. Thank you!
 
Okay, when I'll return from school I will also add quest log example for this.
 
Okay, I have added quests.xml example. Bumping topic.
 
Thanks! This is one thing I always wanted to do, but could never find a working NPC! Reeeeep++
 
I have little problem with NPCs, i thought that I just cannot do this well, but now I copied your script and still NPC ignores me...
Can someone help me?
 
Ok, thx. Now your example works.
Now I'm going to rewrite my script using your example as a base.
Thx men

Edit: Ok my npc works now! Everything is working so thx again.
 
Hermes

can we use the quest log with storage values?
like u have it now with mission ID
i want to make it like mission storage.

like for addons example.
Barbarian Outfit Logs << when you click on that you get down info about
10023 first barbarian addon completed << This
10024 second barbarian addon completed. << This

this above is just examle for more quests.

possible?
 
@up
You can use quest LOGs with ANY storage value. Look closer on my example and you will understand.
 
How do i make it so it gives more than one reward, i current tried :
Code:
			doPlayerAddItem(cid, 2157, 20)
			doPlayerAddItem(cid, 7380, 1)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0

But with that it only gives the top one.
 
@up
Hm, it should give two rewards :f. Try to add them in container:
Code:
local bp = doPlayerAddContainer(cid, 1988, 1)
doContainerAddItem(bp, 2157, 20)
doContainerAddItem(bp, 7380, 1)
 
Thanks Hermes great script as always. One question if you have time.
How could I make it so instead of giveing 10cc you have to give a item,
then you get a item and some exp?
Thanks for any help.
 
Alright well, since its asked here, and since this post helped me SO MUCH beyond belief (It actually changed the TOTAL concept of how I'm creating my ot) I decided to post the modified version of the script, its for a npc i named Len. And basically what he does is that his mission sends you out to hunt and gather 10 cockroach legs, return to him, and he gives you 250gp ALONG with 150xp.

Ontop of that, when you first talk to him, it automatically finishes a quest prior to speaking to him, so feel free to edit out that part if you please to do so.

Code:
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
function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	--[[
	REMEMBER TO SET YOUR STORAGE AS YOURSTORAGE!
	]]--
	local storage = 50001
	if(msgcontains(msg, 'quest') or msgcontains(msg, 'favor')) then
		if(getPlayerStorageValue(cid, storage) < 1) then
			npcHandler:say("Hey, I have a slight favor to ask... Norman has asked me to get him 10 cockroach legs but quite honestly, those things disgust me. So I need you to do it for me.", cid)
			setPlayerStorageValue(cid, storage, 1)
			setPlayerStorageValue(cid, 50000, 2)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Quest Completed: Welcome to Wafe")
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "New Quest: Len\'s Favor")
			doPlayerAddExp(cid, 150)
			doPlayerAddItem(cid, 2152, 2)
			doPlayerAddItem(cid, 2148, 50)
		elseif(getPlayerStorageValue(cid, storage) == 1) then
			npcHandler:say("Do you have the 10 cockroach legs??", cid)
			talkState[talkUser] = 1
		elseif(getPlayerStorageValue(cid, storage) == 2) then
			npcHandler:say("What are you doing? You\'ve finished the favor.", cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(doPlayerRemoveMoney(cid, 100000) == TRUE) then
			npcHandler:say("Thanks, sometimes I think I\'m too lazy but who gives a damn. Anyway, here is your reward! By the way, you might want to consider heading over to the merchants to the north and south to see what they have.", cid)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Quest Completed: Len\'s Favor")
			doPlayerAddExp(cid, 250)
			doPlayerAddItem(cid, 2152, 2)
			setPlayerStorageValue(cid, storage, 2)
			talkState[talkUser] = 0
		else
			npcHandler:say("It seems you don\'t have enough legs gathered.", cid)
			talkState[talkUser] = 0
		end
	elseif(msgcontains(msg, 'no') and talkState[talkUser] > 0) then
		npcHandler:say("Oh well then.", cid)
		talkState[talkUser] = 0
	end
	return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
It's really easy. You have to have just a brain to make great NPCs for your OTServer ;)
 
Back
Top