• 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 with doors

finio

New Member
Joined
Aug 15, 2011
Messages
11
Reaction score
0
Hello, I wolud like to know how to make quest, where I have to give X item to npc, then I can open doors.

I was using search tools so don't be mad on me :)

I am using TFS 0.2.10 for tibia 8.7
 
one door :)
Thanks Evan, good hint.

But if there is someone who can do this for example to other players, he should show this script :p
 
Last edited:
NPC:
Code:
local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid)) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end

function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "ITEM")) then
		if doPlayerRemoveItem(cid, ITEMID) then
			selfSay("Thank you!", cid, true)
			doCreatureSetStorage(cid, 1463, 1)
		else
			selfSay("You don't have that item yet...", cid, true)
		end
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onThink()
	for i, focus in pairs(focuses) do
		if(not isCreature(focus)) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end
Change ITEM with the item name and ITEMID with the itemid of the item.
Door:
Code:
function onUse(cid,item,frompos)
	if item.ationid == 1463 then
		if getCreatureStorage(cid, 1463) > 0 then
			doTransformItem(item.uid, 1211)
		else
			doPlayerSendCancel(cid,"You need to give X item to Y NPC.")
			doSendMagicEffect(frompos,CONST_ME_POFF)
		end
	else
		doTransformItem(item.uid, 1211)
	end
	return TRUE
end
Change X item and Y NPC with with the item name and NPC's name. If you want to change the door to a different opened door, change 1211 with the door id.
If you don't know how to set up the XMLs tell me and I'll post them too ;)
 
Hello, thank for your help, everything works fine :)

But if you could set the npc to talks like that:
player: hi
npc: hello, blablabla i have job for you (little explaintation what is the quest, leave it for me)
player: mission
npc: again blablabla, bring me X item or if you could do amount X items, like 50 worms
player: yes

and when you get 50 worms you go talk to npc:
player:hi
npc:hello
player: 50 worms
npc: thanks blabla (and now i can open the doors)

If you will do that, it will be example to create maaany quests

Thanks in advance
 
Something like this:
Code:
local focuses = {}
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end

local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			table.remove(focuses, i)
			break
		end
	end
end
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v)) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
	doNpcSetCreatureFocus(0)
end

function onCreatureAppear(cid)
end

function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Hmph!")
		removeFocus(cid)
		if(isPlayer(cid)) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end

function onCreatureSay(cid, type, msg)
	if((msg == "hi") and not (isFocused(cid))) then
		selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
		addFocus(cid)
	elseif((isFocused(cid)) and (msg == "mission")) then
		selfSay("Bla, bla, bla", cid, true)
	elseif((isFocused(cid)) and (msgcontains(msg,"worm"))) then
		if doPlayerRemoveItem(cid, 3976, 50) then
			selfSay("Thank you!", cid, true)
			doCreatureSetStorage(cid, 1463, 1)
		else
			selfSay("You don't have the worms yet...", cid, true)
		end
	elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
		selfSay("Goodbye!", cid, true)
		closeShopWindow(cid)
		removeFocus(cid)
	end
end

function onThink()
	for i, focus in pairs(focuses) do
		if(not isCreature(focus)) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Hmph!")
				closeShopWindow(focus)
				removeFocus(focus)
			end
		end
	end
	lookAtFocus()
end
?
;)
 
Ummm it doesn't work,
I can give as many worms as I want to the npc ( after the 50, he should say that I did this mission)
and I can't open the doors after I gave worms

:(
 
But have you tried giving him the 50 at the same time? That should work, if it doesn't, tell me, if it does, but when you don't give him all at the same time it takes worms, tell me too and I'll fix it ;)
 
Back
Top