terá q ter esse sistema aki
creditos:Jiddo (NPC System, Oracle)
Me and Ispiro (NPCs)
Augusto Alvetoria and Deamon_OTS (ItemforItem function)
B]Al Dee[/b]
-- Al Dee local internalCustomerQueue = {} local keywordHandler = KeywordHandler:new({root = {}}) local npcHandler = ShopNpcHandler:new({}) local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler}) npcHandler:init(customerQueue, keywordHandler) npcHandler.walkDistance = 1 -- 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() npcHandler:onThink() end -- OTServ event handling functions end -- Keyword handling functions start 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 == cid then selfSay('I am already talking to you.') npcHandler.talkStart = os.clock() elseif npcHandler.focus > 0 or not(npcHandler.queue:isEmpty()) then selfSay('I\'ll be with you in a moment, ' .. creatureGetName(cid) .. '.') if(not npcHandler.queue:isInQueue(cid)) then npcHandler.queue:pushBack(cid) end elseif(npcHandler.focus == 0) and (npcHandler.queue:isEmpty()) then selfSay('Hello hello, ' .. creatureGetName(cid) .. '! Please come in, look, and buy!') npcHandler.focus = cid npcHandler.talkStart = os.clock() end return true end function farewell(cid, message, keywords, parameters) if(cid == npcHandler.focus) then selfSay('Bye, bye') npcHandler:resetNpc() npcHandler.queue:greetNext() return true end return false end -- Keyword handling functions end function itemForItem(cid, message, keywords, parameters) if(getPlayerItemCount(cid, parameters.itemtrade) >= parameters.counti) then doPlayerRemoveItem(cid, parameters.itemtrade, parameters.counti) doPlayerAddItem(cid, parameters.itemtrade2, parameters.counti2) selfSay('Splendid! Here take your pickaxe.') else selfSay('Sorry I\'m looking for a SMALL axe.') end end -- Sell Item Keywords keywordHandler:addKeyword({'sell', 'spear'}, tradeItem, {itemid = 2389, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'rapier'}, tradeItem, {itemid = 2384, cost = 1}) keywordHandler:addKeyword({'sell', 'sabre'}, tradeItem, {itemid = 2385, cost = 1}) keywordHandler:addKeyword({'sell', 'dagger'}, tradeItem, {itemid = 2379, cost = 1}) keywordHandler:addKeyword({'sell', 'sickle'}, tradeItem, {itemid = 2405, cost = 1}) keywordHandler:addKeyword({'sell', 'hand axe'}, tradeItem, {itemid = 2380, cost = 1}) keywordHandler:addKeyword({'sell', 'axe'}, tradeItem, {itemid = 2386, cost = 1}) keywordHandler:addKeyword({'sell', 'short sword'}, tradeItem, {itemid = 2406, cost = 1}) keywordHandler:addKeyword({'sell', 'jacket'}, tradeItem, {itemid = 2650, cost = 1}) keywordHandler:addKeyword({'sell', 'coat'}, tradeItem, {itemid = 2651, cost = 1}) keywordHandler:addKeyword({'sell', 'doublet'}, tradeItem, {itemid = 2485, cost = 1}) keywordHandler:addKeyword({'sell', 'leather armor'}, tradeItem, {itemid = 2467, cost = 1}) keywordHandler:addKeyword({'sell', 'leather legs'}, tradeItem, {itemid = 2649, cost = 1}) keywordHandler:addKeyword({'sell', 'leather helmet'}, tradeItem, {itemid = 2461, cost = 1}) keywordHandler:addKeyword({'sell', 'studded helmet'}, tradeItem, {itemid = 2482, cost = 1}) keywordHandler:addKeyword({'sell', 'chain helmet'}, tradeItem, {itemid = 2458, cost = 1}) keywordHandler:addKeyword({'sell', 'wooden shield'}, tradeItem, {itemid = 2512, cost = 1}) keywordHandler:addKeyword({'sell', 'studded shield'}, tradeItem, {itemid = 2526, cost = 1}) -- Buy Item Keywords keywordHandler:addKeyword({'pick'}, sayMessage, {text = 'Picks are hard to come by. I trade them only for high quality small axes.', onlyfocus = true}) keywordHandler:addKeyword({'small', 'axe'}, itemForItem, {itemtrade = 2441, counti = 1, itemtrade2 = 2553, counti2 = 1}) keywordHandler:addKeyword({'rope'}, tradeItem, {itemid = 2120, cost = 50}) keywordHandler:addKeyword({'shovel'}, tradeItem, {itemid = 2554, cost = 10}) keywordHandler:addKeyword({'backpack'}, tradeItem, {itemid = 1988, cost = 10}) keywordHandler:addKeyword({'torch'}, tradeItem, {itemid = 2050, cost = 2}) keywordHandler:addKeyword({'machete'}, tradeItem, {itemid = 2420, cost = 30}) keywordHandler:addKeyword({'scythe'}, tradeItem, {itemid = 2550, cost = 12}) keywordHandler:addKeyword({'rod'}, tradeItem, {itemid = 2580, cost = 150}) keywordHandler:addKeyword({'worm'}, tradeItem, {itemid = 3976, cost = 5, charges = 6, realname = "6-pack of worms", stackable = true}) keywordHandler:addKeyword({'spear'}, tradeItem, {itemid = 2389, cost = 10, stackable = true}) keywordHandler:addKeyword({'rapier'}, tradeItem, {itemid = 2384, cost = 15}) keywordHandler:addKeyword({'sabre'}, tradeItem, {itemid = 2385, cost = 25}) keywordHandler:addKeyword({'dagger'}, tradeItem, {itemid = 2379, cost = 5}) keywordHandler:addKeyword({'sickle'}, tradeItem, {itemid = 2405, cost = 8}) keywordHandler:addKeyword({'hand', 'axe'}, tradeItem, {itemid = 2380, cost = 8}) keywordHandler:addKeyword({'short sword'}, tradeItem, {itemid = 2406, cost = 30}) keywordHandler:addKeyword({'jacket'}, tradeItem, {itemid = 2650, cost = 10}) keywordHandler:addKeyword({'coat'}, tradeItem, {itemid = 2651, cost = 8}) keywordHandler:addKeyword({'doublet'}, tradeItem, {itemid = 2485, cost = 16}) keywordHandler:addKeyword({'leather armor'}, tradeItem, {itemid = 2467, cost = 25}) keywordHandler:addKeyword({'leather legs'}, tradeItem, {itemid = 2649, cost = 10}) keywordHandler:addKeyword({'leather helmet'}, tradeItem, {itemid = 2461, cost = 12}) keywordHandler:addKeyword({'studded helmet'}, tradeItem, {itemid = 2482, cost = 63}) keywordHandler:addKeyword({'chain helmet'}, tradeItem, {itemid = 2458, cost = 52}) keywordHandler:addKeyword({'wooden shield'}, tradeItem, {itemid = 2512, cost = 15}) keywordHandler:addKeyword({'studded shield'}, tradeItem, {itemid = 2526, cost = 50}) keywordHandler:addKeyword({'yes'}, confirmAction, nil) keywordHandler:addKeyword({'no'}, confirmAction, nil) keywordHandler:addKeyword({'offer'}, sayMessage, {text = 'I sell weapons, shields, armor, helmets, and equipment. For what do you want to ask?', onlyfocus = true}) keywordHandler:addKeyword({'wares'}, sayMessage, {text = 'I sell weapons, shields, armor, helmets, and equipment. For what do you want to ask?', onlyfocus = true}) keywordHandler:addKeyword({'sell'}, sayMessage, {text = 'I sell much. Just read the blackboards for my awesome wares or just ask me.', onlyfocus = true}) keywordHandler:addKeyword({'job'}, sayMessage, {text = 'I am a merchant. What can I do for you?', onlyfocus = true}) keywordHandler:addKeyword({'weapon'}, sayMessage, {text = 'I sell spears, rapiers, sabres, daggers, hand axes, axes, and short swords. Just tell me what you want to buy.', onlyfocus = true}) keywordHandler:addKeyword({'armor'}, sayMessage, {text = 'I sell jackets, coats, doublets, leather armor, and leather legs. Just tell me what you want to buy.', onlyfocus = true}) keywordHandler:addKeyword({'helmet'}, sayMessage, {text = 'I sell leather helmets, studded helmets, and chain helmets. Just tell me what you want to buy.', onlyfocus = true}) keywordHandler:addKeyword({'shield'}, sayMessage, {text = 'I sell wooden shields and studded shields. Just tell me what you want to buy.', onlyfocus = true}) keywordHandler:addKeyword({'equipment'}, sayMessage, {text = 'I sell torches, shovels, picks, backpacks, sickles, scythes, ropes, worms and fishing rods. Just tell me what you want to buy.', onlyfocus = true}) keywordHandler:addKeyword({'name'}, sayMessage, {text = 'My name is Al Dee, but you can call me Al. Do you want to buy something?', onlyfocus = true}) keywordHandler:addKeyword({'monster'}, sayMessage, {text = 'If you want to challenge the monsters, you need some weapons and armor I sell. You need them definitely!', onlyfocus = true}) keywordHandler:addKeyword({'dungeon'}, sayMessage, {text = 'If you want to explore the dungeons, you have to equip yourself with the vital stuff I am selling. It\'s vital in the deepest sense of the word.', onlyfocus = true}) keywordHandler:addKeyword({'sewer'}, sayMessage, {text = 'Oh, our sewer system is very primitive; so primitive it\'s overrun by rats. But the stuff I sell is safe from them. Do you want to buy some of it?', onlyfocus = true}) keywordHandler:addKeyword({'king'}, sayMessage, {text = 'The king encouraged salesmen to travel here, but only I dared to take the risk, and a risk it was!', onlyfocus = true}) keywordHandler:addKeyword({'dallheim'}, sayMessage, {text = 'Some call him a hero.', onlyfocus = true}) keywordHandler:addKeyword({'bug'}, sayMessage, {text = 'Bugs plague this isle, but my wares are bugfree, totally bugfree.', onlyfocus = true}) keywordHandler:addKeyword({'stuff'}, sayMessage, {text = 'I sell equipment of all kinds, all kind available on this isle. Just ask me about my wares if you are interested.', onlyfocus = true}) keywordHandler:addKeyword({'tibia'}, sayMessage, {text = 'One day I will return to the continent as a rich, a very rich man!', 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
Billy
-- Billy local internalCustomerQueue = {} local keywordHandler = KeywordHandler:new({root = {}}) local npcHandler = ShopNpcHandler:new({}) local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler}) npcHandler:init(customerQueue, keywordHandler) npcHandler.walkDistance = 1 -- 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() npcHandler:onThink() end -- OTServ event handling functions end -- Keyword handling functions start 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 == cid then selfSay('I am already talking to you.') npcHandler.talkStart = os.clock() elseif npcHandler.focus > 0 or not(npcHandler.queue:isEmpty()) then selfSay('Can\'t you see i am talking? Wait!') if(not npcHandler.queue:isInQueue(cid)) then npcHandler.queue:pushBack(cid) end elseif(npcHandler.focus == 0) and (npcHandler.queue:isEmpty()) then selfSay('Howdy ' .. creatureGetName(cid) .. '.') npcHandler.focus = cid npcHandler.talkStart = os.clock() end return true end function farewell(cid, message, keywords, parameters) if(cid == npcHandler.focus) then selfSay('Bye.') npcHandler:resetNpc() npcHandler.queue:greetNext() return true end return false end -- Keyword handling functions end -- Sell Item Keywords keywordHandler:addKeyword({'sell', 'bread'}, tradeItem, {itemid = 2689, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'cheese'}, tradeItem, {itemid = 2696, cost = 1}) keywordHandler:addKeyword({'sell', 'meat'}, tradeItem, {itemid = 2666, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'ham'}, tradeItem, {itemid = 2671, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'salmon'}, tradeItem, {itemid = 2668, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'fish'}, sayMessage, {text = '"Go away with this stinking $#%^"', onlyfocus = true}) keywordHandler:addKeyword({'sell', 'cherry'}, tradeItem, {itemid = 2679, cost = 1, stackable = true}) keywordHandler:addKeyword({'sell', 'rat'}, tradeItem, {itemid = 2813, cost = 2}) -- Buy Item Keywords keywordHandler:addKeyword({'bread'}, tradeItem, {itemid = 2689, cost = 3, stackable = true}) keywordHandler:addKeyword({'cheese'}, tradeItem, {itemid = 2696, cost = 5}) keywordHandler:addKeyword({'meat'}, tradeItem, {itemid = 2666, cost = 5, stackable = true}) keywordHandler:addKeyword({'ham'}, tradeItem, {itemid = 2671, cost = 8, stackable = true}) keywordHandler:addKeyword({'yes'}, confirmAction, nil) keywordHandler:addKeyword({'no'}, confirmAction, nil) keywordHandler:addKeyword({'offer'}, sayMessage, {text = 'I can offer you bread, cheese, ham, or meat.', onlyfocus = true}) keywordHandler:addKeyword({'wares'}, sayMessage, {text = 'I can offer you bread, cheese, ham, or meat.', onlyfocus = true}) keywordHandler:addKeyword({'sell'}, sayMessage, {text = 'I sell various kinds of food.', onlyfocus = true}) keywordHandler:addKeyword({'job'}, sayMessage, {text = 'I am farmer and a cook.', onlyfocus = true}) keywordHandler:addKeyword({'cook'}, sayMessage, {text = 'I am the best cook around. You can sell me most types of food.', onlyfocus = true}) keywordHandler:addKeyword({'tibia'}, sayMessage, {text = 'There is so much to be explored! Better hurry to get to the continent!', onlyfocus = true}) keywordHandler:addKeyword({'cipfried'}, sayMessage, {text = 'He never leaves this temple and only has time to care about those new arivals.', onlyfocus = true}) keywordHandler:addKeyword({'amber'}, sayMessage, {text = 'Shes pretty indeed! I wonder if she likes bearded men.', onlyfocus = true}) keywordHandler:addKeyword({'god'}, sayMessage, {text = 'I am the god of cooking, indeed!', onlyfocus = true}) keywordHandler:addKeyword({'buy'}, sayMessage, {text = 'I buy food of most kind. Since I am a great cook I need much of it.', onlyfocus = true}) keywordHandler:addKeyword({'willie'}, sayMessage, {text = 'Don\'t listen to that old wannabe, I\'m the best cook around.', onlyfocus = true}) keywordHandler:addKeyword({'name'}, sayMessage, {text = 'Billy.', onlyfocus = true}) keywordHandler:addKeyword({'time'}, sayMessage, {text = 'I came here to have some peace and leisure so leave me alone with \'time\'.', onlyfocus = true}) keywordHandler:addKeyword({'help'}, sayMessage, {text = 'Can\'t help you, sorry. I\'m a cook, not a priest.', onlyfocus = true}) keywordHandler:addKeyword({'monster'}, sayMessage, {text = 'Don\'t be afraid, in the town you should be safe."', onlyfocus = true}) keywordHandler:addKeyword({'dungeon'}, sayMessage, {text = 'You\'ll find a lot of dungeons if you look around.', onlyfocus = true}) keywordHandler:addKeyword({'sewer'}, sayMessage, {text = 'The local sewers are infested by rats, fresh rats give a good stew, you can sell them to me.', onlyfocus = true}) keywordHandler:addKeyword({'king'}, sayMessage, {text = 'The king and his tax collectors are far away. You\'ll meet them soon enough."', onlyfocus = true}) keywordHandler:addKeyword({'obi'}, sayMessage, {text = 'I like him, we usualy have a drink or two once a week and share storys about Willie."', onlyfocus = true}) keywordHandler:addKeyword({'seymour'}, sayMessage, {text = 'I don\'t like his headmaster behaviour. Then again, he IS a headmaster after all.', onlyfocus = true}) keywordHandler:addKeyword({'dallheim'}, sayMessage, {text = 'One of the kings best men, here to protect us.', onlyfocus = true}) keywordHandler:addKeyword({'weapon'}, sayMessage, {text = 'Ask one of the shopkeepers. They make a fortune here with all those wannabe heroes.', onlyfocus = true}) keywordHandler:addKeyword({'spell'}, sayMessage, {text = 'I can spell but know no spell.', onlyfocus = true}) keywordHandler:addKeyword({'magic'}, sayMessage, {text = 'I can spell but know no spell.', 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
Amber
-- Amber local internalCustomerQueue = {} local keywordHandler = KeywordHandler:new({root = {}}) local npcHandler = ShopNpcHandler:new({}) local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler}) npcHandler:init(customerQueue, keywordHandler) npcHandler.walkDistance = 1 -- 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() npcHandler:onThink() end -- OTServ event handling functions end -- Keyword handling functions start 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 == cid then selfSay('I am already talking to you.') npcHandler.talkStart = os.clock() elseif npcHandler.focus > 0 or not(npcHandler.queue:isEmpty()) then selfSay('Sorry, I\'m already talking to someone.') if(not npcHandler.queue:isInQueue(cid)) then npcHandler.queue:pushBack(cid) end elseif(npcHandler.focus == 0) and (npcHandler.queue:isEmpty()) then selfSay('Oh hello, nice to see you ' .. creatureGetName(cid) .. '.') npcHandler.focus = cid npcHandler.talkStart = os.clock() end return true end function farewell(cid, message, keywords, parameters) if(cid == npcHandler.focus) then selfSay('See you later.') npcHandler:resetNpc() npcHandler.queue:greetNext() return true end return false end -- Keyword handling functions end function itemForItem(cid, message, keywords, parameters) if(getPlayerItemCount(cid, parameters.itemtrade) >= parameters.counti) then doPlayerRemoveItem(cid, parameters.itemtrade, parameters.counti) doPlayerAddItem(cid, parameters.itemtrade2, parameters.counti2) selfSay('Excellent. Here, take this short sword, that might serve you well.') else selfSay('Hm, you don\'t have it.') end end keywordHandler:addKeyword({'explore'}, sayMessage, {text = 'I have been almost everywhere in Tibia.', onlyfocus = true}) keywordHandler:addKeyword({'wares'}, sayMessage, {text = 'I fought fierce monsters, climbed the highest mountains, and crossed the sea on a raft.', onlyfocus = true}) keywordHandler:addKeyword({'sea'}, sayMessage, {text = 'My trip over the sea was horrible. The weather was bad, the waves high and my raft quite simple.', onlyfocus = true}) keywordHandler:addKeyword({'raft'}, sayMessage, {text = 'I left my raft at the south eastern shore. I forgot my private notebook on it. If you could return it to me I would be very grateful."', onlyfocus = true}) keywordHandler:addKeyword({'job'}, sayMessage, {text = 'I explore and seek adventure.', onlyfocus = true}) keywordHandler:addKeyword({'weapon'}, sayMessage, {text = 'The best weapons on this isle are just toothpicks, compared with the weapons warriors of the mainland wield.', onlyfocus = true}) keywordHandler:addKeyword({'tibia'}, sayMessage, {text = 'I try to explore each spot of Tibia, and one day I will succeed.', onlyfocus = true}) keywordHandler:addKeyword({'helmet'}, sayMessage, {text = 'Oh, I fought orcs, cyclopses, minotaurs, and even green dragons.', onlyfocus = true}) keywordHandler:addKeyword({'adventure'}, sayMessage, {text = 'I fought fierce monsters, climbed the highest mountains, and crossed the sea on a raft.', onlyfocus = true}) keywordHandler:addKeyword({'sea'}, sayMessage, {text = 'My trip over the sea was horrible. The weather was bad, the waves high and my raft quite simple.', onlyfocus = true}) keywordHandler:addKeyword({'time'}, sayMessage, {text = 'Sorry, I lost my watch in a storm.', onlyfocus = true}) keywordHandler:addKeyword({'help'}, sayMessage, {text = 'I can\'t help you much beyond information.', onlyfocus = true}) keywordHandler:addKeyword({'information'}, sayMessage, {text = 'Just ask and I\'ll try to answer.', onlyfocus = true}) keywordHandler:addKeyword({'dungeon'}, sayMessage, {text = 'I have not had the time to explore the dungeons of this isle, but I have seen two big caves in the east, and there is a ruined tower in the northwest.', onlyfocus = true}) keywordHandler:addKeyword({'sewer'}, sayMessage, {text = 'I like sewers. I made my very first battle experience in the Thais sewers. The small sewersystem of Rookgaard has some nasty rats to fight.', onlyfocus = true}) keywordHandler:addKeyword({'assistant'}, sayMessage, {text = 'I have a job of great responsibility. Mostly I keep annoying persons away from my boss.', onlyfocus = true}) keywordHandler:addKeyword({'monster'}, sayMessage, {text = 'Oh, I fought orcs, cyclopses, minotaurs, and even green dragons.', onlyfocus = true}) keywordHandler:addKeyword({'dragon'}, sayMessage, {text = 'Horrible monsters they are.', onlyfocus = true}) keywordHandler:addKeyword({'minotaur'}, sayMessage, {text = 'Horrible monsters they are.', onlyfocus = true}) keywordHandler:addKeyword({'cyclopse'}, sayMessage, {text = 'Horrible monsters they are.', onlyfocus = true}) keywordHandler:addKeyword({'seymour'}, sayMessage, {text = 'I think this poor guy was a bad choice as the head of the academy.', onlyfocus = true}) keywordHandler:addKeyword({'academy'}, sayMessage, {text = 'A fine institution, but it needs definitely more funds from the king.', onlyfocus = true}) keywordHandler:addKeyword({'king'}, sayMessage, {text = 'King Tibianus is the ruler of Thais.', onlyfocus = true}) keywordHandler:addKeyword({'thais'}, sayMessage, {text = 'A fine city, but the king has some problems enforcing the law.', onlyfocus = true}) keywordHandler:addKeyword({'cipfried'}, sayMessage, {text = 'A gentle person. You should visit him, if you have problems.', onlyfocus = true}) keywordHandler:addKeyword({'dallheim'}, sayMessage, {text = 'An extraordinary warrior. He\'s the first and last line of defense of Rookgaard.', onlyfocus = true}) keywordHandler:addKeyword({'hyacinth'}, sayMessage, {text = 'Hyacinth is a great healer. He lives somewhere hidden on this isle.', onlyfocus = true}) keywordHandler:addKeyword({'willie'}, sayMessage, {text = 'He\'s funny in his own, gruffy way.', onlyfocus = true}) keywordHandler:addKeyword({'obi'}, sayMessage, {text = 'He\'s a funny little man.', onlyfocus = true}) keywordHandler:addKeyword({'magic'}, sayMessage, {text = 'You can learn spells only in the guildhalls of the mainland.', onlyfocus = true}) keywordHandler:addKeyword({'castle'}, sayMessage, {text = 'If you travel to Thais, you really should visit the marvelous castle.', onlyfocus = true}) -- Notebook Quest keywordHandler:addKeyword({'notebook'}, itemForItem, {itemtrade = 2325, counti = 1, itemtrade2 = 2406, counti2 = 1}) 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
Seymour
Note: You WILL need tradeItemForItem function, check here. It should be the last script.
-- Seymour local internalCustomerQueue = {} local keywordHandler = KeywordHandler:new({root = {}}) local npcHandler = ShopNpcHandler:new({}) local customerQueue = CustomerQueue:new({customers = internalCustomerQueue, handler = npcHandler}) npcHandler:init(customerQueue, keywordHandler) npcHandler.walkDistance = 0 -- OTServ event handling functions start function tradeItemForItem(cid, message, keywords, parameters) if npcHandler.focus ~= cid then return false end npcHandler.talkState = TALKSTATE_TRADE_ITEM npcHandler.itemid1 = parameters.itemid1 npcHandler.itemid2 = parameters.itemid2 selfSay('Do you have a suitable present box for me?') return true end 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('Good bye! And remember: No running up and down in the academy!') end npcHandler:resetNpc() npcHandler.queue:greetNext() end local dist = getDistanceToCreature(npcHandler.focus) if dist > 4 then selfSay('Good bye! And remember: No running up and down in the academy!') 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 tradeItem(cid, message, keywords, parameters) if npcHandler.focus ~= cid then return false end local tempcount = getCount(message) if(tempcount > 500) then tempcount = 500 end if(parameters.realname ~= nil) then itemname = parameters.realname end local tradeKeyword = 'buy' if(parameters.realname == 'dead rat') then npcHandler.talkState = TALKSTATE_SELL_ITEM else npcHandler.talkState = TALKSTATE_BUY_ITEM end if(npcHandler.talkState == TALKSTATE_SELL_ITEM) then--"Have you brought a dead rat to me to pick up your reward?" if(tempcount ~= 1) then selfSay('Have you broght ' .. tempcount .. ' ' .. itemname .. 's to me to pick up your reward?') else selfSay('Have you broght a ' .. itemname .. ' to me to pick up your reward?') end else --"Do you want to buy the Key to Adventure for 5 gold coins?" selfSay('Do you want to ' .. tradeKeyword .. ' the ' .. itemname .. ' for ' .. parameters.cost .. ' gold coins?') tempcount = 1 end npcHandler:setActiveItem(parameters.itemid, tempcount, parameters.charges, tempcount*parameters.cost, (parameters.stackable ~= nil and parameters.stackable == true)) return true end function confirmAction(cid, message, keywords, parameters) if npcHandler.focus ~= cid then return false end if(keywords[1] == 'yes') then if(npcHandler.talkState == TALKSTATE_SELL_ITEM) then npcHandler.talkState = TALKSTATE_NONE local ret = doPlayerSellItem(npcHandler.focus, npcHandler.itemid, npcHandler.stackable, npcHandler.count, npcHandler.cost) if(ret == LUA_NO_ERROR) then selfSay('Thank you! Here is your reward.') else if(parameters.itemid2 ~= nil) then local ret = doPlayerSellItem(npcHandler.focus, npcHandler.itemid2, npcHandler.stackable, npcHandler.count, npcHandler.cost) if(ret == LUA_NO_ERROR) then selfSay('Thank you! Here is your reward.') end else if(npcHandler.count == 1) then selfSay('HEY! You don\'t have one! Stop playing tricks on fooling me or I will give you some extra work!') else selfSay('HEY! You do not have so many!') end end end elseif(npcHandler.talkState == TALKSTATE_BUY_ITEM) then npcHandler.talkState = TALKSTATE_NONE local key = 0 if(doPlayerRemoveMoney(cid, npcHandler.cost) == 1) then key = doPlayerAddItem(cid,npcHandler.itemid,npcHandler.count) doSetItemActionId(key,4600) selfSay('Here you are.') else selfSay('You don\'t have enough money.') end elseif(npcHandler.talkState == TALKSTATE_TRADE_ITEM) then npcHandler.talkState = TALKSTATE_NONE if(doPlayerTakeItem(npcHandler.focus, npcHandler.itemid1, false, 1) == LUA_NO_ERROR) then local ret = 0 ret = doPlayerGiveItem(npcHandler.focus, npcHandler.itemid2, false, 1) if(ret == LUA_NO_ERROR) then selfSay('THANK YOU! Here is a helmet that will serve you well.') end else selfSay('HEY! You don\'t have one! Stop playing tricks on me or I will give some extra work!.') end end elseif(keywords[1] == 'no') then if(npcHandler.talkState == TALKSTATE_SELL_ITEM) then selfSay('Go and find some rats to kill!') npcHandler.talkState = TALKSTATE_NONE elseif(npcHandler.talkState == TALKSTATE_BUY_ITEM) then selfSay('As you wish.') npcHandler.talkState = TALKSTATE_NONE elseif(npcHandler.talkState == TALKSTATE_TRADE_ITEM) then selfSay('HEY! You don\'t have one! Stop playing tricks on me or I will give some extra work!') npcHandler.talkState = TALKSTATE_NONE end end return true 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()) then if npcHandler.focus ~= cid then selfSay('Please, ' .. creatureGetName(cid) .. '. Wait for your turn!.') if(not npcHandler.queue:isInQueue(cid)) then npcHandler.queue:pushBack(cid) end else npcHandler.talkStart = os.clock() end elseif(npcHandler.focus == 0) and (npcHandler.queue:isEmpty()) then selfSay('Hello, ' .. creatureGetName(cid) .. '. What do you need?') npcHandler.focus = cid npcHandler.talkStart = os.clock() end return true end function farewell(cid, message, keywords, parameters) if(cid == npcHandler.focus) then selfSay('Good bye! And remember: No running up and down in the academy!') npcHandler:resetNpc() npcHandler.queue:greetNext() return true end return false end -- Keyword handling functions end -- Keyword structure generation start keywordHandler:addKeyword({'key'}, tradeItem, {itemid = 2088, cost = 5, realname = "Key to Adventure"}) keywordHandler:addKeyword({'rat'}, tradeItem, {itemid = 2813, itemid2 = 2814, cost = 2, realname = "dead rat"}) --keywordHandler:addKeyword({'magic sulpher'}, tradeItemForItem, {itemid1 = 2392, count1 = 3, stackable1 = false, itemid2 = 5904, count2 = 1, cost = 0, prize = 0, stackable2 = true, itemname1 = "fire swords"}) keywordHandler:addKeyword({'box'}, tradeItemForItem, {itemid1 = 1990, itemid2 = 2480}) --Do you have a suitable present box for me? keywordHandler:addKeyword({'yes'}, confirmAction, nil) keywordHandler:addKeyword({'no'}, confirmAction, nil) keywordHandler:addKeyword({'mission'}, sayMessage, {text = 'Well I would like to send our king a little present, but I do not have a suitable box. If you find a nice box, please bring it tome.', onlyfocus = true}) keywordHandler:addKeyword({'quest'}, sayMessage, {text = 'Well I would like to send our king a little present, but I do not have a suitable box. If you find a nice box, please bring it tome.', onlyfocus = true}) keywordHandler:addKeyword({'job'}, sayMessage, {text = 'I am the master of this fine academy.', onlyfocus = true}) keywordHandler:addKeyword({'tibia'}, sayMessage, {text = 'Oh, how I miss the crowded streets of Thais. I know one day I will get promoted and get a job at the castle... I must get outof here! The faster the better! It is people like you who are driving me mad.', onlyfocus = true}) keywordHandler:addKeyword({'seymour'}, sayMessage, {text = 'My name is Seymour, but to you I am \'Sir\' Seymour.', onlyfocus = true}) keywordHandler:addKeyword({'name'}, sayMessage, {text = 'My name is Seymour, but to you I am \'Sir\' Seymour.', onlyfocus = true}) keywordHandler:addKeyword({'cipfried'}, sayMessage, {text = 'A humble monk with healing powers, and a pupil of the great Quentin himself.', onlyfocus = true}) keywordHandler:addKeyword({'al', 'dee'}, sayMessage, {text = 'He is a shop owner in the northwestern part of the village.', onlyfocus = true}) keywordHandler:addKeyword({'amber'}, sayMessage, {text = 'A traveller from the main land. I wonder what brought her here, since no one comes here of his own free will.', onlyfocus = true}) keywordHandler:addKeyword({'dallheim'}, sayMessage, {text = 'Oh good Dallheim! What a fighter he is! Without him we would be doomed.', onlyfocus = true}) keywordHandler:addKeyword({'hyacinth'}, sayMessage, {text = 'A mysterious druid who lives somewhere in the wilderness. He sells precious life fluids.', onlyfocus = true}) keywordHandler:addKeyword({'obi'}, sayMessage, {text = 'A cousin of Thais\' smith Sam. He has a shop here where you can buy most stuff an adventurer needs.', onlyfocus = true}) keywordHandler:addKeyword({'willie'}, sayMessage, {text = 'Willie is a fine farmer, although he has short temper.', onlyfocus = true}) keywordHandler:addKeyword({'the oracle'}, sayMessage, {text = 'You will find the oracle upstairs. Talk to the oracle as soon as you have made level 8. Choose a vocation and a new hometown, and you will be sent off to the continent.', onlyfocus = true}) keywordHandler:addKeyword({'hi'}, greet, nil) keywordHandler:addKeyword({'hello'}, greet, nil) keywordHandler:addKeyword({'bye'}, farewell, nil) -- Keyword structure generation end
continua