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

The Forgotten Server v0.3 (alpha 2)

Status
Not open for further replies.
ok thx very much i wait on relase:)

and i have question can whos me say what i must do whn i want add npc system on priv to lua or xml;/
 
Last edited:
Alpha 3 soon?
Cant wait,

I plan on updateing to this version.
 
What does "Servers.xml" do?

Content:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<servers>
	<server id="1" name="Example" ip="127.0.0.1" port="7171"/>
</servers>


And 2 of my npcs seems to be bugged...

Error:
Code:
[14/10/2008  18:49:48] Lua Script Error: [Npc interface] 
[14/10/2008  18:49:48] data/npc/scripts/shops/rune shop.lua

[14/10/2008  18:49:48] data/npc/lib/npcsystem/npchandler.lua:285: table index is nil
[14/10/2008  18:49:48] [Warning - NpcScript::NpcScript] Can not load script: data/npc/scripts/shops/rune shop.lua

Lua file:
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

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

--max
shopModule:addSellableItem({'normal potion flask', 'normal flask'}, 7636, 5, 'empty small potion flask')
shopModule:addSellableItem({'strong potion flask', 'strong flask'}, 7634, 10, 'empty strong potion flask')

shopModule:addBuyableItemContainer({'bp mp'}, 2001, 7620, 1020, 1, 'backpack of mana potion')
shopModule:addBuyableItemContainer({'bp smp'}, 2001, 7620, 1620, 1, 'backpack of strong mana potion')
shopModule:addBuyableItemContainer({'bp hmm'}, 2001, 2311, 2420, 10, 'backpack of heavy magic missile')
shopModule:addBuyableItemContainer({'bp gfb'}, 2001, 2304, 3620, 4, 'backpack of great fireball')
shopModule:addBuyableItemContainer({'bp explo'}, 2001, 2313, 3820, 6, 'backpack of explosion runes')
shopModule:addBuyableItemContainer({'bp uh'}, 2001, 2273, 3520, 1, 'backpack of ultimate healing runes')
shopModule:addBuyableItemContainer({'bp sd'}, 2001, 2268, 6520, 2, 'backpack of sudden death runes')
shopModule:addBuyableItemContainer({'bp blank'}, 2001, 2260, 10, 1, 'backpack of blank runes')
shopModule:addBuyableItemContainer({'bp df'}, 2001, 2261, 920, 3, 'backpack of destroy field runes')
shopModule:addBuyableItemContainer({'bp mwall'}, 2001, 2293, 7020, 3, 'backpack of magic wall runes')

shopModule:addBuyableItem({'light wand', 'lightwand'},		2163, 500,		'magic light wand')
shopModule:addBuyableItem({'mana fluid', 'manafluid'},		2006, 50,	7,	'mana fluid')
shopModule:addBuyableItem({'life fluid', 'lifefluid'},		2006, 50,	10,	'life fluid')
shopModule:addBuyableItem({'wand of vortex', 'wov'},		2190, 50,		'wand of vortex')
shopModule:addBuyableItem({'wand of dragonbreath', 'wod'},	2191, 400,		'wand of dragonbreath')
shopModule:addBuyableItem({'wand of decay', 'wod'},		2188, 2000,		'wand of decay')
shopModule:addBuyableItem({'wand of cosmic energy', 'woce'},	2189, 4000,		'wand of cosmic energy')
shopModule:addBuyableItem({'wand of inferno', 'woi'},		2187, 7500,		'wand of inferno')
shopModule:addBuyableItem({'snakebite rod', 'kebabta'},		2182, 50,		'snakebite rod')
shopModule:addBuyableItem({'monlight rod', 'mr'},		2186, 400,		'moonlight rod')
shopModule:addBuyableItem({'necrotic rod', 'nr'},		2185, 2000,		'necrotic rod')
shopModule:addBuyableItem({'terra rod', 'kebabta'},			2181, 4000,		'terra rod')
shopModule:addBuyableItem({'hailstorm rod', 'hr'},		2183, 7500,		'hailstorm rod rod')

shopModule:addBuyableItem({'heavy magic missile', 'hmm'},	2311, 120,	10,	'heavy magic missile rune')
shopModule:addBuyableItem({'great fireball', 'gfb'},		2304, 180,	4,	'great fireball rune')
shopModule:addBuyableItem({'explo', 'xpl'},			2313, 190,	6,	'explosion rune')
shopModule:addBuyableItem({'ultimate healing', 'uh'},		2273, 175,	1,	'ultimate healing rune')
shopModule:addBuyableItem({'sudden death', 'sd'},		2268, 325,	2,	'sudden death rune')
shopModule:addBuyableItem({'blank', 'rune'},			2260, 10,		'blank rune')
shopModule:addBuyableItem({'animate dead', 'kebabta'},		2316, 375,	1,	'animate dead rune')
shopModule:addBuyableItem({'antidote', 'kebabta'},		2266, 65,	1,	'antidote rune')
shopModule:addBuyableItem({'avalanche', 'aval'},		2274, 180,	4,	'avalanche rune')
shopModule:addBuyableItem({'chamelon', 'kebabta'},		2291, 210,	1,	'chamelon rune')
shopModule:addBuyableItem({'desintegrate', 'kebabta'},		2310, 80,	3,	'desintegrate rune')
shopModule:addBuyableItem({'destroy field', 'df'},		2261, 45,	3,	'destroy field rune')
shopModule:addBuyableItem({'energy bomb', 'ebomb'},		2262, 325,	2,	'energy bomb rune')
shopModule:addBuyableItem({'energy field', 'kebabta'},		2277, 115,	3,	'desintegrate rune')
shopModule:addBuyableItem({'energy wall', 'ewall'},		2279, 340,	4,	'energy wall rune')
shopModule:addBuyableItem({'firebomb', 'fbomb'},		2305, 235,	2,	'fire bomb rune')
shopModule:addBuyableItem({'fire field', 'kebabta'},			2301, 85,	3,	'fire field rune')
shopModule:addBuyableItem({'fire wall', 'fwall'},		2303, 245,	4,	'fire wall rune')
shopModule:addBuyableItem({'fireball', 'fball'},		2302, 150,	5,	'fireball rune')
shopModule:addBuyableItem({'icicle', 'kebabta'},				2271, 150,	5,	'icicle rune')
shopModule:addBuyableItem({'intense healing', 'ih'},	2265, 95,	1,	'intense healing rune')
shopModule:addBuyableItem({'light magic missilie', 'lmm'},		2287, 40,	10,	'light magic missile rune')
shopModule:addBuyableItem({'magic wall', 'mwall'},		2293, 350,	3,	'magic wall rune')
shopModule:addBuyableItem({'paralyze', 'kebabta'},			2278, 700,	1,	'paralyze rune')
shopModule:addBuyableItem({'poison bomb', 'pbomb'},		2286, 170,	2,	'poison bomb rune')
shopModule:addBuyableItem({'poison field', 'pfield'},	2285, 65,	3,	'poison field rune')
shopModule:addBuyableItem({'poison wall', 'pwall'},		2289, 210,	4,	'poison wall rune')
shopModule:addBuyableItem({'soulfire', 'kebabta'},			2308, 140,	3,	'soulfire rune')
shopModule:addBuyableItem({'stalagmite', 'kebabta'},			2292, 120,	10,	'stalagmite rune')
shopModule:addBuyableItem({'stone shower', 'kebabta'},		2288, 150,	4,	'stone shower rune')
shopModule:addBuyableItem({'thunderstorm', 'kebabta'},		2315, 150,	4,	'tunderstorm rune')
shopModule:addBuyableItem({'spellbook', 'Kekkaka'},		2175, 150,	1,	'spell book')

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

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Npc XML file:

Code:
<npc name="Anglesea Walk" script="data/npc/scripts/shops/rune shop.lua" walkinterval="4500" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="141" head="57" body="22" legs="96" feet="114" addons="1"/>
    <parameters>
        <parameter key="message_greet" value="Hello and welcome |PLAYERNAME|. What might possibly bring you to my shop today?" />
        <parameter key="message_needmoremoney" value="You do not have enough money." />
 

        	<parameter key="module_keywords" value="1" />
        	<parameter key="keywords" value="job;name;offer;dwarves;rods;wands;runes;dwarfs" />
        	<parameter key="keyword_reply1" value="My job is simply to serve this city as a punishment" />
        	<parameter key="keyword_reply2" value="Hehe. I don't like my second name either..." />
        	<parameter key="keyword_reply3" value="I have alot of runes, rods, wands and mana fluids for sale." />
        	<parameter key="keyword_reply4" value="I hate them. Don't tell anybody but they are small booring drunk people without fashion sence." />
        	<parameter key="keyword_reply5" value="Here is my list of Rods. They are orderes by the level requirement: Snakebite rod, Moonlight rod, Necrotic rod, Terra rod and last Hailstorm rod. Which one would you like to buy?" />
        	<parameter key="keyword_reply6" value="Here is my list of Wands. They are orderes by the level requirement: Wands of vortex, Wand of dragonbreath, Wand of decay, Wand of cosmic energy and the best of them all! Do you need any of them?" />
        	<parameter key="keyword_reply7" value="Oh ok. I have really many runes... This could take awhile, I have the following runes: Animate dead, Antidote rune, Avalanche, Chamelon, Desintegrate, Destroy field, Energy bomb, Energy field, Explosion, Fire bomb, Fire field, Fireball, Great fireball, Heavy magic missile, Icicle, Intense healing rune, Light magi missile, Magic wall, Paralyze, Poison bomb, Poison field, Poison wall, Soulfire, Stalagmite, Stone shower, Sudden death, Thunderstorm, Ultimate healing runes. Which one would you like to buy?" />
        	<parameter key="keyword_reply8" value="I hate them. Don't tell anybody but they are small booring drunk people without fashion sence." />
   </parameters>
</npc>

anyone know whats wrong?

//Massen
 
Last edited:
@ Massen:
Post your npchandler.lua (can be found in data/npc/lib/npcsystem/ )
and about the servers.xml, maybe multiworld? but I'm not quite sure, first have to download the server...

Yours,
Markey
 
Here's my Npchandler.lua (the exact same one as in tfs alpha V0.3 (2)

Code:
-- Advanced NPC System (Created by Jiddo),
-- Modified by Talaturen.

if(NpcHandler == nil) then
	-- Constant talkdelay behaviors.
	TALKDELAY_NONE = 0 -- No talkdelay. Npc will reply immedeatly.
	TALKDELAY_ONTHINK = 1 -- Talkdelay handled through the onThink callback function. (Default)
	TALKDELAY_EVENT = 2 -- Not yet implemented

	-- Currently applied talkdelay behavior. TALKDELAY_ONTHINK is default.
	NPCHANDLER_TALKDELAY = TALKDELAY_ONTHINK

	-- Constant conversation behaviors.
	CONVERSATION_DEFAULT = 0 -- Conversation through default window, like it was before 8.2 update.
	CONVERSATION_PRIVATE = 1 -- Conversation through NPCs chat window, as of 8.2 update. (Default)
		--Small Note: Private conversations also means the NPC will use multi-focus system.

	-- Currently applied conversation behavior. CONVERSATION_PRIVATE is default.
	NPCHANDLER_CONVBEHAVIOR = CONVERSATION_PRIVATE

	-- Constant indexes for defining default messages.
	MESSAGE_GREET 			= 1 -- When the player greets the npc.
	MESSAGE_FAREWELL 		= 2 -- When the player unGreets the npc.
	MESSAGE_BUY 			= 3 -- When the npc asks the player if he wants to buy something.
	MESSAGE_ONBUY 			= 4 -- When the player successfully buys something via talk.
	MESSAGE_BOUGHT			= 5 -- When the player bought something through the shop window.
	MESSAGE_SELL 			= 6 -- When the npc asks the player if he wants to sell something.
	MESSAGE_ONSELL 			= 7 -- When the player successfully sells something via talk.
	MESSAGE_SOLD			= 8 -- When the player sold something through the shop window.
	MESSAGE_MISSINGMONEY	= 9 -- When the player does not have enough money.
	MESSAGE_NEEDMONEY		= 10 -- Same as above, used for shop window.
	MESSAGE_MISSINGITEM		= 11 -- When the player is trying to sell an item he does not have.
	MESSAGE_NEEDITEM		= 12 -- Same as above, used for shop window.
	MESSAGE_NEEDSPACE 		= 13 -- When the player don't have any space to buy an item
	MESSAGE_NEEDMORESPACE	= 14 -- When the player has some space to buy an item, but not enough space
	MESSAGE_IDLETIMEOUT		= 15 -- When the player has been idle for longer then idleTime allows.
	MESSAGE_WALKAWAY		= 16 -- When the player walks out of the talkRadius of the npc.
	MESSAGE_DECLINE			= 17 -- When the player says no to something.
	MESSAGE_SENDTRADE		= 18 -- When the npc sends the trade window to the player
	MESSAGE_NOSHOP			= 19 -- When the npc's shop is requested but he doesn't have any
	MESSAGE_ONCLOSESHOP		= 20 -- When the player closes the npc's shop window
	MESSAGE_ALREADYFOCUSED	= 21 -- When the player already has the focus of this npc.
	MESSAGE_PLACEDINQUEUE	= 22 -- When the player has been placed in the costumer queue.

	-- Constant indexes for callback functions. These are also used for module callback ids.
	CALLBACK_CREATURE_APPEAR 	= 1
	CALLBACK_CREATURE_DISAPPEAR = 2
	CALLBACK_CREATURE_SAY 		= 3
	CALLBACK_ONTHINK 			= 4
	CALLBACK_GREET 				= 5
	CALLBACK_FAREWELL 			= 6
	CALLBACK_MESSAGE_DEFAULT 	= 7
	CALLBACK_PLAYER_ENDTRADE 	= 8
	CALLBACK_PLAYER_CLOSECHANNEL= 9
	CALLBACK_ONBUY				= 10
	CALLBACK_ONSELL				= 11

	-- Addidional module callback ids
	CALLBACK_MODULE_INIT		= 12
	CALLBACK_MODULE_RESET		= 13

	-- Constant strings defining the keywords to replace in the default messages.
	TAG_PLAYERNAME = '|PLAYERNAME|'
	TAG_ITEMCOUNT = '|ITEMCOUNT|'
	TAG_TOTALCOST = '|TOTALCOST|'
	TAG_ITEMNAME = '|ITEMNAME|'
	TAG_QUEUESIZE = '|QUEUESIZE|'

	NpcHandler = {
		keywordHandler = nil,
		focuses = nil,
		talkStart = nil,
		idleTime = 90,
		talkRadius = 4,
		talkDelayTime = 1, -- Seconds to delay outgoing messages.
		queue = nil,
		talkDelay = nil,
		callbackFunctions = nil,
		modules = nil,
		shopItems = nil, -- They must be here since ShopModule uses "static" functions
		messages = {
			-- These are the default replies of all npcs. They can/should be changed individually for each npc.
			[MESSAGE_GREET] 			= 'Welcome, |PLAYERNAME|! I have been expecting you.',
			[MESSAGE_FAREWELL] 			= 'Good bye, |PLAYERNAME|!',
			[MESSAGE_BUY] 				= 'Do you want to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
			[MESSAGE_ONBUY] 			= 'It was a pleasure doing business with you.',
			[MESSAGE_BOUGHT] 			= 'Bought |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold.',
			[MESSAGE_SELL] 				= 'Do you want to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?',
			[MESSAGE_ONSELL] 			= 'Thank you for this |ITEMNAME|, |PLAYERNAME| gold.',
			[MESSAGE_SOLD]	 			= 'Sold |ITEMCOUNT|x |ITEMNAME| for |TOTALCOST| gold.',
			[MESSAGE_MISSINGMONEY]		= 'Sorry, you don\'t have enough money.',
			[MESSAGE_NEEDMONEY] 		= 'You do not have enough money.',
			[MESSAGE_MISSINGITEM] 		= 'You don\'t even have that item, |PLAYERNAME|!',
			[MESSAGE_NEEDITEM]	 		= 'You do not have this object.',
			[MESSAGE_NEEDSPACE]			= 'You do not have enough capacity.',
			[MESSAGE_NEEDMORESPACE]		= 'You do not have enough capacity for all items.',
			[MESSAGE_IDLETIMEOUT] 		= 'Next, please!',
			[MESSAGE_WALKAWAY] 			= 'How rude!',
			[MESSAGE_DECLINE]			= 'Not good enough, is it... ?',
			[MESSAGE_SENDTRADE]			= 'Here\'s my offer, |PLAYERNAME|. Don\'t you like it?',
			[MESSAGE_NOSHOP]			= 'Sorry, I\'m not offering anything.',
			[MESSAGE_ONCLOSESHOP]		= 'Thank you, come back when you want something more.',
			[MESSAGE_ALREADYFOCUSED]	= '|PLAYERNAME|! I am already talking to you...',
			[MESSAGE_PLACEDINQUEUE] 	= '|PLAYERNAME|, please wait for your turn. There are |QUEUESIZE| customers before you.'
		}
	}

	-- Creates a new NpcHandler with an empty callbackFunction stack.
	function NpcHandler:new(keywordHandler)
		local obj = {}
		obj.callbackFunctions = {}
		obj.modules = {}
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			obj.focuses = {}
			obj.talkStart = {}
		else
			obj.queue = Queue:new(obj)
			obj.focuses = 0
			obj.talkStart = 0
		end
		obj.talkDelay = {}
		obj.keywordHandler = keywordHandler
		obj.messages = {}
		obj.shopItems = {}

		setmetatable(obj.messages, self.messages)
		self.messages.__index = self.messages

		setmetatable(obj, self)
		self.__index = self
		return obj
	end

	-- Re-defines the maximum idle time allowed for a player when talking to this npc.
	function NpcHandler:setMaxIdleTime(newTime)
		self.idleTime = newTime
	end

	-- Attackes a new keyword handler to this npchandler
	function NpcHandler:setKeywordHandler(newHandler)
		self.keywordHandler = newHandler
	end

	-- Function used to change the focus of this npc.
	function NpcHandler:addFocus(newFocus)
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			if(self:isFocused(newFocus)) then
				return
			end

			table.insert(self.focuses, newFocus)
		else
			self.focuses = newFocus
		end
		self:updateFocus()
	end
	NpcHandler.changeFocus = NpcHandler.addFocus --"changeFocus" looks better for CONVERSATION_DEFAULT

	-- Function used to verify if npc is focused to certain player
	function NpcHandler:isFocused(focus)
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			for k,v in pairs(self.focuses) do
				if v == focus then
					return true
				end
			end
			return false
		end
		return (self.focuses == focus)
	end

	-- This function should be called on each onThink and makes sure the npc faces the player it is talking to.
	--	Should also be called whenever a new player is focused.
	function NpcHandler:updateFocus()
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			for pos, focus in pairs(self.focuses) do
				if(focus ~= nil) then
					doNpcSetCreatureFocus(focus)
					return
				end
			end
			doNpcSetCreatureFocus(0)
		else
			doNpcSetCreatureFocus(self.focuses)
		end
	end

	-- Used when the npc should un-focus the player.
	function NpcHandler:releaseFocus(focus)
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			if(not self:isFocused(focus)) then
				return
			end

			local pos = nil
			for k,v in pairs(self.focuses) do
				if v == focus then
					pos = k
				end
			end
			table.remove(self.focuses, pos)
			self.talkStart[focus] = nil
			closeShopWindow(focus) --Even if it can not exist, we need to prevent it.
			self:updateFocus()
		else
			closeShopWindow(focus)
			self:changeFocus(0)
		end
	end

	-- Returns the callback function with the specified id or nil if no such callback function exists.
	function NpcHandler:getCallback(id)
		local ret = nil
		if(self.callbackFunctions ~= nil) then
			ret = self.callbackFunctions[id]
		end
		return ret
	end

	-- Changes the callback function for the given id to callback.
	function NpcHandler:setCallback(id, callback)
		if(self.callbackFunctions ~= nil) then
			self.callbackFunctions[id] = callback
		end
	end

	-- Adds a module to this npchandler and inits it.
	function NpcHandler:addModule(module)
		if(self.modules ~= nil) then
			table.insert(self.modules, module)
			module:init(self)
		end
	end

	-- Calls the callback function represented by id for all modules added to this npchandler with the given arguments.
	function NpcHandler:processModuleCallback(id, ...)
		local ret = true
		for i, module in pairs(self.modules) do
			local tmpRet = true
			if(id == CALLBACK_CREATURE_APPEAR and module.callbackOnCreatureAppear ~= nil) then
				tmpRet = module:callbackOnCreatureAppear(unpack(arg))
			elseif(id == CALLBACK_CREATURE_DISAPPEAR and module.callbackOnCreatureDisappear ~= nil) then
				tmpRet = module:callbackOnCreatureDisappear(unpack(arg))
			elseif(id == CALLBACK_CREATURE_SAY and module.callbackOnCreatureSay ~= nil) then
				tmpRet = module:callbackOnCreatureSay(unpack(arg))
			elseif(id == CALLBACK_PLAYER_ENDTRADE and module.callbackOnPlayerEndTrade ~= nil) then
				tmpRet = module:callbackOnPlayerEndTrade(unpack(arg))
			elseif(id == CALLBACK_PLAYER_CLOSECHANNEL and module.callbackOnPlayerCloseChannel ~= nil) then
				tmpRet = module:callbackOnPlayerCloseChannel(unpack(arg))
			elseif(id == CALLBACK_ONBUY and module.callbackOnBuy ~= nil) then
				tmpRet = module:callbackOnBuy(unpack(arg))
			elseif(id == CALLBACK_ONSELL and module.callbackOnSell ~= nil) then
				tmpRet = module:callbackOnSell(unpack(arg))
			elseif(id == CALLBACK_ONTHINK and module.callbackOnThink ~= nil) then
				tmpRet = module:callbackOnThink(unpack(arg))
			elseif(id == CALLBACK_GREET and module.callbackOnGreet ~= nil) then
				tmpRet = module:callbackOnGreet(unpack(arg))
			elseif(id == CALLBACK_FAREWELL and module.callbackOnFarewell ~= nil) then
				tmpRet = module:callbackOnFarewell(unpack(arg))
			elseif(id == CALLBACK_MESSAGE_DEFAULT and module.callbackOnMessageDefault ~= nil) then
				tmpRet = module:callbackOnMessageDefault(unpack(arg))
			elseif(id == CALLBACK_MODULE_RESET and module.callbackOnModuleReset ~= nil) then
				tmpRet = module:callbackOnModuleReset(unpack(arg))
			end
			if(not tmpRet) then
				ret = false
				break
			end
		end
		return ret
	end

	-- Returns the message represented by id.
	function NpcHandler:getMessage(id)
		local ret = nil
		if(self.messages ~= nil) then
			ret = self.messages[id]
		end
		return ret
	end

	-- Changes the default response message with the specified id to newMessage.
	function NpcHandler:setMessage(id, newMessage)
		if(self.messages ~= nil) then
			self.messages[id] = newMessage
		end
	end

	-- Translates all message tags found in msg using parseInfo
	function NpcHandler:parseMessage(msg, parseInfo)
		local ret = msg
		for search, replace in pairs(parseInfo) do
			ret = string.gsub(ret, search, replace)
		end
		return ret
	end

	-- Makes sure the npc un-focuses the currently focused player
	function NpcHandler:unGreet(cid)
		if(not self:isFocused(cid)) then
			return
		end

		local callback = self:getCallback(CALLBACK_FAREWELL)
		if(callback == nil or callback()) then
			if(self:processModuleCallback(CALLBACK_FAREWELL)) then
				if(self.queue == nil or not self.queue:greetNext()) then
					local msg = self:getMessage(MESSAGE_FAREWELL)
					local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
					msg = self:parseMessage(msg, parseInfo)
					self:say(msg, cid, true)
					self:releaseFocus(cid)
				end
			end
		end
	end

	-- Greets a new player.
	function NpcHandler:greet(cid)
		if(cid ~= 0) then
			local callback = self:getCallback(CALLBACK_GREET)
			if(callback == nil or callback(cid)) then
				if(self:processModuleCallback(CALLBACK_GREET, cid)) then
					local msg = self:getMessage(MESSAGE_GREET)
					local parseInfo = { [TAG_PLAYERNAME] = getCreatureName(cid) }
					msg = self:parseMessage(msg, parseInfo)
					self:say(msg, cid, true)
				else
					return
				end
			else
				return
			end
		end
		self:addFocus(cid)
	end

	-- Handles onCreatureAppear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_APPEAR callback.
	function NpcHandler:onCreatureAppear(cid)
		local callback = self:getCallback(CALLBACK_CREATURE_APPEAR)
		if(callback == nil or callback(cid)) then
			if(self:processModuleCallback(CALLBACK_CREATURE_APPEAR, cid)) then
				--
			end
		end
	end

	-- Handles onCreatureDisappear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_DISAPPEAR callback.
	function NpcHandler:onCreatureDisappear(cid)
		local callback = self:getCallback(CALLBACK_CREATURE_DISAPPEAR)
		if(callback == nil or callback(cid)) then
			if(self:processModuleCallback(CALLBACK_CREATURE_DISAPPEAR, cid)) then
				if(self:isFocused(cid)) then
					self:unGreet(cid)
				end
			end
		end
	end

	-- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback.
	function NpcHandler:onCreatureSay(cid, msgtype, msg)
		local callback = self:getCallback(CALLBACK_CREATURE_SAY)
		if(callback == nil or callback(cid, msgtype, msg)) then
			if(self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg)) then
				if(not self:isInRange(cid)) then
					return
				end

				if(self.keywordHandler ~= nil) then
					if(self:isFocused(cid) and (msgtype == TALKTYPE_PRIVATE_PN or NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT) or (not self:isFocused(cid))) then
						local ret = self.keywordHandler:processMessage(cid, msg)
						if(not ret) then
							local callback = self:getCallback(CALLBACK_MESSAGE_DEFAULT)
							if(callback ~= nil and callback(cid, msgtype, msg)) then
								if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
									self.talkStart[cid] = os.time()
								else
									self.talkStart = os.time()
								end
							end
						else
							if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
								self.talkStart[cid] = os.time()
							else
								self.talkStart = os.time()
							end
						end
					end
				end
			end
		end
	end

	-- Handles onPlayerEndTrade events. If you wish to handle this yourself, use the CALLBACK_PLAYER_ENDTRADE callback.
	function NpcHandler:onPlayerEndTrade(cid)
		local callback = self:getCallback(CALLBACK_PLAYER_ENDTRADE)
		if(callback == nil or callback(cid)) then
			if(self:processModuleCallback(CALLBACK_PLAYER_ENDTRADE, cid, msgtype, msg)) then
				if(self:isFocused(cid)) then
					local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
					local msg = self:parseMessage(self:getMessage(MESSAGE_ONCLOSESHOP), parseInfo)
					self:say(msg, cid)
				end
			end
		end
	end

	-- Handles onPlayerCloseChannel events. If you wish to handle this yourself, use the CALLBACK_PLAYER_CLOSECHANNEL callback.
	function NpcHandler:onPlayerCloseChannel(cid)
		local callback = self:getCallback(CALLBACK_PLAYER_CLOSECHANNEL)
		if(callback == nil or callback(cid)) then
			if(self:processModuleCallback(CALLBACK_PLAYER_CLOSECHANNEL, cid, msgtype, msg)) then
				if(self:isFocused(cid)) then
					self:unGreet(cid)
				end
			end
		end
	end

	-- Handles onBuy events. If you wish to handle this yourself, use the CALLBACK_ONBUY callback.
	function NpcHandler:onBuy(cid, itemid, subType, amount)
		local callback = self:getCallback(CALLBACK_ONBUY)
		if(callback == nil or callback(cid, itemid, subType, amount)) then
			if(self:processModuleCallback(CALLBACK_ONBUY, cid, itemid, subType, amount)) then
				--
			end
		end
	end

	-- Handles onSell events. If you wish to handle this yourself, use the CALLBACK_ONSELL callback.
	function NpcHandler:onSell(cid, itemid, subType, amount)
		local callback = self:getCallback(CALLBACK_ONSELL)
		if(callback == nil or callback(cid, itemid, subType, amount)) then
			if(self:processModuleCallback(CALLBACK_ONSELL, cid, itemid, subType, amount)) then
				--
			end
		end
	end

	-- Handles onThink events. If you wish to handle this yourself, please use the CALLBACK_ONTHINK callback.
	function NpcHandler:onThink()
		local callback = self:getCallback(CALLBACK_ONTHINK)
		if(callback == nil or callback()) then
			if(NPCHANDLER_TALKDELAY == TALKDELAY_ONTHINK) then
				if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
					for cid, talkDelay in pairs(self.talkDelay) do
						if(talkDelay.time ~= nil and talkDelay.message ~= nil and os.time() >= talkDelay.time) then
							selfSay(talkDelay.message, cid, talkDelay.publicize and TRUE or FALSE)
							self.talkDelay[cid] = nil
						end
					end
				elseif(self.talkDelay.time ~= nil and self.talkDelay.message ~= nil and os.time() >= self.talkDelay.time) then
					selfSay(self.talkDelay.message)
					self.talkDelay.time = nil
					self.talkDelay.message = nil
				end
			end

			if(self:processModuleCallback(CALLBACK_ONTHINK)) then
				if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
					for pos, focus in pairs(self.focuses) do
						if(focus ~= nil) then
							if(not self:isInRange(focus)) then
								self:onWalkAway(focus)
							elseif((os.time() - self.talkStart[focus]) > self.idleTime) then
								self:unGreet(focus)
							else
								self:updateFocus()
							end
						end
					end
				elseif(self.focuses ~= 0) then
					if(not self:isInRange(self.focuses)) then
						self:onWalkAway(self.focuses)
					elseif(os.time()-self.talkStart > self.idleTime) then
						self:unGreet(self.focuses)
					else
						self:updateFocus()
					end
				end
			end
		end
	end

	-- Tries to greet the player with the given cid.
	function NpcHandler:onGreet(cid)
		if(self:isInRange(cid)) then
			if(NPCHANDLER_CONVBEHAVIOR == CONVERSATION_PRIVATE) then
				if(not self:isFocused(cid)) then
					self:greet(cid)
					return
				end
			elseif(NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT) then
				if(self.focuses == 0) then
					self:greet(cid)
				elseif(self.focuses == cid) then
					local msg = self:getMessage(MESSAGE_ALREADYFOCUSED)
					local parseInfo = { [TAG_PLAYERNAME] = getCreatureName(cid) }
					msg = self:parseMessage(msg, parseInfo)
					self:say(msg)
				else
					if(not self.queue:isInQueue(cid)) then
						self.queue:push(cid)
					end
					local msg = self:getMessage(MESSAGE_PLACEDINQUEUE)
					local parseInfo = { [TAG_PLAYERNAME] = getCreatureName(cid), [TAG_QUEUESIZE] = self.queue:getSize() }
					msg = self:parseMessage(msg, parseInfo)
					self:say(msg)
				end
			end
		end
	end

	-- Simply calls the underlying unGreet function.
	function NpcHandler:onFarewell(cid)
		self:unGreet(cid)
	end

	-- Should be called on this npc's focus if the distance to focus is greater then talkRadius.
	function NpcHandler:onWalkAway(cid)
		if(self:isFocused(cid)) then
			local callback = self:getCallback(CALLBACK_CREATURE_DISAPPEAR)
			if(callback == nil or callback()) then
				if(self:processModuleCallback(CALLBACK_CREATURE_DISAPPEAR, cid)) then
					if(self.queue == nil or not self.queue:greetNext()) then
						local msg = self:getMessage(MESSAGE_WALKAWAY)
						local parseInfo = { [TAG_PLAYERNAME] = getPlayerName(cid) }
						msg = self:parseMessage(msg, parseInfo)
						self:say(msg, cid, true)
						self:releaseFocus(cid)
					end
				end
			end
		end
	end

	-- Returns true if cid is within the talkRadius of this npc.
	function NpcHandler:isInRange(cid)
		local distance = getDistanceTo(cid) or -1
		if distance == -1 then
			return false
		end

		return (distance <= self.talkRadius)
	end

	-- Resets the npc into it's initial state (in regard of the keyrodhandler).
	--	All modules are also receiving a reset call through their callbackOnModuleReset function.
	function NpcHandler:resetNpc()
		if(self:processModuleCallback(CALLBACK_MODULE_RESET)) then
			self.keywordHandler:reset()
		end
	end

	-- Makes the npc represented by this instance of NpcHandler say something.
	--	This implements the currently set type of talkdelay.
	--	shallDelay is a boolean value. If it is false, the message is not delayed. Default value is true.
	function NpcHandler:say(message, focus, publicize, shallDelay)
		if(shallDelay == nil) then
			shallDelay = true
		end
		if(NPCHANDLER_TALKDELAY == TALKDELAY_NONE or shallDelay == false) then
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				selfSay(message, focus, publicize and TRUE or FALSE)
				return
			else
				selfSay(message)
				return
			end
		end
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			self.talkDelay[focus] = {
				message = message,
				time = os.time() + self.talkDelayTime,
				publicize = publicize
			}
		else
			self.talkDelay = {
				message = message,
				time = os.time() + self.talkDelayTime
			}
		end
	end
end

//Massen
 
Thank you very much by your information.

On the other hand I think that this it is a good OtServ, I can say that it is the best one than I have seen...

I am programmer, would like I to work in the OtServ with his group, since it would be worth the effort. =)
 
I recieved this error after being online for 30-40 min alone~

Code:
[15/10/2008  14:19:33] Warning: [Server::onAccept] More than 100 listen errors.

What is this?

//Massen
 
I know that this is a bit off-topic, but I want to make a client, like remote controll, with visual basic.
My question is, how does this work?? Do you send some "commands" or something like this to the server?

If anybody knows and can tell me plz send me a pm, I'd be really thankful.
Yours,
Markey
 
Hello, im getting this error in the console
Code:
Error while saving player: xxx
and everyones acc and pass just stops working, i cant even login on my god to save the world.
and then there's a rollback, i get this error all the time :S
Can anyone help me?

Thanks
 
I also have this problem in MySql

""Error while saving player: xxx"" and there happens when there are players banned (very common)
""Loss percentage"" 95% of the players (only when you buy the Blessings) -
and not just a percentage or lose
 
Last edited:
Status
Not open for further replies.
Back
Top