ex eclipse
New Member
hello there guys, i got a cipfriend script, but i dunno why its not working on TFS 0.2.10..
here is the script
"Lua Script Error: [Npc interface]
data/npc/scripts/cipfried.lua
data/npc/scripts/cipfried.lua:5: attempt to index global 'ShopNpcHandler' (a nil
value)
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/cipfried.l
ua"
here is the script
Code:
-- Cipfried
local internalCustomerQueue = {}
local keywordHandler = KeywordHandler:new({root = {}})
local npcHandler = ShopNpcHandler:new({})
local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler})
npcHandler:init(customerQueue, keywordHandler)
-- OTServ event handling functions start
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
-- OTServ event handling functions end
-- Keyword handling functions start
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)
-- Keyword structure generation end
Last edited by a moderator: