- Joined
- Aug 6, 2007
- Messages
- 1,767
- Reaction score
- 36
yea i stole this from ******, if you want to whine because i took the npc examples from an other forum, Please go to the richt top of your screen and click on the X.
If you want more examples tell me what kind of npc and i'll make an example from it
Thx for reminindig me Ispro i totally forgot it!
Credits to Jiddo for maiking the examples!
Npcs:
data\npc\Boat.xml (All functions are in lua):
data\npc\scripts\travel.lua:
[/quote]
Npc buys all empty vial script:
If you want more examples tell me what kind of npc and i'll make an example from it
Thx for reminindig me Ispro i totally forgot it!
Credits to Jiddo for maiking the examples!
Npcs:
data\npc\Distance.xml:
Code:<npc name="Frenzy" script="data/npc/scripts/distance.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look type="134" head="57" body="59" legs="40" feet="76" corpse="2212"/> <parameters> <parameter key="module_shop" value="1" /> <parameter key="shop_sellable" value="crossbow,2455,150;bow,2456,130" /> <parameter key="shop_buyable" value="crossbow,2455,360;bow,2456,200;spear,2389,20;power bolt,2547,200;burst arrow,2546,56;poison arrow,2545,18;bolt,2543,3;arrow,2544,2" /> </parameters> </npc>
data\npc\scripts\distance.lua:
Code:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end npcHandler:addModule(FocusModule:new())
data\npc\Boat.xml (most functions in boat.xml):
Code:<npc name="Captain Steven" script="data/npc/scripts/travel.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look type="133" head="20" body="120" legs="75" feet="13" corpse="2212"/> <parameters> <parameter key="module_travel" value="1" /> <parameter key="travel_destinations" value="derelin,1294,429,6,119;farda,865,251,6,123;taqinata,868,690,6,134" /> <parameter key="module_keywords" value="1" /> <parameter key="keywords" value="job;name;offer;help;mission;quest" /> <parameter key="keyword_reply1" value="I am the captain of this ship." /> <parameter key="keyword_reply2" value="My name is Steven. Why do you ask?" /> <parameter key="keyword_reply3" value="I offer only the possability to travel to far away cities on this continent." /> <parameter key="keyword_reply4" value="Do I look like a helpful guy to you?" /> <parameter key="keyword_reply5" value="What are you talking about?" /> <parameter key="keyword_reply6" value="Hum. I'll tell you what! If you come back in a month or so I might be able to help you with that my friend." /> </parameters> </npc>
data\npc\scripts\travel.lua:
Code:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end -- Makes sure the npc reacts when you say hi, bye etc. npcHandler:addModule(FocusModule:new())
data\npc\Boat.xml (All functions are in lua):
Code:
<npc name="Captain Steven" script="data/npc/scripts/travel.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1">
<health now="150" max="150"/>
<look type="133" head="20" body="120" legs="75" feet="13" corpse="2212"/>
<parameters>
</parameters>
</npc>
data\npc\scripts\travel.lua:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
-- OTServ event handling functions start
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
-- OTServ event handling functions end
-- Don't forget npcHandler = npcHandler in the parameters. It is required for all StdModule functions!
local travelNode = keywordHandler:addKeyword({'derelin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to travel to Derelin for 119 gold coins?'})
travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 119, destination = {x=1367, y=403, z=7} })
travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'I wouldn\'t go there either.'})
local travelNode = keywordHandler:addKeyword({'drunia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to travel to Drunia for 123 gold coins?'})
travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = false, level = 0, cost = 123, destination = {x=967, y=247, z=7} })
travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Too expensive, eh?'})
keywordHandler:addKeyword({'destination'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to Derelin or Drunia for just a small fee.'})
-- Makes sure the npc reacts when you say hi, bye etc.
npcHandler:addModule(FocusModule:new())
data\npc\King.xml:
Code:<npc name="The King" script="data/npc/scripts/promotion.lua" autowalk="0" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look type="137" head="140" body="64" legs="121" feet="76" corpse="2212"/> <parameters> <parameter key="message_farewell" value="Farewell |PLAYERNAME|!" /> </parameters> </npc>
data\npc\script\promotion.lua:
Code:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end local node1 = keywordHandler:addKeyword({'promot'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can promote you for 20000 gold coins. Do you want me to promote you?'}) node1:addChildKeyword({'yes'}, StdModule.promotePlayer, {npcHandler = npcHandler, promotions = {[1] = 5, [2] = 6, [3] = 7, [4] = 8}, cost = 20000, level = 20, text = 'Congratulations! You are now promoted.'}) node1:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Allright then. Come back when you are ready.', reset = true}) npcHandler:addModule(FocusModule:new())
data\npc\Oracle.xml:
Code:<npc name="The Oracle" script="data/npc/scripts/oracle.lua" autowalk="0" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look typeex="1448" corpse="2212"/> <parameters> </parameters> </npc>
data\npc\scripts\oracle.lua:
Code:local LEVEL = 8 local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end function oracle(cid, message, keywords, parameters, node) if(cid ~= npcHandler.focus) then return false end local cityNode = node:getParent():getParent() local vocNode = node:getParent() local destination = cityNode:getParameters().destination local townid = cityNode:getParameters().townid local voc = vocNode:getParameters().voc if(destination ~= nil and voc ~= nil and townid ~= nil) then if(getPlayerLevel(cid) < parameters.level) then npcHandler:say('You must first reach level ' .. parameters.level .. '!') else doPlayerSetVocation(cid,voc) doPlayerSetTown(cid,townid) --doPlayerSetMasterPos(cid,destination) doTeleportThing(cid,destination) end else error('Destination:', destination, 'Vocation:', vocation, 'Townid:', townid) end npcHandler:resetNpc() return true end function greetCallback(cid) if(getPlayerLevel(cid) < LEVEL) then npcHandler:say('CHILD! COME BACK WHEN YOU HAVE GROWN UP!') return false else return true end end -- Set the greeting callback function npcHandler:setCallback(CALLBACK_GREET, greetCallback) -- Set the greeting message. npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. Are you prepared to face your destiny?') -- Pre-create the yes/no nodes. local yesNode = KeywordNode:new({'yes'}, oracle, {level = LEVEL}) local noNode = KeywordNode:new({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, moveup = 1, text = 'Then what vocation do you want to become?'}) -- Create the actual keyword structure... local node1 = keywordHandler:addKeyword({'yes'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'What city do you wish to live in? Derelin or Drunia?'}) local node2 = node1:addChildKeyword({'derelin'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, townid = 3, destination = {x=1330, y=368, z=7}, text = 'The desert city of Derelin, eh? So what vocation do you wish to become? Sorcerer, druid, paladin or knight?'}) local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, voc = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, voc = 2, onlyFocus = true, text = 'Are you sure that a druid is what you wish to become? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, voc = 3, onlyFocus = true, text = 'A ranged marksman. Are you sure? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, voc = 4, onlyFocus = true, text = 'A mighty warrior. Is that your final decision? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node2 = node1:addChildKeyword({'drunia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, townid = 1, destination = {x=939, y=263, z=7}, text = 'The town of Drunia, eh? So what vocation do you wish to become? Sorcerer, druid, paladin or knight?'}) local node3 = node2:addChildKeyword({'sorcerer'}, StdModule.say, {npcHandler = npcHandler, voc = 1, onlyFocus = true, text = 'So, you wish to be a powerful magician? Are you sure about that? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'druid'}, StdModule.say, {npcHandler = npcHandler, voc = 2, onlyFocus = true, text = 'Are you sure that a druid is what you wish to become? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'paladin'}, StdModule.say, {npcHandler = npcHandler, voc = 3, onlyFocus = true, text = 'A ranged marksman. Are you sure? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) local node3 = node2:addChildKeyword({'knight'}, StdModule.say, {npcHandler = npcHandler, voc = 4, onlyFocus = true, text = 'A mighty warrior. Is that your final decision? This decision is irreversible!'}) node3:addChildKeywordNode(yesNode) node3:addChildKeywordNode(noNode) keywordHandler:addKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Then come back when you are ready.'}) -- Make it react to hi/bye etc. npcHandler:addModule(FocusModule:new())
data\npc\Runes.xml:
Code:<npc name="Mike" script="data/npc/scripts/runes.lua" autowalk="1" floorchange="0" access="5" level="1" maglevel="1"> <health now="150" max="150"/> <look type="130" head="39" body="122" legs="125" feet="57" corpse="2212"/> <parameters> <parameter key="message_greet" value="Hello |PLAYERNAME|. Do you want to buy any spell runes?" /> <parameter key="message_needmoremoney" value="You do not have enough money." /> <parameter key="message_decline" value="Is |TOTALCOST| gold coins too much for you? Get out of here!" /> </parameters> </npc>
data\npc\scripts\runes.lua:
Code:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end local shopModule = ShopModule:new() npcHandler:addModule(shopModule) shopModule:addBuyableItem({'light wand', 'lightwand'}, 2163, 500, 'magic light wand') shopModule:addBuyableItem({'mana fluid', 'manafluid'}, 2006, 100, 7, 'mana fluid') shopModule:addBuyableItem({'life fluid', 'lifefluid'}, 2006, 80, 10, 'life fluid') shopModule:addBuyableItem({'heavy magic missile', 'hmm'}, 2311, 125, 10, 'heavy magic missile rune') shopModule:addBuyableItem({'great fireball', 'gfb'}, 2304, 180, 4, 'great fireball rune') shopModule:addBuyableItem({'explo', 'xpl'}, 2313, 250, 6, 'explosion rune') shopModule:addBuyableItem({'ultimate healing', 'uh'}, 2273, 175, 2, 'ultimate healing rune') shopModule:addBuyableItem({'sudden death', 'sd'}, 2268, 325, 2, 'sudden death rune') shopModule:addBuyableItem({'blank', 'rune'}, 2260, 10, 'blank rune') npcHandler:addModule(FocusModule:new())
Npc buys all empty vial script:
add this at the bottem of data/global.lua:
Code:PLAYERSLOT_FIRST = 1 PLAYERSLOT_LAST = 10 function removePlayerItemsWithCharges(cid, itemid, charges) if(isItemRune(itemid) ~= TRUE and isItemFluidContainer(itemid) ~= TRUE) then error('[Error] removePlayerItemsWithCharges: Item ' .. itemid .. ' is not a rune or fluid container.', 2) return 0 end local n = 0 for slot = PLAYERSLOT_FIRST, PLAYERSLOT_LAST, 1 do local item = getPlayerSlotItem(cid, slot) if(item.itemid > 0) then if(item.itemid == itemid and item.type == charges) then if(doRemoveItem(item.uid, -1) == LUA_NO_ERROR) then n = n + 1 else print('[Warning] removePlayerItemsWithCharges: ', 'Could not remove item with uid ' .. item.uid) end elseif(isContainer(item.uid) == TRUE) then n = n + removeContainerItemsWithCharges(item.uid, itemid, charges) end end end return n end function removeContainerItemsWithCharges(uid, itemid, charges) if(isItemRune(itemid) ~= TRUE and isItemFluidContainer(itemid) ~= TRUE) then error('[Error] removeContainerItemsWithCharges: Item ' .. itemid .. ' is not a rune or fluid container.', 2) return 0 end local n = 0 local slot = 0 local cap = getContainerCap(uid) while(slot <= cap) do local item = getContainerItem(uid, slot) if(item.itemid > 0) then if(item.itemid == itemid and item.type == charges) then if(doRemoveItem(item.uid, -1) == LUA_NO_ERROR) then n = n+1 slot = slot-1 else print('[Warning] removeContainerItemsWithCharges: ', 'Could not remove item with uid ' .. item.uid) end elseif(isContainer(item.uid) == TRUE) then n = n + removeContainerItemsWithCharges(item.uid, itemid, charges) end end slot = slot+1 end return n end
the buy vials buildet in the rune npc data/npcs/scripts/runes.lua:
Code:local keywordHandler = KeywordHandler:new() local npcHandler = NpcHandler:new(keywordHandler) NpcSystem.parseParameters(npcHandler) -- OTServ event handling functions start 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 -- OTServ event handling functions end function returnVials(cid, message, keywords, parameters, node) if(npcHandler.focus ~= cid) then return false end local amount = removePlayerItemsWithCharges(cid, parameters.itemid, parameters.charges) if(amount <= 0) then npcHandler:say('You do not have any.') else local price = amount*parameters.cost if(doPlayerAddMoney(cid, price) == LUA_NO_ERROR) then npcHandler:say('Here are your reward of ' .. price .. ' gold coins. It was a pleasure doing business with you.') else error('[Error] returnVials:', 'Could not give ' .. price .. ' gold coins to player ' .. getPlayerName(cid)) end end npcHandler:resetNpc() return true end local shopModule = ShopModule:new() npcHandler:addModule(shopModule) shopModule:addBuyableItem({'light wand', 'lightwand'}, 2163, 500, 1, 'magic light wand') shopModule:addBuyableItem({'mana fluid', 'manafluid'}, 2006, 100, 7, 'mana fluid') shopModule:addBuyableItem({'life fluid', 'lifefluid'}, 2006, 80, 10, 'life fluid') shopModule:addBuyableItem({'heavy magic missile', 'hmm'}, 2311, 125, 10, 'heavy magic missile rune') shopModule:addBuyableItem({'great fireball', 'gfb'}, 2304, 180, 4, 'great fireball rune') shopModule:addBuyableItem({'explo', 'xpl'}, 2313, 250, 6, 'explosion rune') shopModule:addBuyableItem({'ultimate healing', 'uh'}, 2273, 175, 2, 'ultimate healing rune') shopModule:addBuyableItem({'sudden death', 'sd'}, 2268, 325, 2, 'sudden death rune') shopModule:addBuyableItem({'blank', 'rune'}, 2260, 10, 1, 'blank rune') local node = keywordHandler:addKeyword({'flask'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you wish to return all your empty vials for 5 gold coins each?'}) node:addChildKeyword({'yes'}, returnVials, {itemid = 2006, charges = 0, cost = 5}) node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Allright then.'}) npcHandler:addModule(FocusModule:new())
Last edited by a moderator: