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

bomba

Member
Joined
Feb 26, 2008
Messages
635
Reaction score
7
Location
Brazil
The npc.XML:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Cipfried" script="data/npc/scripts/healer.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="57"/>
</npc>

The screipt.LUA:
Code:
 local internalCustomerQueue = {}
 local keywordHandler = KeywordHandler:new({root = {}})
 local npcHandler = ShopNpcHandler:new({})
 local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler})
npcHandler:init(customerQueue, keywordHandler)

function onThingMove(creature, thing, oldpos, oldstackpos)		npcHandler:onThingMove(creature, thing, oldpos, oldstackpos) end
function onCreatureAppear(creature)		npcHandler:onCreatureAppear(creature) end
function onCreatureDisappear(id)		npcHandler:onCreatureDisappear(id) end
function onCreatureTurn(creature)		npcHandler:onCreatureTurn(creature) end
function onCreatureSay(cid, type, msg)		npcHandler:onCreatureSay(cid, type, msg) end
function onCreatureChangeOutfit(creature)		npcHandler:onCreatureChangeOutfit(creature) end

function onThink()
	if (os.clock() - npcHandler.talkStart) > 40 then
	if npcHandler.focus > 0 then
	   selfSay('Well, bye then.')
end
npcHandler:resetNpc()
npcHandler.queue:greetNext()
end
 local dist = getDistanceToCreature(npcHandler.focus)
	if dist > 3 then
	   selfSay('Well, bye then.')
npcHandler:resetNpc()
npcHandler.queue:greetNext()
end
	if npcHandler.focus == 0 then
	if(npcHandler.spawnPos == nil) then
 local sx, sy, sz = selfGetPosition()
npcHandler.spawnPos = {x = sx, y = sy, z = sz}
end
npcHandler.lastMove = walk(npcHandler.lastMove, npcHandler.spawnPos, npcHandler.walkDistance)
    else
npcHandler.lastPos = turnToCreature(npcHandler.focus, npcHandler.lastPos)
 end
end

function healPlayer(cid, message, keywords, parameters)
	if(getPlayerHealth(cid) < parameters.maxheal) then
 position = getPlayerPosition(npcHandler.focus)
	   doSendMagicEffect(position, 12)
 local healHP = parameters.maxheal - getPlayerHealth(cid)
	   doPlayerAddHealth(npcHandler.focus,healHP)
	   selfSay('You are looking really bad. Let me heal your wounds.')
    else
	   selfSay('You aren\'t looking really bad, ' .. creatureGetName(cid) .. '. I only help in cases of real emergencies. Raise your health simply by eating food.')
 end
 return TRUE
end

function healPlayerNoMsg(cid, maxheal)
	if(getPlayerHealth(cid) < maxheal) then
 position = getPlayerPosition(npcHandler.focus)
	   doSendMagicEffect(position, 12)
 local healHP = maxheal - getPlayerHealth(cid)
	   doPlayerAddHealth(npcHandler.focus,healHP)
	   selfSay('Hello, ' .. creatureGetName(cid) .. '! You are looking really bad. Let me heal your wounds.')
 end
 return TRUE
end

function tradeItem(cid, message, keywords, parameters)		return npcHandler:defaultTradeHandler(cid, message, keywords, parameters) end
function confirmAction(cid, message, keywords, parameters)		return npcHandler:defaultConfirmHandler(cid, message, keywords, parameters) end
function sayMessage(cid, message, keywords, parameters)		return npcHandler:defaultMessageHandler(cid, message, keywords, parameters) end

function greet(cid, message, keywords, parameters)
	if (npcHandler.focus > 0 or not(npcHandler.queue:isEmpty()) and npcHandler.focus ~= cid) then
	   selfSay('Please, ' .. creatureGetName(cid) .. '. Wait for your turn!.')
	if(not npcHandler.queue:isInQueue(cid)) then
npcHandler.queue:pushBack(cid)
end
	 elseif(npcHandler.focus == 0) and (npcHandler.queue:isEmpty()) then
npcHandler.focus = cid
npcHandler.talkStart = os.clock()
	if(getPlayerHealth(cid) >= 65) then
	   selfSay('Hello, ' .. creatureGetName(cid) .. '! I will heal you if you are injured. Feel free to ask me for help.')
    else
 healPlayerNoMsg(npcHandler.focus, 65)
  end
 end
  return TRUE
end

function farewell(cid, message, keywords, parameters)		return npcHandler:defaultFarewellHandler(cid, message, keywords, parameters) end
keywordHandler:addKeyword({'heal'},	healPlayer, {maxheal = 65})
keywordHandler:addKeyword({'help'},	healPlayer, {maxheal = 65})
keywordHandler:addKeyword({'yes'}, confirmAction, nil)
keywordHandler:addKeyword({'no'}, confirmAction, nil)
keywordHandler:addKeyword({'monk'},		sayMessage, {text = 'I sacrifice my life to serve the good gods of Tibia.', onlyfocus = true})
keywordHandler:addKeyword({'rookgaard'},		sayMessage, {text = 'The gods have chosen this isle as the point of arrival for the newborn souls.', onlyfocus = true})
keywordHandler:addKeyword({'god'},		sayMessage, {text = 'They created Tibia and all life on it. Visit our library and learn about them.', onlyfocus = true})
keywordHandler:addKeyword({'job'},		sayMessage, {text = 'I am just a humble monk. Ask me if you need help or healing.', onlyfocus = true})
keywordHandler:addKeyword({'life'},		sayMessage, {text = 'The gods decorated Tibia with various forms of life. Plants, the citizens, and even the monsters.', onlyfocus = true})
keywordHandler:addKeyword({'plant'},		sayMessage, {text = 'Just walk around. You will see grass, trees, and bushes.', onlyfocus = true})
keywordHandler:addKeyword({'citizen'},		sayMessage, {text = 'Only few people live here. Walk around and talk to them.', onlyfocus = true})
keywordHandler:addKeyword({'obi'},		sayMessage, {text = 'He is a local shop owner.', onlyfocus = true})
keywordHandler:addKeyword({'al dee'},		sayMessage, {text = 'He is a local shop owner.', onlyfocus = true})
keywordHandler:addKeyword({'name'},		sayMessage, {text = 'My name is Cipfried.', onlyfocus = true})
keywordHandler:addKeyword({'seymour'},		sayMessage, {text = 'Seymour is a loyal follower of the king and responsible for the academy.', onlyfocus = true})
keywordHandler:addKeyword({'academy'},		sayMessage, {text = 'You should visit Seymour in the academy and ask him about a mission.', onlyfocus = true})
keywordHandler:addKeyword({'willie'},		sayMessage, {text = 'He is a fine farmer. The farm is located to the left of the temple.', onlyfocus = true})
keywordHandler:addKeyword({'monster'},		sayMessage, {text = 'They are a constant threat. Learn to fight by hunting rabbits, deers and sheeps. Then try to fight rats, bugs and perhaps spiders.', onlyfocus = true})
keywordHandler:addKeyword({'help'},		sayMessage, {text = 'First you should try to get some gold and buy better equipment.', onlyfocus = true})
keywordHandler:addKeyword({'quest'},		sayMessage, {text = 'First you should try to get some gold and buy better equipment.', onlyfocus = true})
keywordHandler:addKeyword({'gold'},		sayMessage, {text = 'You have to slay monsters and take their gold. Or sell food at Willie\'s farm.', onlyfocus = true})
keywordHandler:addKeyword({'tibia'},		sayMessage, {text = 'That\'s where we are. The world of Tibia.', onlyfocus = true})
keywordHandler:addKeyword({'rat'},		sayMessage, {text = 'In the north of this temple you find a sewer grate. Use it to enter the sewers if you feel prepared. Don\'t forget a torch; you\'ll need it.', onlyfocus = true})
keywordHandler:addKeyword({'sewer'},		sayMessage, {text = 'In the north of this temple you find a sewer grate. Use it to enter the sewers if you feel prepared. Don\'t forget a torch; you\'ll need it.', onlyfocus = true})
keywordHandler:addKeyword({'equipment'},		sayMessage, {text = 'First you need some armor and perhaps a better weapon or a shield. A real adventurer needs a rope, a shovel, and a fishing pole, too.', onlyfocus = true})
keywordHandler:addKeyword({'food'},		sayMessage, {text = 'If you want to heal your wounds you should eat something. Willie sells excellent meals. But if you are very weak, come to me and ask me to heal you.', onlyfocus = true})
keywordHandler:addKeyword({'hi'}, greet, nil)
keywordHandler:addKeyword({'hello'}, greet, nil)
keywordHandler:addKeyword({'hey'}, greet, nil)
keywordHandler:addKeyword({'bye'}, farewell, nil)
keywordHandler:addKeyword({'farewell'}, farewell, nil)
 
Hi.

I have problem

Code:
[20/01/2009  07:41:11] > Map loading time: 3.922 seconds.

[20/01/2009  07:41:12] Lua Script Error: [Npc interface] 
[20/01/2009  07:41:12] data/npc/scripts/healer.lua

[20/01/2009  07:41:12] data/npc/scripts/healer.lua:3: attempt to index global 'ShopNpcHandler' (a nil value)
[20/01/2009  07:41:12] Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/healer.lua

[20/01/2009  07:41:24] >> Loading raids
[20/01/2009  07:41:24] >> All modules has been loaded, server starting up...
[20/01/2009  07:41:27] >> Eternal Server Online!

I use TFS 0.2.11. What change for "ShopNpcHandler" or what add to modules?
 
Back
Top