• 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] Need help to change script working on TFS 0.3

Reah

New Member
Joined
Jul 7, 2008
Messages
87
Reaction score
0
Im using The Forgotten Server Version 0.3.1 Patch2

I got some nice npc but they're not working on this server...
I want u to help me change some lines to work. Then i will change all my npcs like this...

Ok. Here is to script of my Runes Shop ;p
Code:
---------holy missile------------

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

ShopModule:addBuyableItem({'spellbook'}, 2175, 150, 1, 'spellbook')
ShopModule:addBuyableItem({'magic lightwand'}, 2163, 400, 1, 'magic lightwand')

shopModule:addBuyableItem({'health potion'}, 7618, 45, 1, 'health potion')
ShopModule:addBuyableItem({'mana potion'}, 7620, 50, 1, 'mana potion')
ShopModule:addBuyableItem({'strong health'}, 7588, 100, 1, 'strong health potion')
ShopModule:addBuyableItem({'strong mana'}, 7589, 80, 1, 'strong mana potion')
ShopModule:addBuyableItem({'great health'}, 7591, 190, 1, 'great health potion')
ShopModule:addBuyableItem({'great mana'}, 7590, 120, 1, 'great mana potion')
ShopModule:addBuyableItem({'great spirit'}, 8472, 190, 1, 'great spirit potion')
ShopModule:addBuyableItem({'ultimate health'}, 8473, 310, 1, 'ultimate health potion')

ShopModule:addSellableItem({'normal flask'}, 7636, 5, 'empty small potion flask')
ShopModule:addSellableItem({'strong flask'}, 7634, 10, 'empty strong potion flask')
ShopModule:addSellableItem({'great flask'}, 7635, 15, 'empty great potion flask')

ShopModule:addBuyableItem({'blank rune'}, 		2260, 10, 1,		'blank rune')
ShopModule:addBuyableItem({'animate dead'}, 		2316, 375, 1,		'animate dead rune')
ShopModule:addBuyableItem({'antidote'}, 		2266, 65, 1, 		'antidote rune')
ShopModule:addBuyableItem({'avalanche'}, 		2274, 180, 4,		'avalanche rune')
ShopModule:addBuyableItem({'chameleon'}, 		2291, 210, 1, 		'chameleon rune')
ShopModule:addBuyableItem({'convince creature'}, 	2290, 80, 1,		'convince creature rune')
ShopModule:addBuyableItem({'desintegrate'}, 		2310, 80, 3,		'desintegrate rune')
ShopModule:addBuyableItem({'destroy field'}, 		2261, 45,  3, 		'destroy field')
ShopModule:addBuyableItem({'energy bomb'}, 		2262, 325, 2,		'energy bomb rune')
ShopModule:addBuyableItem({'energy field'}, 		2277, 115, 3, 		'energy field')
ShopModule:addBuyableItem({'energy wall'}, 		2279, 340, 4,		'energy wall rune')
ShopModule:addBuyableItem({'explosion'}, 		2313, 190, 6, 		'explosion rune')
ShopModule:addBuyableItem({'fire bomb'}, 		2305, 235, 2,		'fire bomb rune')
ShopModule:addBuyableItem({'fire field'}, 		2301, 85,  3,		'fire field rune')
ShopModule:addBuyableItem({'fire wall'}, 		2303, 245, 4,		'fire wall rune')
ShopModule:addBuyableItem({'fireball'}, 		2302, 150,  5,		'fire ball')
ShopModule:addBuyableItem({'great fireball'}, 		2304, 180, 4, 		'great fireball rune')
ShopModule:addBuyableItem({'heavy magic missile'}, 	2311, 120, 10,		'heavy magic missile rune')
ShopModule:addBuyableItem({'icicle'}, 			2271, 150, 5,		'icicle rune')
ShopModule:addBuyableItem({'intense healing'}, 		2265, 95, 1,		'intense healing rune')
ShopModule:addBuyableItem({'light magic missile'}, 	2287, 40, 10,		'light magic missile rune')
ShopModule:addBuyableItem({'magic wall'}, 		2293, 350, 3,		'magic wall rune')
ShopModule:addBuyableItem({'paralyze'}, 		2278, 700, 1, 		'paralyze rune')
ShopModule:addBuyableItem({'poison bomb'}, 		2286, 170, 2,		'poison bomb rune')
ShopModule:addBuyableItem({'poison field'}, 		2285, 65,  3,		'poison field')
ShopModule:addBuyableItem({'poison wall'}, 		2289, 210, 4,		'poison wall rune')
ShopModule:addBuyableItem({'soulfire'}, 		2308, 140, 3, 		'soulfire rune')
ShopModule:addBuyableItem({'stalagmite'}, 		2292, 120, 10, 		'stalagmite rune')
ShopModule:addBuyableItem({'stone shower'}, 		2288, 150, 4, 		'stoneshower rune')
ShopModule:addBuyableItem({'sudden death'}, 		2268, 325, 3, 		'sudden death rune')
ShopModule:addBuyableItem({'thunderstorm'}, 		2268, 150, 4, 		'thunderstorm rune')
ShopModule:addBuyableItem({'ultimate healing'}, 	2273, 175, 1, 		'ultimate healing rune')
ShopModule:addBuyableItem({'wild growth'}, 		2269, 320, 2,		'wild growth rune')

ShopModule:addBuyableItemContainer({'bp blank rune'}, 		1988, 2260, 220, 1,		'bp blank rune')
ShopModule:addBuyableItemContainer({'bp animate dead'}, 	1998, 2316, 7520, 1,		'bp animate dead rune')
ShopModule:addBuyableItemContainer({'bp antidote'}, 		2003, 2266, 1320, 1, 		'bp antidote rune')
ShopModule:addBuyableItemContainer({'bp avalanche'}, 		2002, 2274, 3620, 4,		'bp avalanche rune')
ShopModule:addBuyableItemContainer({'bp chameleon'}, 		1998, 2291, 4220, 1, 		'bp chameleon rune')
ShopModule:addBuyableItemContainer({'bp convince creature'}, 	1998, 2290, 1620, 1,		'bp convince creature rune')
ShopModule:addBuyableItemContainer({'bp desintegrate'}, 	2001, 2310, 1620, 3,		'bp desintegrate rune')
ShopModule:addBuyableItemContainer({'bp destroy field'}, 	2003, 2261, 920,  3, 		'bp destroy field')
ShopModule:addBuyableItemContainer({'bp energy bomb'}, 		2003, 2262, 6520, 2,		'bp energy bomb rune')
ShopModule:addBuyableItemContainer({'bp energy field'}, 	1998, 2277, 2320, 3, 		'bp energy field')
ShopModule:addBuyableItemContainer({'bp energy wall'}, 		2002, 2279, 6820, 4,		'bp energy wall rune')
ShopModule:addBuyableItemContainer({'bp explosion'}, 		2001, 2313, 3820, 6, 		'bp explosion rune')
ShopModule:addBuyableItemContainer({'bp fire bomb'}, 		2000, 2305, 4720, 2,		'bp fire bomb rune')
ShopModule:addBuyableItemContainer({'bp fire field'}, 		2000, 2301, 1720,  3,		'bp fire field rune')
ShopModule:addBuyableItemContainer({'bp fire wall'}, 		2000, 2303, 4920, 4,		'bp fire wall rune')
ShopModule:addBuyableItemContainer({'bp fireball'}, 		2000, 2302, 3020,  5,		'bp fire ball')
ShopModule:addBuyableItemContainer({'bp great fireball'}, 	2000, 2304, 3620, 4, 		'bp great fireball rune')
ShopModule:addBuyableItemContainer({'bp heavy magic missile'}, 	2001, 2311, 2420, 10,		'bp heavy magic missile rune')
ShopModule:addBuyableItemContainer({'bp icicle'}, 		2002, 2271, 3020, 5,		'bp icicle rune')
ShopModule:addBuyableItemContainer({'bp intense healing'}, 	2003, 2265, 1920, 1,		'bp intense healing rune')
ShopModule:addBuyableItemContainer({'bp light magic missile'}, 	1998, 2287, 820, 10,		'bp light magic missile rune')
ShopModule:addBuyableItemContainer({'bp magic wall'}, 		1999, 2293, 7020, 3,		'bp magic wall rune')
ShopModule:addBuyableItemContainer({'bp paralyze'}, 		2002, 2278, 1420, 1, 		'bp paralyze rune')
ShopModule:addBuyableItemContainer({'bp poison bomb'}, 		1998, 2286, 3420, 2,		'bp poison bomb rune')
ShopModule:addBuyableItemContainer({'bp poison field'}, 	1998, 2285, 1320,  3,		'bp poison field')
ShopModule:addBuyableItemContainer({'bp poison wall'}, 		1998, 2289, 4220, 4,		'bp poison wall rune')
ShopModule:addBuyableItemContainer({'bp soulfire'}, 		2000, 2308, 2820, 3, 		'bp soulfire rune')
ShopModule:addBuyableItemContainer({'bp stalagmite'}, 		1998, 2292, 2400, 10, 		'bp stalagmite rune')
ShopModule:addBuyableItemContainer({'bp stone shower'}, 	1999, 2288, 3020, 4, 		'bp stoneshower rune')
ShopModule:addBuyableItemContainer({'bp sudden death'}, 	2003, 2268, 6520, 3, 		'bp sudden death rune')
ShopModule:addBuyableItemContainer({'bp thunderstorm'}, 	1999, 2268, 3020, 4, 		'bp thunderstorm rune')
ShopModule:addBuyableItemContainer({'bp ultimate healing'}, 	2002, 2273, 3520, 1, 		'bp ultimate healing rune')
ShopModule:addBuyableItemContainer({'bp wild growth'}, 		2002, 2269, 6420, 2,		'bp wild growth rune')

ShopModule:addBuyableItemContainer({'bp health potion'}, 	2000, 7618, 45, 1, 		'bp health potion')
ShopModule:addBuyableItemContainer({'bp mana potion'}, 		2001, 7620, 50, 1, 		'bp mana potion')
ShopModule:addBuyableItemContainer({'bp strong health'}, 	2000, 7588, 100, 1, 		'bp strong health potion')
ShopModule:addBuyableItemContainer({'bp strong mana'}, 		2001, 7589, 80, 1, 		'bp strong mana potion')
ShopModule:addBuyableItemContainer({'bp great health'}, 	2000, 7591, 190, 1, 		'bp great health potion')
ShopModule:addBuyableItemContainer({'bp great mana'}, 		2001, 7590, 120, 1, 		'bp great mana potion')
ShopModule:addBuyableItemContainer({'bp great spirit'}, 	1988, 8472, 190, 1, 		'bp great spirit potion')
ShopModule:addBuyableItemContainer({'bp ultimate health'}, 	2000, 8473, 310, 1, 		'bp ultimate health potion')

ShopModule:addBuyableItem({'wand of vortex'}, 2190, 500, 1, 'wand of vortex')
ShopModule:addBuyableItem({'wand of dragonbreath'}, 2191, 1000, 1, 'wand of dragonbreath')
ShopModule:addBuyableItem({'wand of decay'}, 2188, 5000, 1, 'wand of decay')
ShopModule:addBuyableItem({'wand of draconia'}, 8921, 7500, 1, 'wand of draconia')
ShopModule:addBuyableItem({'wand of cosmic energy'}, 2189, 10000, 1, 'wand of cosmic energy')
ShopModule:addBuyableItem({'wand of inferno'}, 2187, 15000, 1, 'wand of inferno')
ShopModule:addBuyableItem({'wand of starstorm'}, 8920, 18000, 1, 'wand of starstorm')
ShopModule:addBuyableItem({'wand of voodoo'}, 8922, 22000, 1, 'wand of voodoo')

ShopModule:addBuyableItem({'snakebite rod'}, 2182, 500, 1, 'snakebite rod')
ShopModule:addBuyableItem({'moonlight rod'}, 2186, 1000, 1, 'moonlight rod')
ShopModule:addBuyableItem({'necrotic rod'}, 2185, 5000, 1, 'necrotic rod')
ShopModule:addBuyableItem({'northwind rod'}, 8911, 7500, 1, 'northwind rod')
ShopModule:addBuyableItem({'terra rod'}, 2181, 10000, 1, 'terra rod')
ShopModule:addBuyableItem({'hailstorm rod'}, 2183, 15000, 1, 'hailstorm rod')
ShopModule:addBuyableItem({'springsprout rod'}, 8912, 18000, 1, 'springsprout rod')
ShopModule:addBuyableItem({'underworld rod'}, 8910, 22000, 1,  'underworld rod')

ShopModule:addSellableItem({'wand of vortex'}, 2190, 500, 1, 'wand of vortex')
ShopModule:addSellableItem({'wand of dragonbreath'}, 2191, 1000, 1, 'wand of dragonbreath')
ShopModule:addSellableItem({'wand of decay'}, 2188, 5000, 1, 'wand of decay')
ShopModule:addSellableItem({'wand of draconia'}, 8921, 7500, 1, 'wand of draconia')
ShopModule:addSellableItem({'wand of cosmic energy'}, 2189, 10000, 1, 'wand of cosmic energy')
ShopModule:addSellableItem({'wand of inferno'},2187, 15000, 1, 'wand of inferno')
ShopModule:addSellableItem({'wand of starstorm'}, 8920, 18000, 1, 'wand of starstorm')
ShopModule:addSellableItem({'wand of voodoo'}, 8922, 22000, 1, 'wand of voodoo')

ShopModule:addSellableItem({'snakebite rod'}, 2182, 500, 1, 'snakebite rod')
ShopModule:addSellableItem({'moonlight rod'}, 2186, 1000, 1,   'moonlight rod')
ShopModule:addSellableItem({'necrotic rod'}, 2185, 5000, 1, 'necrotic rod')
ShopModule:addSellableItem({'northwind rod'}, 8911, 7500, 1, 'northwind rod')
ShopModule:addSellableItem({'terra rod'}, 2181, 10000, 1, 'terra rod')
ShopModule:addSellableItem({'hailstorm rod'}, 2183, 15000, 1, 'hailstorm rod')
ShopModule:addSellableItem({'springsprout rod'}, 8912, 18000, 1, 'springsprout rod')
ShopModule:addSellableItem({'underworld rod'}, 8910, 22000, 1, 'underworld rod')


function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	local items = {[1] = 2190, [2] = 2182, [5] = 2190, [6] = 2182}
	if(msgcontains(msg, 'first rod') or msgcontains(msg, 'first wand')) then
		if(isSorcerer(cid) or isDruid(cid)) then
			if(getPlayerStorageValue(cid, 30002) == -1) then
				selfSay('So you ask me for a {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '} to begin your advanture?', cid)
				talkState[talkUser] = 1
			else
				selfSay('What? I have already gave you one {' .. getItemNameById(items[getPlayerVocation(cid)]) .. '}!', cid)
			end
		else
			selfSay('Sorry, you aren\'t a druid either a sorcerer.', cid)
		end
	elseif(msgcontains(msg, 'yes')) then
		if(talkState[talkUser] == 1) then
			doPlayerAddItem(cid, items[getPlayerVocation(cid)], 1)
			selfSay('Here you are young adept, take care yourself.', cid)
			setPlayerStorageValue(cid, 30002, 1)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		selfSay('Ok then.', cid)
		talkState[talkUser] = 0
	end

	return true
end

local ShopModule = ShopModule:new()
npcHandler:addModule(ShopModule)

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
I got some errors. I tried to change the letters in shopModule to ShopModule that i saw in modules.lua but i get new errors... Now i tried to fix error, but i'm realy noob in scripts... Never did npc.
Code:
[14/02/2009 07:54:33] data/npc/lib/npcsystem/modules.lua:743: attempt to index field 'npcHandler' (a nil value)
[14/02/2009 07:54:33] [Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/runes.lua
[14/02/2009 07:54:33] data/npc/scripts/runes.lua:5: unexpected symbol near '.'
 
Try this npc/lib/npcsystem/modules.lua Delete all on your that modules.lua and paste this
Code:
-- Advanced NPC System (Created by Jiddo),
-- Modified by Talaturen.
-- Modified by Elf.

if(Modules == nil) then
	-- default words for greeting and ungreeting the npc. Should be a table containing all such words.
	FOCUS_GREETWORDS = {'hi', 'hello', 'hey'}
	FOCUS_FAREWELLWORDS = {'bye', 'farewell', 'cya'}

	-- The words for requesting trade window.
	SHOP_TRADEREQUEST = {'offer', 'trade'}

	-- The word for accepting/declining an offer. CAN ONLY CONTAIN ONE FIELD! Should be a teble with a single string value.
	SHOP_YESWORD = {'yes'}
	SHOP_NOWORD = {'no'}

	-- Pattern used to get the amount of an item a player wants to buy/sell.
	PATTERN_COUNT = '%d+'

	-- Constants used to separate buying from selling.
	SHOPMODULE_SELL_ITEM = 1
	SHOPMODULE_BUY_ITEM = 2
	SHOPMODULE_BUY_ITEM_CONTAINER = 3

	-- Constants used for shop mode. Notice: addBuyableItemContainer is working on all modes
	SHOPMODULE_MODE_TALK = 1 -- Old system used before Tibia 8.2: sell/buy item name
	SHOPMODULE_MODE_TRADE = 2 -- Trade window system introduced in Tibia 8.2
	SHOPMODULE_MODE_BOTH = 3 -- Both working at one time

	-- Used shop mode
	SHOPMODULE_MODE = SHOPMODULE_MODE_BOTH

	Modules = {
		parseableModules = {}
	}

	StdModule = {}

	-- These callback function must be called with parameters.npcHandler = npcHandler in the parameters table or they will not work correctly.
	-- Notice: The members of StdModule have not yet been tested. If you find any bugs, please report them to me.
	-- Usage:
		-- keywordHandler:addKeyword({'offer'}, StdModule.say, {npcHandler = npcHandler, text = 'I sell many powerful melee weapons.'})
	function StdModule.say(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.say called without any npcHandler instance.')
		end
		local onlyFocus = (parameters.onlyFocus == nil or parameters.onlyFocus == true)
		if(not npcHandler:isFocused(cid) and onlyFocus) then
			return false
		end
		local parseInfo = {
				[TAG_PLAYERNAME] = getCreatureName(cid),
		}
		msgout = npcHandler:parseMessage(parameters.text or parameters.message, parseInfo)
		npcHandler:say(msgout, cid, parameters.publicize and true)
		if(parameters.reset == true) then
			npcHandler:resetNpc()
		elseif(parameters.moveup ~= nil and type(parameters.moveup) == 'number') then
			npcHandler.keywordHandler:moveUp(parameters.moveup)
		end
		return true
	end

	--Usage:
		-- local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'})
		-- 		node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, cost = 20000, promotion = 1, level = 20}, text = 'Congratulations! You are now promoted.')
		-- 		node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, text = 'Alright then, come back when you are ready.'}, reset = true)
	function StdModule.promotePlayer(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.promotePlayer called without any npcHandler instance.')
		end
		if(not npcHandler:isFocused(cid)) then
			return false
		end

		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
			if(getPlayerPromotionLevel(cid) >= parameters.promotion) then
				npcHandler:say('You are already promoted!', cid)
			elseif(getPlayerLevel(cid) < parameters.level) then
				npcHandler:say('I am sorry, but I can only promote you once you have reached level ' .. parameters.level .. '.', cid)
			elseif(doPlayerRemoveMoney(cid, parameters.cost) ~= TRUE) then
				npcHandler:say('You do not have enough money!', cid)
			else
				setPlayerPromotionLevel(cid, parameters.promotion)
				npcHandler:say(parameters.text, cid)
			end
		else
			npcHandler:say("You need a premium account in order to get promoted.", cid)
		end
		npcHandler:resetNpc()
		return true
	end

	function StdModule.learnSpell(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.buySpell called without any npcHandler instance.')
		end
		if(not npcHandler:isFocused(cid)) then
			return false
		end

		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
			if getPlayerLearnedInstantSpell(cid, parameters.spellName) == TRUE then
				npcHandler:say('You already know this spell.', cid)
			elseif getPlayerLevel(cid) < parameters.level then
				npcHandler:say('You need to obtain a level of ' .. parameters.level .. ' or higher to be able to learn ' .. parameters.spellName .. '.', cid)
			elseif getPlayerVocation(cid) ~= parameters.vocation and getPlayerVocation(cid) ~= parameters.vocation + 4 and vocation ~= 9 then
				npcHandler:say('This spell is not for your vocation', cid)
			elseif doPlayerRemoveMoney(cid, parameters.price) == FALSE then
				npcHandler:say('You do not have enough money, this spell costs ' .. parameters.price .. ' gold.', cid)
			else
				npcHandler:say('You have learned ' .. parameters.spellName .. '.', cid)
				playerLearnInstantSpell(cid, parameters.spellName)
			end
		else
			npcHandler:say('You need a premium account in order to buy ' .. parameters.spellName .. '.', cid)
		end
		npcHandler:resetNpc()
		return true
	end

	function StdModule.bless(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.bless called without any npcHandler instance.')
		end
		if(not npcHandler:isFocused(cid)) then
			return false
		end

		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
			if getPlayerBlessing(cid, parameters.bless) then
				npcHandler:say("Gods have already blessed you with this blessing!", cid)
			elseif doPlayerRemoveMoney(cid, parameters.cost) == FALSE then
				npcHandler:say("You don't have enough money for blessing.", cid)
			else
				npcHandler:say("You have been blessed by one of the five gods!", cid)
				doPlayerAddBlessing(cid, parameters.bless)
			end
		else
			npcHandler:say('You need a premium account in order to be blessed.', cid)
		end
		npcHandler:resetNpc()
		return true
	end

	function StdModule.travel(cid, message, keywords, parameters, node)
		local npcHandler = parameters.npcHandler
		if(npcHandler == nil) then
			error('StdModule.travel called without any npcHandler instance.')
		end
		if(not npcHandler:isFocused(cid)) then
			return false
		end
		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium == false) then
			if(parameters.level ~= nil and getPlayerLevel(cid) < parameters.level) then
				npcHandler:say('You must reach level ' .. parameters.level .. ' before I can let you go there.', cid)
			elseif(doPlayerRemoveMoney(cid, parameters.cost) ~= TRUE) then
				npcHandler:say('You do not have enough money!', cid)
			else
				doTeleportThing(cid, parameters.destination, 0)
				doSendMagicEffect(parameters.destination, 10)
			end
		else
			npcHandler:say('I can only allow premium players to travel with me.', cid)
		end
		npcHandler:resetNpc()
		return true
	end

	FocusModule = {
		npcHandler = nil
	}

	-- Creates a new instance of FocusModule without an associated NpcHandler.
	function FocusModule:new()
		local obj = {}
		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	-- Inits the module and associates handler to it.
	function FocusModule:init(handler)
		self.npcHandler = handler
		for i, word in pairs(FOCUS_GREETWORDS) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = FOCUS_GREETWORDS.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onGreet, {module = self})
		end

		for i, word in pairs(FOCUS_FAREWELLWORDS) do
			local obj = {}
			table.insert(obj, word)
			obj.callback = FOCUS_FAREWELLWORDS.callback or FocusModule.messageMatcher
			handler.keywordHandler:addKeyword(obj, FocusModule.onFarewell, {module = self})
		end

		return true
	end

	-- Greeting callback function.
	function FocusModule.onGreet(cid, message, keywords, parameters)
		parameters.module.npcHandler:onGreet(cid)
		return true
	end

	-- UnGreeting callback function.
	function FocusModule.onFarewell(cid, message, keywords, parameters)
		if(parameters.module.npcHandler:isFocused(cid)) then
			parameters.module.npcHandler:onFarewell(cid)
			return true
		else
			return false
		end
	end

	-- Custom message matching callback function for greeting messages.
	function FocusModule.messageMatcher(keywords, message)
		for i, word in pairs(keywords) do
			if(type(word) == 'string') then
				if string.find(message, word) and not string.find(message, '[%w+]' .. word) and not string.find(message, word .. '[%w+]') then
					return true
				end
			end
		end
		return false
	end

	KeywordModule = {
		npcHandler = nil
	}
	-- Add it to the parseable module list.
	Modules.parseableModules['module_keywords'] = KeywordModule

	function KeywordModule:new()
		local obj = {}
		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	function KeywordModule:init(handler)
		self.npcHandler = handler
		return true
	end

	-- Parses all known parameters.
	function KeywordModule:parseParameters()
		local ret = NpcSystem.getParameter('keywords')
		if(ret ~= nil) then
			self:parseKeywords(ret)
		end
	end

	function KeywordModule:parseKeywords(data)
		local n = 1
		for keys in string.gmatch(data, '[^;]+') do
			local i = 1

			local keywords = {}

			for temp in string.gmatch(keys, '[^,]+') do
				table.insert(keywords, temp)
				i = i+1
			end

			if(i ~= 1) then
				local reply = NpcSystem.getParameter('keyword_reply' .. n)
				if(reply ~= nil) then
					self:addKeyword(keywords, reply)
				else
					print('[Warning] NpcSystem:', 'Parameter \'' .. 'keyword_reply' .. n .. '\' missing. Skipping...')
				end
			else
				print('[Warning] NpcSystem:', 'No keywords found for keyword set #' .. n .. '. Skipping...')
			end
			n = n+1
		end
	end

	function KeywordModule:addKeyword(keywords, reply)
		self.npcHandler.keywordHandler:addKeyword(keywords, StdModule.say, {npcHandler = self.npcHandler, onlyFocus = true, text = reply, reset = true})
	end

	TravelModule = {
		npcHandler = nil,
		destinations = nil,
		yesNode = nil,
		noNode = nil,
	}
	-- Add it to the parseable module list.
	Modules.parseableModules['module_travel'] = TravelModule

	function TravelModule:new()
		local obj = {}
		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	function TravelModule:init(handler)
		self.npcHandler = handler
		self.yesNode = KeywordNode:new(SHOP_YESWORD, TravelModule.onConfirm, {module = self})
		self.noNode = KeywordNode:new(SHOP_NOWORD, TravelModule.onDecline, {module = self})
		self.destinations = {}
		return true
	end

	-- Parses all known parameters.
	function TravelModule:parseParameters()
		local ret = NpcSystem.getParameter('travel_destinations')
		if(ret ~= nil) then
			self:parseDestinations(ret)

			self.npcHandler.keywordHandler:addKeyword({'destination'}, TravelModule.listDestinations, {module = self})
			self.npcHandler.keywordHandler:addKeyword({'where'}, TravelModule.listDestinations, {module = self})
			self.npcHandler.keywordHandler:addKeyword({'travel'}, TravelModule.listDestinations, {module = self})

		end
	end

	function TravelModule:parseDestinations(data)
		for destination in string.gmatch(data, '[^;]+') do
			local i = 1

			local name = nil
			local x = nil
			local y = nil
			local z = nil
			local cost = nil
			local premium = false

			for temp in string.gmatch(destination, '[^,]+') do
				if(i == 1) then
					name = temp
				elseif(i == 2) then
					x = tonumber(temp)
				elseif(i == 3) then
					y = tonumber(temp)
				elseif(i == 4) then
					z = tonumber(temp)
				elseif(i == 5) then
					cost = tonumber(temp)
				elseif(i == 6) then
					premium = temp == 'true'
				else
					print('[Warning] NpcSystem:', 'Unknown parameter found in travel destination parameter.', temp, destination)
				end
				i = i+1
			end

			if(name ~= nil and x ~= nil and y ~= nil and z ~= nil and cost ~= nil) then
				self:addDestination(name, {x=x, y=y, z=z}, cost, premium)
			else
				print('[Warning] NpcSystem:', 'Parameter(s) missing for travel destination:', name, x, y, z, cost, premium)
			end
		end
	end

	function TravelModule:addDestination(name, position, price, premium)
		table.insert(self.destinations, name)

		local parameters = {
			cost = price,
			destination = position,
			premium = premium,
			module = self
		}
		local keywords = {}
		table.insert(keywords, name)

		local keywords2 = {}
		table.insert(keywords2, 'bring me to ' .. name)
		local node = self.npcHandler.keywordHandler:addKeyword(keywords, TravelModule.travel, parameters)
		self.npcHandler.keywordHandler:addKeyword(keywords2, TravelModule.bringMeTo, parameters)
		node:addChildKeywordNode(self.yesNode)
		node:addChildKeywordNode(self.noNode)
	end

	function TravelModule.travel(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local npcHandler = module.npcHandler

		local cost = parameters.cost
		local destination = parameters.destination
		local premium = parameters.premium

		module.npcHandler:say('Do you want to travel to ' .. keywords[1] .. ' for ' .. cost .. ' gold coins?', cid)
		return true

	end

	function TravelModule.onConfirm(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local npcHandler = module.npcHandler

		local parentParameters = node:getParent():getParameters()
		local cost = parentParameters.cost
		local destination = parentParameters.destination
		local premium = parentParameters.premium

		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium ~= true) then
			if(doPlayerRemoveMoney(cid, cost) ~= TRUE) then
				npcHandler:say('You do not have enough money!', cid)
			else
				npcHandler:say('It was a pleasure doing business with you.', cid)
				npcHandler:releaseFocus(cid)
				doTeleportThing(cid, destination, 0)
				doSendMagicEffect(destination, 10)
			end
		else
			npcHandler:say('I can only allow premium players to travel there.', cid)
		end

		npcHandler:resetNpc()
		return true
	end

	-- onDecline keyword callback function. Generally called when the player sais 'no' after wanting to buy an item.
	function TravelModule.onDecline(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end
		local parentParameters = node:getParent():getParameters()
		local parseInfo = {
			[TAG_PLAYERNAME] = getCreatureName(cid),
		}
		local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_DECLINE), parseInfo)
		module.npcHandler:say(msg, cid)
		module.npcHandler:resetNpc()
		return true
	end

	function TravelModule.bringMeTo(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local cost = parameters.cost
		local destination = parameters.destination
		local premium = parameters.premium

		if(isPlayerPremiumCallback == nil or isPlayerPremiumCallback(cid) == true or parameters.premium ~= true) then
			if(doPlayerRemoveMoney(cid, cost) == TRUE) then
				doTeleportThing(cid, destination, 0)
				doSendMagicEffect(destination, 10)
			end
		end
		return true
	end

	function TravelModule.listDestinations(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local msg = 'I can bring you to '
		--local i = 1
		local maxn = table.maxn(module.destinations)
		for i, destination in pairs(module.destinations) do
			msg = msg .. destination
			if(i == maxn -1) then
				msg = msg .. ' and '
			elseif(i == maxn) then
				msg = msg .. '.'
			else
				msg = msg .. ', '
			end
			i = i + 1
		end

		module.npcHandler:say(msg, cid)
		module.npcHandler:resetNpc()
		return true
	end

	ShopModule = {
		npcHandler = nil,
		yesNode = nil,
		noNode = nil,
		noText = '',
		maxCount = 100,
		amount = 0
	}

	-- Add it to the parseable module list.
	Modules.parseableModules['module_shop'] = ShopModule

	-- Creates a new instance of ShopModule
	function ShopModule:new()
		local obj = {}
		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	-- Parses all known parameters.
	function ShopModule:parseParameters()
		local ret = NpcSystem.getParameter('shop_buyable')
		if(ret ~= nil) then
			self:parseBuyable(ret)
		end

		local ret = NpcSystem.getParameter('shop_sellable')
		if(ret ~= nil) then
			self:parseSellable(ret)
		end

		local ret = NpcSystem.getParameter('shop_buyable_containers')
		if(ret ~= nil) then
			self:parseBuyableContainers(ret)
		end
	end

	-- Parse a string contaning a set of buyable items.
	function ShopModule:parseBuyable(data)
		for item in string.gmatch(data, '[^;]+') do
			local i = 1

			local name = nil
			local itemid = nil
			local cost = nil
			local subType = nil
			local realName = nil

			for temp in string.gmatch(item, '[^,]+') do
				if(i == 1) then
					name = temp
				elseif(i == 2) then
					itemid = tonumber(temp)
				elseif(i == 3) then
					cost = tonumber(temp)
				elseif(i == 4) then
					subType = tonumber(temp)
				elseif(i == 5) then
					realName = temp
				else
					print('[Warning] NpcSystem:', 'Unknown parameter found in buyable items parameter.', temp, item)
				end
				i = i + 1
			end

			if(SHOPMODULE_MODE == SHOPMODULE_MODE_TRADE) then
				if(itemid ~= nil and cost ~= nil) then
					if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
						print('[Warning] NpcSystem:', 'SubType missing for parameter item:', item)
					else
						self:addBuyableItem(nil, itemid, cost, subType, realName)
					end
				else
					print('[Warning] NpcSystem:', 'Parameter(s) missing for item:', itemid, cost)
				end
			else
				if(name ~= nil and itemid ~= nil and cost ~= nil) then
					if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
						print('[Warning] NpcSystem:', 'SubType missing for parameter item:', item)
					else
						local names = {}
						table.insert(names, name)
						self:addBuyableItem(names, itemid, cost, subType, realName)
					end
				else
					print('[Warning] NpcSystem:', 'Parameter(s) missing for item:', name, itemid, cost)
				end
			end
		end
	end

	-- Parse a string contaning a set of sellable items.
	function ShopModule:parseSellable(data)
		for item in string.gmatch(data, '[^;]+') do
			local i = 1

			local name = nil
			local itemid = nil
			local cost = nil
			local realName = nil

			for temp in string.gmatch(item, '[^,]+') do
				if(i == 1) then
					name = temp
				elseif(i == 2) then
					itemid = tonumber(temp)
				elseif(i == 3) then
					cost = tonumber(temp)
				elseif(i == 4) then
					realName = temp
				else
					print('[Warning] NpcSystem:', 'Unknown parameter found in sellable items parameter.', temp, item)
				end
				i = i + 1
			end

			if(SHOPMODULE_MODE == SHOPMODULE_MODE_TRADE) then
				if(itemid ~= nil and cost ~= nil) then
					self:addSellableItem(nil, itemid, cost, realName)
				else
					print('[Warning] NpcSystem:', 'Parameter(s) missing for item:', itemid, cost)
				end
			else
				if(name ~= nil and itemid ~= nil and cost ~= nil) then
					local names = {}
					table.insert(names, name)
					self:addSellableItem(names, itemid, cost, realName)
				else
					print('[Warning] NpcSystem:', 'Parameter(s) missing for item:', name, itemid, cost)
				end
			end
		end
	end

	-- Parse a string contaning a set of buyable items.
	function ShopModule:parseBuyableContainers(data)
		for item in string.gmatch(data, '[^;]+') do
			local i = 1

			local name = nil
			local container = nil
			local itemid = nil
			local cost = nil
			local subType = nil
			local realName = nil

			for temp in string.gmatch(item, '[^,]+') do
				if(i == 1) then
					name = temp
				elseif(i == 2) then
					itemid = tonumber(temp)
				elseif(i == 3) then
					itemid = tonumber(temp)
				elseif(i == 4) then
					cost = tonumber(temp)
				elseif(i == 5) then
					subType = tonumber(temp)
				elseif(i == 6) then
					realName = temp
				else
					print('[Warning] NpcSystem:', 'Unknown parameter found in buyable items parameter.', temp, item)
				end
				i = i + 1
			end

			if(name ~= nil and container ~= nil and itemid ~= nil and cost ~= nil) then
				if((isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) and subType == nil) then
					print('[Warning] NpcSystem:', 'SubType missing for parameter item:', item)
				else
					local names = {}
					table.insert(names, name)
					self:addBuyableItemContainer(names, container, itemid, cost, subType, realName)
				end
			else
				print('[Warning] NpcSystem:', 'Parameter(s) missing for item:', name, container, itemid, cost)
			end
		end
	end

	-- Initializes the module and associates handler to it.
	function ShopModule:init(handler)
		self.npcHandler = handler
		self.yesNode = KeywordNode:new(SHOP_YESWORD, ShopModule.onConfirm, {module = self})
		self.noNode = KeywordNode:new(SHOP_NOWORD, ShopModule.onDecline, {module = self})
		self.noText = handler:getMessage(MESSAGE_DECLINE)

		if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
			for i, word in pairs(SHOP_TRADEREQUEST) do
				local obj = {}
				table.insert(obj, word)
				obj.callback = SHOP_TRADEREQUEST.callback or ShopModule.messageMatcher
				handler.keywordHandler:addKeyword(obj, ShopModule.requestTrade, {module = self})
			end
		end

		return true
	end

	-- Custom message matching callback function for requesting trade messages.
	function ShopModule.messageMatcher(keywords, message)
		for i, word in pairs(keywords) do
			if(type(word) == 'string') then
				if string.find(message, word) and not string.find(message, '[%w+]' .. word) and not string.find(message, word .. '[%w+]') then
					return true
				end
			end
		end
		return false
	end

	-- Resets the module-specific variables.
	function ShopModule:reset()
		self.amount = 0
	end

	-- Function used to match a number value from a string.
	function ShopModule:getCount(message)
		local ret = 1
		local b, e = string.find(message, PATTERN_COUNT)
		if b ~= nil and e ~= nil then
			ret = tonumber(string.sub(message, b, e))
		end

		if(ret <= 0) then
			ret = 1
		elseif(ret > self.maxCount) then
			ret = self.maxCount
		end

		return ret
	end

	-- Adds a new buyable item.
	--	names = A table containing one or more strings of alternative names to this item. Used only for old buy/sell system.
	--	itemid = The itemid of the buyable item
	--	cost = The price of one single item
	--	subType - The subType of each rune or fluidcontainer item. Can be left out if it is not a rune/fluidcontainer. Default value is 0.
	--	realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemNameById will be used)

function ShopModule:buyContainer(names, container, itemid, cost, charges, realname)
		for i, name in pairs(names) do
			local parameters = {
			        container = container,
					itemid = itemid,
					cost = cost,
					charges = charges,
					eventType = SHOPMODULE_BUY_CONTAINER,
					module = self
				}
			if(realname ~= nil) then
				parameters.realname = realname
			end
			if(isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) then
				parameters.charges = charges
			end
			keywords = {}
			table.insert(keywords, name)
			local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
			node:addChildKeywordNode(self.yesNode)
			node:addChildKeywordNode(self.noNode)
		end
	end

	function ShopModule:addBuyableItem(names, itemid, cost, subType, realName)
		if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
			if(self.npcHandler.shopItems[itemid] == nil) then
				self.npcHandler.shopItems[itemid] = {buyPrice = 0, sellPrice = 0, subType = 0, realName = ""}
			end

			self.npcHandler.shopItems[itemid].buyPrice = cost
			self.npcHandler.shopItems[itemid].realName = realName or getItemNameById(itemid)
			self.npcHandler.shopItems[itemid].subType = subType or 0
		end

		if(names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE) then
			for i, name in pairs(names) do
				local parameters = {
						itemid = itemid,
						cost = cost,
						eventType = SHOPMODULE_BUY_ITEM,
						module = self,
						realName = realName or getItemNameById(itemid),
						subType = subType or 1
					}

				keywords = {}
				table.insert(keywords, 'buy')
				table.insert(keywords, name)
				local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
				node:addChildKeywordNode(self.yesNode)
				node:addChildKeywordNode(self.noNode)
			end
		end
	end

	-- Adds a new buyable container of items.
	--	names = A table containing one or more strings of alternative names to this item.
	--	container = Backpack, bag or any other itemid of container where bought items will be stored
	--	itemid = The itemid of the buyable item
	--	cost = The price of one single item
	--	subType - The subType of each rune or fluidcontainer item. Can be left out if it is not a rune/fluidcontainer. Default value is 0.
	--	realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemNameById will be used)
	function ShopModule:addBuyableItemContainer(names, container, itemid, cost, subType, realName)
		if(names ~= nil) then
			for i, name in pairs(names) do
				local parameters = {
						container = container,
						itemid = itemid,
						cost = cost,
						eventType = SHOPMODULE_BUY_ITEM_CONTAINER,
						module = self,
						realName = realName or getItemNameById(itemid),
						subType = subType or 1
					}

				keywords = {}
				table.insert(keywords, 'buy')
				table.insert(keywords, name)
				local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
				node:addChildKeywordNode(self.yesNode)
				node:addChildKeywordNode(self.noNode)
			end
		end
	end

	-- Adds a new sellable item.
	--	names = A table containing one or more strings of alternative names to this item. Used only by old buy/sell system.
	--	itemid = The itemid of the sellable item
	--	cost = The price of one single item
	--	realName - The real, full name for the item. Will be used as ITEMNAME in MESSAGE_ONBUY and MESSAGE_ONSELL if defined. Default value is nil (getItemNameById will be used)
	function ShopModule:addSellableItem(names, itemid, cost, realName)
		if(SHOPMODULE_MODE ~= SHOPMODULE_MODE_TALK) then
			if(self.npcHandler.shopItems[itemid] == nil) then
				self.npcHandler.shopItems[itemid] = {buyPrice = 0, sellPrice = 0, subType = 0, realName = ""}
			end

			self.npcHandler.shopItems[itemid].sellPrice = cost
			self.npcHandler.shopItems[itemid].realName = realName or getItemNameById(itemid)
		end

		if(names ~= nil and SHOPMODULE_MODE ~= SHOPMODULE_MODE_TRADE) then
			for i, name in pairs(names) do
				local parameters = {
						itemid = itemid,
						cost = cost,
						eventType = SHOPMODULE_SELL_ITEM,
						module = self,
						realName = realName or getItemNameById(itemid)
					}

				keywords = {}
				table.insert(keywords, 'sell')
				table.insert(keywords, name)
				local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
				node:addChildKeywordNode(self.yesNode)
				node:addChildKeywordNode(self.noNode)
			end
		end
	end

	-- onModuleReset callback function. Calls ShopModule:reset()
	function ShopModule:callbackOnModuleReset()
		self:reset()
		return true
	end

	-- doPlayerAddItem function variation. Used specifically for NPCs.
	ShopModule.doPlayerAddItem = function(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)
		local amount = amount or 1
		local subType = subType or 0
		local ignoreCap = ignoreCap and TRUE or FALSE
		local backpack = backpack or 1988

		local item = 0
		if(isItemStackable(itemid) == TRUE) then
			item = doCreateItemEx(itemid, amount)
			if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
				return 0, 0
			end

			return amount, 0
		end

		local a = 0
		if(inBackpacks) then
			local container = doCreateItemEx(backpack, 1)
			for i = 1, amount do
				item = doAddContainerItem(container, itemid, subType)
				if(itemid == ITEM_PARCEL) then
					doAddContainerItem(item, ITEM_LABEL)
				end

				if(isInArray({20, amount}, i) == TRUE) then
					if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then
						break
					end
					a = a + i

					if(amount > i) then
						container = doCreateItemEx(backpack, 1)
					end
				end
			end
			return a, b
		end

		for i = 1, amount do
			item = doCreateItemEx(itemid, subType)
			if(itemid == ITEM_PARCEL) then
				doAddContainerItem(item, ITEM_LABEL)
			end

			if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then
				break
			end
			a = a + 1
		end
		return a, 0
	end

	-- Callback onBuy() function. If you wish, you can change certain Npc to use your onBuy().
	function ShopModule:callbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks)
		if(self.npcHandler.shopItems[itemid] == nil) then
			error("[ShopModule.onBuy]", "items[itemid] == nil")
			return false
		end

		local totalCost = amount * self.npcHandler.shopItems[itemid].buyPrice
		if(inBackpacks) then
			totalCost = totalCost + (math.max(1, math.floor(amount / 20)) * 20)
		end

		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = amount,
			[TAG_TOTALCOST] = totalCost,
			[TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
		}

		if(getPlayerMoney(cid) < totalCost) then
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDMONEY)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendCancel(cid, msg)
			return false
		end

		local a, b = ShopModule.doPlayerAddItem(cid, itemid, amount, subType, ignoreCap, inBackpacks)
		if(a < amount) then
			local msgId = MESSAGE_NEEDMORESPACE
			if(a == 0) then
				msgId = MESSAGE_NEEDSPACE
			end

			local msg = self.npcHandler:getMessage(msgId)
			parseInfo[TAG_ITEMCOUNT] = a
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendCancel(cid, msg)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			if(a > 0) then
				doPlayerRemoveMoney(cid, ((a * self.npcHandler.shopItems[itemid].buyPrice) + b * 20))
				return true
			end
			return false
		else
			local msg = self.npcHandler:getMessage(MESSAGE_BOUGHT)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
			doPlayerRemoveMoney(cid, totalCost)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return true
		end
	end

	-- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
	function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
		if(self.npcHandler.shopItems[itemid] == nil) then
			error("[ShopModule.onSell]", "items[itemid] == nil")
			return false
		end

		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = amount,
			[TAG_TOTALCOST] = amount * self.npcHandler.shopItems[itemid].sellPrice,
			[TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
		}

		if(subType < 1) then
			subType = -1
		end
		if(doPlayerRemoveItem(cid, itemid, amount, subType) == TRUE) then
			local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
			doPlayerAddMoney(cid, amount * self.npcHandler.shopItems[itemid].sellPrice)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return true
		else
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendCancel(cid, msg)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return false
		end
	end

	-- Callback for requesting a trade window with the NPC.
	function ShopModule.requestTrade(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local itemWindow = {}
		for itemid, attr in pairs(module.npcHandler.shopItems) do
			local item = {id = itemid, buy = attr.buyPrice, sell = attr.sellPrice, subType = attr.subType, name = attr.realName}
			table.insert(itemWindow, item)
		end

		if(itemWindow[1] == nil) then
			local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
			local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_NOSHOP), parseInfo)
			module.npcHandler:say(msg, cid)
			return true
		end

		local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
		local msg = module.npcHandler:parseMessage(module.npcHandler:getMessage(MESSAGE_SENDTRADE), parseInfo)
		openShopWindow(cid, itemWindow,
			function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) end,
			function(cid, itemid, subType, amount, ignoreCap, inBackpacks) module.npcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) end)
		module.npcHandler:say(msg, cid)
		return true
	end

	-- onConfirm keyword callback function. Sells/buys the actual item.
	function ShopModule.onConfirm(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local parentParameters = node:getParent():getParameters()
		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = module.amount,
			[TAG_TOTALCOST] = parentParameters.cost * module.amount,
			[TAG_ITEMNAME] = parentParameters.realName
		}

		if(parentParameters.eventType == SHOPMODULE_SELL_ITEM) then
			local ret = doPlayerSellItem(cid, parentParameters.itemid, module.amount, parentParameters.cost * module.amount)
			if(ret == LUA_NO_ERROR) then
				local msg = module.npcHandler:getMessage(MESSAGE_ONSELL)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			else
				local msg = module.npcHandler:getMessage(MESSAGE_MISSINGITEM)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			end
		elseif(parentParameters.eventType == SHOPMODULE_BUY_ITEM) then
			local ret = doPlayerBuyItem(cid, parentParameters.itemid, module.amount, parentParameters.cost * module.amount, parentParameters.subType)
			if(ret == LUA_NO_ERROR) then
				if parentParameters.itemid == ITEM_PARCEL then
					doPlayerBuyItem(cid, ITEM_LABEL, module.amount, 0, parentParameters.subType)
				end
				local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			else
				local msg = module.npcHandler:getMessage(MESSAGE_MISSINGMONEY)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			end
		elseif(parentParameters.eventType == SHOPMODULE_BUY_ITEM_CONTAINER) then
			local ret = doPlayerBuyItemContainer(cid, parentParameters.container, parentParameters.itemid, module.amount, parentParameters.cost * module.amount, parentParameters.subType)
			if(ret == LUA_NO_ERROR) then
				local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			else
				local msg = module.npcHandler:getMessage(MESSAGE_MISSINGMONEY)
				msg = module.npcHandler:parseMessage(msg, parseInfo)
				module.npcHandler:say(msg, cid)
			end
		end

		module.npcHandler:resetNpc()
		return true
	end

	-- onDecliune keyword callback function. Generally called when the player sais 'no' after wanting to buy an item.
	function ShopModule.onDecline(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local parentParameters = node:getParent():getParameters()
		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = module.amount,
			[TAG_TOTALCOST] = parentParameters.cost * module.amount,
			[TAG_ITEMNAME] = parentParameters.realName
		}

		local msg = module.npcHandler:parseMessage(module.noText, parseInfo)
		module.npcHandler:say(msg, cid)
		module.npcHandler:resetNpc()
		return true
	end

	-- tradeItem callback function. Makes the npc say the message defined by MESSAGE_BUY or MESSAGE_SELL
	function ShopModule.tradeItem(cid, message, keywords, parameters, node)
		local module = parameters.module
		if(not module.npcHandler:isFocused(cid)) then
			return false
		end

		local count = module:getCount(message)
		module.amount = count
		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = module.amount,
			[TAG_TOTALCOST] = parameters.cost * module.amount,
			[TAG_ITEMNAME] = parameters.realName
		}

		if(parameters.eventType == SHOPMODULE_SELL_ITEM) then
			local msg = module.npcHandler:getMessage(MESSAGE_SELL)
			msg = module.npcHandler:parseMessage(msg, parseInfo)
			module.npcHandler:say(msg, cid)
		elseif(parameters.eventType == SHOPMODULE_BUY_ITEM) then
			local msg = module.npcHandler:getMessage(MESSAGE_BUY)
			msg = module.npcHandler:parseMessage(msg, parseInfo)
			module.npcHandler:say(msg, cid)
		elseif(parameters.eventType == SHOPMODULE_BUY_CONTAINER) then
			tmpName = node:getKeywords()[3]
		elseif(parameters.eventType == SHOPMODULE_BUY_ITEM_CONTAINER) then
			local msg = module.npcHandler:getMessage(MESSAGE_BUY)
			msg = module.npcHandler:parseMessage(msg, parseInfo)
			module.npcHandler:say(msg, cid)
		end
		return true
	end
end

Backup your old modules.lua if this isnt working...
 
i made it work. I think i got small letter made in "shopModule"

But there is next bug. When i want to buy bp of ... it buy me just one rune.
When i pute bp runes on first lines it works. But... when u buy too much bps to your eq... it sell all bps for all money but u lose some bps if u dont have capacity etc.

And why when i buy something on trade i get it in backpack and twice...
 
Last edited:
Back
Top Bottom