• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Mission NPC 2.5

ziggy46802

Active Member
Joined
Aug 19, 2012
Messages
418
Reaction score
27
First let me say that the original file came from Acubens, he made the 2.0 mission npc, I just improved it into 2.5 and here it is, I take no credit for the original creation of this file, just the modification.

Here is the lua file for the mission npc

put this in data/npc/scripts
ratquest.lua
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
-- OTServ event handling functions start
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 onPlayerEndTrade(cid)				npcHandler:onPlayerEndTrade(cid) end
function onPlayerCloseChannel(cid)			npcHandler:onPlayerCloseChannel(cid) end
-- OTServ event handling functions 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
 
 
	--------------------------------
	------- NPC MISION  2.5 --------
	---by Acubens, great scripter---
	-----modified by Ziggy46802-----
		   -- Otland.net --
	--------------------------------
 
	local first = {
	-- Place true if you want experience to be part of the quest reward, false if only an item. Place true if you want both
	useExpReward = true,
	-- The experience, if above is set to true, that the player will receive as a reward for the quest
	experience = 1500,
	-- Item ID of the "quest item", or the item that the npc takes from you for you to complete the quest
	item = 8710,
	-- Item ID of the second quest item, just leave alone if you only want one item
	itemtwo = 2160,
	-- The quanity, or how many, of the item needed to complete the quest
	item_count = 10,
	-- The quantity, or how many, of the second quest item needed to complete the quest
	itemtwo_count = 1,  
	-- Item ID of the quest reward if the first option is set to false, but an item can be used with true for exp as reward as well 
	reward = 2480,
	-- Item ID of the quest reward if the first option is set to false, this is the second item that can be "not used"
	rewardtwo = 2160,
	-- The quantity, or how many, of the quest reward that the player will receive for the second item upon completion of the quest, can be "not used"
	rewardtwo_count = 100,
	-- The quanity, or how many, of the quest reward that the player will receive upon completion of the quest
	reward_count = 1, 
	-- The storage value that the quest will use (advised would be between 1000 and 10000)
	storage = 1001, 
	--this is the value of the storage value above that is set when the quest is completed, most people use -1 (non existant) for starting the quest and 1 for ending, but I use 2
	last = 2,
	-- The name of the quest which will pop up upon completion of the quest as "You have completed the quest 'quest name'"
	questname = "Rat Extermination"
	}
 
	local npc_message ={
 
	--the number at the front just shows you what number message it is so when you see "npc_message[4]" in the script you know which line of code it refers to
 
	-- 1Message asking if you have the required items, should be something like "Do you have the 10 antennas?" no highlighting is needed
	"Did you kill enough of them to collect 10 of their antennas?",
	-- 2if you dont have items - message
	"You dont have any items to this mission.", 
	-- 3thanks - message
	"Thank You for Help me, {take it}.",
	-- 4Message that the npc says if you have already done the quest
	"Well the rats aren't as bad anymore, thanks to you that is.",
	-- 5First message for the quest, should be like "Please go collect 10 chicken feathers for me" and do {} around a word like I did, antennas
	"We have a real bad rat problem here in Granitewood. If you kill some of them and collect 10 of their {antennas} then I might give up one of my products for free just for you.",
	-- 6Message given upon completion of the quest, the npc does not say it, it is another type of text
	"Congratulations, you have finished the quest "..first.questname..""
 
	}
 
 
	if(msgcontains(msg, 'rat')) then --the first keyword, should be a word that the xml file for the npc says to you upon greeting
		selfSay(npc_message[5], cid)
	end

if(msgcontains(msg, 'antennas')) then --the second keyword, should be the {highlighted} word from the "5First message"
	selfSay(npc_message[1], cid)
	talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then --this is just saying what happens if you say yes to the "do you have the items" message
	if (getPlayerStorageValue(cid,first.storage) == first.last) then --this is checking if you have already done the quest, if you want it repeatable, then set first.last to something like 100, so that it will "never" be done basically, but only set it to 100 on this line, not in the config, make sure it and first.last are different if you want it repeatable
		selfSay(npc_message[4], cid) 
	else
		if(doPlayerRemoveItem(cid,first.item,first.item_count)) --you don't need to edit this, it pulls the item required for the quest from the config at the start 
		--and --remove the commenting dashes at the front of this line if you want multiple items for the items required for the quest, or you can use or instead of and if you want the person to be able to turn in one or the other item to complete the quest
		--(doPlayerRemoveItem(cid,first.itemtwo,first.itemtwo_count)) --remove the commenting dashes at the front of this line if you want two items
		then
			setPlayerStorageValue(cid,first.storage,first.last) --this sets the storage value so that the quest is "done" and can not be done again
			if(useExpReward) then
				doPlayerAddExperience(cid,first.experience)
				doPlayerAddItem(cid,first.reward,first.reward_count) --comment this line if you want true as exp as reward and only exp as the reward, no item included too
			else
				doPlayerAddItem(cid,first.reward,first.reward_count) --if useExpReward was set to false, these are the items that the player receives
				doPlayerAddItem(cid,first.rewardtwo,first.rewardtwo_count) --comment this line if you only want one item as a reward
			end
			selfSay(npc_message[3], cid) --this is all the completion of the quest and the thank you and the "you completed quest blah" stuff
			doSendMagicEffect(getCreaturePosition(cid), 10)
			doCreatureSay(cid, npc_message[6], TALKTYPE_ORANGE_1)
		else
			selfSay(npc_message[2], cid) --this is the message you get if you don't have the items required for the quest
		end
	end
return true
end
 
end



npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
local shopModule = ShopModule:new() --comment this line if you do not want a shop
npcHandler:addModule(shopModule) --comment this line if you do not want a shop

-------------------For sale-------------------
	--1
shopModule:addBuyableItem({'bandana'}, 5917, 600, 'bandana')

-------------------Sell to him-------------------

	--1
shopModule:addSellableItem({'bandana'}, 5917, 150,'bandana')

 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new()) --comment this line if you do not want a shop

Basically same as the 2.0, but upgraded to 2.5 since it now has two items required for quest, if you want, and two rewards for quest, if you want, and option to be repeatable, if you want, and an item included with the exp as reward, if you want, as well as very "complete" commenting so that it is VERY easy to follow and foolproof pretty much. Anyone could take this with no prior knowledge and make a pretty cool mission npc out of it.

All credits for the original, and basis of the npc, goes to Acubens, who is a great scripter. I just took it and added a little to it to improve upon it, and remind everyone its here since his post was buried, and also commented it since I noticed his english wasn't the best and some people might have a hard time following it, so I commented it like crazy so that someone completely new to the world of open tibia could take this and set it up

Put this in data/npc/scripts as something like ratquest.lua and make your npc.xml file in data/npc use the file "ratquest.lua" to use this. The XML file is not included since the default can be used, besides making it use the right script.

Here is an npc for data/npc

Quest Guy.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Quest Guy" script="data/npc/scripts/ratquest.lua" walkinterval="5000" floorchange="0">
    <health now="100" max="100"/>
    <look type="266" head="1" body="1" legs="1" feet="1" addons="3"/>
    <parameters>
        <parameter key="message_greet" value="Welcome |PLAYERNAME| Are your ready for this {mission}?" />
 
 
 
    </parameters>
</npc>

Rep me if you like this, and rep Acubens too since he made the original.

Leave a comment on what you think I should add, if anything, or change, if anything.
 
Last edited:
Can you use Lua and XML tags? No color = eye burner
 
sorry, I just forgot to use them and used the generic "code" tags, fixed it though

Fixed him, I tested him in my server and he did not work, but this script does indeed work, I tested it on my server (latest TFS 9.6)
 
Last edited:
Nice script. Thanks!

Only thing is im getting an error when im trying to complete the quest.
Problem with doPlayerRemoveItem.

Im using forgotten server 1.0
upload_2014-9-3_0-52-52.png
 
Last edited:
Back
Top