Guest User

addon npc

a guest
Sep 14th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.48 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. NpcSystem.parseParameters(npcHandler)
  4.  
  5.  
  6. function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
  7. function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid) end
  8. function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg) end
  9. function onThink()                             npcHandler:onThink() end
  10.  
  11. npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. Will you help me? If you do, I'll reward you with nice addons! Just say {addons} or {help} if you don't know what to do.")
  12.  
  13. function playerBuyAddonNPC(cid, message, keywords, parameters, node)
  14.     if(not npcHandler:isFocused(cid)) then
  15.         return false
  16.     end
  17.     if (parameters.confirm ~= true) and (parameters.decline ~= true) then
  18.         if(getPlayerPremiumDays(cid) == 0) and (parameters.premium == true) then
  19.             npcHandler:say('Sorry, but this addon is only for premium players!', cid)
  20.             npcHandler:resetNpc()
  21.             return true
  22.         end
  23.         if (getPlayerStorageValue(cid, parameters.storageID) ~= -1) then
  24.             npcHandler:say('You already have this addon!', cid)
  25.             npcHandler:resetNpc()
  26.             return true
  27.         end
  28.         local itemsTable = parameters.items
  29.         local items_list = ''
  30.         if table.maxn(itemsTable) > 0 then
  31.             for i = 1, table.maxn(itemsTable) do
  32.                 local item = itemsTable[i]
  33.                 items_list = items_list .. item[2] .. ' ' .. getItemNameById(item[1])
  34.                 if i ~= table.maxn(itemsTable) then
  35.                     items_list = items_list .. ', '
  36.                 end
  37.             end
  38.         end
  39.         local text = ''
  40.         if (parameters.cost > 0) and table.maxn(parameters.items) then
  41.             text = items_list .. ' and ' .. parameters.cost .. ' gp'
  42.         elseif (parameters.cost > 0) then
  43.             text = parameters.cost .. ' gp'
  44.         elseif table.maxn(parameters.items) then
  45.             text = items_list
  46.         end
  47.         npcHandler:say('Did you bring me ' .. text .. ' for ' .. keywords[1] .. '?', cid)
  48.         return true
  49.     elseif (parameters.confirm == true) then
  50.         local addonNode = node:getParent()
  51.         local addoninfo = addonNode:getParameters()
  52.         local items_number = 0
  53.         if table.maxn(addoninfo.items) > 0 then
  54.             for i = 1, table.maxn(addoninfo.items) do
  55.                 local item = addoninfo.items[i]
  56.                 if (getPlayerItemCount(cid,item[1]) >= item[2]) then
  57.                     items_number = items_number + 1
  58.                 end
  59.             end
  60.         end
  61.         if(getPlayerMoney(cid) >= addoninfo.cost) and (items_number == table.maxn(addoninfo.items)) then
  62.             doPlayerRemoveMoney(cid, addoninfo.cost)
  63.             if table.maxn(addoninfo.items) > 0 then
  64.                 for i = 1, table.maxn(addoninfo.items) do
  65.                     local item = addoninfo.items[i]
  66.                     doPlayerRemoveItem(cid,item[1],item[2])
  67.                 end
  68.             end
  69.             doPlayerAddOutfit(cid, addoninfo.outfit_male, addoninfo.addon)
  70.             doPlayerAddOutfit(cid, addoninfo.outfit_female, addoninfo.addon)
  71.             setPlayerStorageValue(cid,addoninfo.storageID,1)
  72.             npcHandler:say('Here you are.', cid)
  73.         else
  74.             npcHandler:say('You do not have needed items or cash!', cid)
  75.         end
  76.         npcHandler:resetNpc()
  77.         return true
  78.     elseif (parameters.decline == true) then
  79.         npcHandler:say('Not interested? Maybe other addon?', cid)
  80.         npcHandler:resetNpc()
  81.         return true
  82.     end
  83.     return false
  84. end
  85.  
  86. local noNode = KeywordNode:new({'no'}, playerBuyAddonNPC, {decline = true})
  87. local yesNode = KeywordNode:new({'yes'}, playerBuyAddonNPC, {confirm = true})
  88.  
  89. -- citizen (done)
  90. local outfit_node = keywordHandler:addKeyword({'first citizen addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5878,100}}, outfit_female = 136, outfit_male = 128, addon = 1, storageID = 10001})
  91.     outfit_node:addChildKeywordNode(yesNode)
  92.     outfit_node:addChildKeywordNode(noNode)
  93. local outfit_node = keywordHandler:addKeyword({'second citizen addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5890,100}, {5902,50}, {2480,1}}, outfit_female = 136, outfit_male = 128, addon = 2, storageID = 10002})
  94.     outfit_node:addChildKeywordNode(yesNode)
  95.     outfit_node:addChildKeywordNode(noNode)
  96.  
  97. -- hunter (done)
  98. local outfit_node = keywordHandler:addKeyword({'first hunter addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5947,1}, {5876,100}, {5948,100}, {5891,5}, {5887,1}, {5889,1}, {5888,1}}, outfit_female = 137, outfit_male = 129, addon = 1, storageID = 10003})
  99.     outfit_node:addChildKeywordNode(yesNode)
  100.     outfit_node:addChildKeywordNode(noNode)
  101. local outfit_node = keywordHandler:addKeyword({'second hunter addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5875,1}}, outfit_female = 137, outfit_male = 129, addon = 2, storageID = 10004})
  102.     outfit_node:addChildKeywordNode(yesNode)
  103.     outfit_node:addChildKeywordNode(noNode)
  104.  
  105. -- knight (done)
  106. local outfit_node = keywordHandler:addKeyword({'first knight addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5880,100}, {5892,1}}, outfit_female = 139, outfit_male = 131, addon = 1, storageID = 10005})
  107.     outfit_node:addChildKeywordNode(yesNode)
  108.     outfit_node:addChildKeywordNode(noNode)
  109. local outfit_node = keywordHandler:addKeyword({'second knight addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5893,100}, {5924,1}, {5885,1}, {5887,1}}, outfit_female = 139, outfit_male = 131, addon = 2, storageID = 10006})
  110.     outfit_node:addChildKeywordNode(yesNode)
  111.     outfit_node:addChildKeywordNode(noNode)
  112.  
  113. -- mage (done)
  114. local outfit_node = keywordHandler:addKeyword({'first mage addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{2182,1}, {2186,1}, {2185,1}, {8911,1}, {2181,1}, {2183,1}, {2190,1}, {2191,1}, {2188,1}, {8921,1}, {2189,1}, {2187,1}, {2392,30}, {5809,1}, {2193,20}}, outfit_female = 138, outfit_male = 130, addon = 1, storageID = 10005})
  115. outfit_node:addChildKeywordNode(yesNode)
  116. outfit_node:addChildKeywordNode(noNode)
  117. local outfit_node = keywordHandler:addKeyword({'second mage addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5903,1}}, outfit_female = 138, outfit_male = 130, addon = 2, storageID = 10006})
  118. outfit_node:addChildKeywordNode(yesNode)
  119. outfit_node:addChildKeywordNode(noNode)
  120.  
  121.  
  122. -- summoner (done)
  123. local outfit_node = keywordHandler:addKeyword({'first summoner addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5878,100}}, outfit_female = 141, outfit_male = 133, addon = 1, storageID = 10009})
  124. outfit_node:addChildKeywordNode(yesNode)
  125. outfit_node:addChildKeywordNode(noNode)
  126. local outfit_node = keywordHandler:addKeyword({'second summoner addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5894,70}, {5911,20}, {5883,40}, {5922,35}, {5879,10}, {5881,60}, {5882,40}, {2392,3}, {5905,30}}, outfit_female = 141, outfit_male = 133, addon = 2, storageID = 10010})
  127. outfit_node:addChildKeywordNode(yesNode)
  128. outfit_node:addChildKeywordNode(noNode)
  129.  
  130.  
  131. -- barbarian (done)
  132. local outfit_node = keywordHandler:addKeyword({'first barbarian addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5884,1}, {5885,1}, {5910,50}, {5911,50}, {5886,10}}, outfit_female = 147, outfit_male = 143, addon = 1, storageID = 10011})
  133.     outfit_node:addChildKeywordNode(yesNode)
  134.     outfit_node:addChildKeywordNode(noNode)
  135. local outfit_node = keywordHandler:addKeyword({'second barbarian addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5880,100}, {5892,1}, {5893,50}, {5876,50}}, outfit_female = 147, outfit_male = 143, addon = 2, storageID = 10012})
  136.     outfit_node:addChildKeywordNode(yesNode)
  137.     outfit_node:addChildKeywordNode(noNode)
  138.  
  139. -- druid (done)
  140. local outfit_node = keywordHandler:addKeyword({'first druid addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5896,50}, {5897,50}}, outfit_female = 148, outfit_male = 144, addon = 1, storageID = 10013})
  141.     outfit_node:addChildKeywordNode(yesNode)
  142.     outfit_node:addChildKeywordNode(noNode)
  143. local outfit_node = keywordHandler:addKeyword({'second druid addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5906,100}, {5939,1}, {5940,1}}, outfit_female = 148, outfit_male = 144, addon = 2, storageID = 10014})
  144.     outfit_node:addChildKeywordNode(yesNode)
  145.     outfit_node:addChildKeywordNode(noNode)
  146.  
  147. -- nobleman (done)
  148. local outfit_node = keywordHandler:addKeyword({'first nobleman addon'}, playerBuyAddonNPC, {premium = true, cost = 150000, items = {}, outfit_female = 140, outfit_male = 132, addon = 1, storageID = 10015})
  149.     outfit_node:addChildKeywordNode(yesNode)
  150.     outfit_node:addChildKeywordNode(noNode)
  151. local outfit_node = keywordHandler:addKeyword({'second nobleman addon'}, playerBuyAddonNPC, {premium = true, cost = 150000, items = {}, outfit_female = 140, outfit_male = 132, addon = 2, storageID = 10016})
  152.     outfit_node:addChildKeywordNode(yesNode)
  153.     outfit_node:addChildKeywordNode(noNode)
  154.  
  155. -- oriental (done)
  156. local outfit_node = keywordHandler:addKeyword({'first oriental addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5945,1}}, outfit_female = 150, outfit_male = 146, addon = 1, storageID = 10017})
  157.     outfit_node:addChildKeywordNode(yesNode)
  158.     outfit_node:addChildKeywordNode(noNode)
  159. local outfit_node = keywordHandler:addKeyword({'second oriental addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5883,100}, {5895,100}, {5891,2}, {5912,100}}, outfit_female = 150, outfit_male = 146, addon = 2, storageID = 10018})
  160.     outfit_node:addChildKeywordNode(yesNode)
  161.     outfit_node:addChildKeywordNode(noNode)
  162.  
  163. -- warrior (done)
  164. local outfit_node = keywordHandler:addKeyword({'first warrior addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5925,100}, {5899,100}, {5884,1}, {5919,1}}, outfit_female = 142, outfit_male = 134, addon = 1, storageID = 10019})
  165.     outfit_node:addChildKeywordNode(yesNode)
  166.     outfit_node:addChildKeywordNode(noNode)
  167. local outfit_node = keywordHandler:addKeyword({'second warrior addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5880,100}, {5887,1}}, outfit_female = 142, outfit_male = 134, addon = 2, storageID = 10020})
  168.     outfit_node:addChildKeywordNode(yesNode)
  169.     outfit_node:addChildKeywordNode(noNode)
  170.  
  171. -- wizard (done)
  172. local outfit_node = keywordHandler:addKeyword({'first wizard addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{2536,1}, {2492,1}, {2488,1}, {2123,1}}, outfit_female = 149, outfit_male = 145, addon = 1, storageID = 10021})
  173.     outfit_node:addChildKeywordNode(yesNode)
  174.     outfit_node:addChildKeywordNode(noNode)
  175. local outfit_node = keywordHandler:addKeyword({'second wizard addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5922,50}}, outfit_female = 149, outfit_male = 145, addon = 2, storageID = 10022})
  176.     outfit_node:addChildKeywordNode(yesNode)
  177.     outfit_node:addChildKeywordNode(noNode)
  178.  
  179. -- assassin (done)
  180. local outfit_node = keywordHandler:addKeyword({'first assassin addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5912,50}, {5910,50}, {5911,50}, {5913,50}, {5914,50}, {5909,50}, {5886,10}}, outfit_female = 156, outfit_male = 152, addon = 1, storageID = 10023})
  181.     outfit_node:addChildKeywordNode(yesNode)
  182.     outfit_node:addChildKeywordNode(noNode)
  183. local outfit_node = keywordHandler:addKeyword({'second assassin addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5804,1}, {5930,10}}, outfit_female = 156, outfit_male = 152, addon = 2, storageID = 10024})
  184.     outfit_node:addChildKeywordNode(yesNode)
  185.     outfit_node:addChildKeywordNode(noNode)
  186.  
  187. -- beggar (done)
  188. local outfit_node = keywordHandler:addKeyword({'first beggar addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5878,50}, {5921,30}, {5913,20}, {5894,10}}, outfit_female = 157, outfit_male = 153, addon = 1, storageID = 10025})
  189.     outfit_node:addChildKeywordNode(yesNode)
  190.     outfit_node:addChildKeywordNode(noNode)
  191. local outfit_node = keywordHandler:addKeyword({'second beggar addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5883,100}, {2160,2}, {6107,1}}, outfit_female = 157, outfit_male = 153, addon = 2, storageID = 10026})
  192.     outfit_node:addChildKeywordNode(yesNode)
  193.     outfit_node:addChildKeywordNode(noNode)
  194.  
  195. -- pirate (done)
  196. local outfit_node = keywordHandler:addKeyword({'first pirate addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6098,100}, {6126,100}, {6097,100}}, outfit_female = 155, outfit_male = 151, addon = 1, storageID = 10027})
  197.     outfit_node:addChildKeywordNode(yesNode)
  198.     outfit_node:addChildKeywordNode(noNode)
  199. local outfit_node = keywordHandler:addKeyword({'second pirate addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6101,1}, {6102,1}, {6100,1}, {6099,1}}, outfit_female = 155, outfit_male = 151, addon = 2, storageID = 10028})
  200.     outfit_node:addChildKeywordNode(yesNode)
  201.     outfit_node:addChildKeywordNode(noNode)
  202.  
  203. -- shaman (done)
  204. local outfit_node = keywordHandler:addKeyword({'first shaman addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5810,5}, {3955,5}, {5015,1}}, outfit_female = 158, outfit_male = 154, addon = 1, storageID = 10029})
  205.     outfit_node:addChildKeywordNode(yesNode)
  206.     outfit_node:addChildKeywordNode(noNode)
  207. local outfit_node = keywordHandler:addKeyword({'second shaman addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{3966,5}, {3967,5}}, outfit_female = 158, outfit_male = 154, addon = 2, storageID = 10030})
  208.     outfit_node:addChildKeywordNode(yesNode)
  209.     outfit_node:addChildKeywordNode(noNode)
  210.  
  211. -- norseman (done)
  212. local outfit_node = keywordHandler:addKeyword({'first norseman addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{7290,5}}, outfit_female = 252, outfit_male = 251, addon = 1, storageID = 10031})
  213.     outfit_node:addChildKeywordNode(yesNode)
  214.     outfit_node:addChildKeywordNode(noNode)
  215. local outfit_node = keywordHandler:addKeyword({'second norseman addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{7290,10}}, outfit_female = 252, outfit_male = 251, addon = 2, storageID = 10032})
  216.     outfit_node:addChildKeywordNode(yesNode)
  217.     outfit_node:addChildKeywordNode(noNode)
  218.  
  219. -- jester (done)(custom)
  220. local outfit_node = keywordHandler:addKeyword({'first jester addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5912,50}, {5913,50}, {5914,50}, {5909,50}}, outfit_female = 270, outfit_male = 273, addon = 1, storageID = 10033})
  221.     outfit_node:addChildKeywordNode(yesNode)
  222.     outfit_node:addChildKeywordNode(noNode)
  223. local outfit_node = keywordHandler:addKeyword({'second jester addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5912,50}, {5910,50}, {5911,50}, {5912,50}}, outfit_female = 270, outfit_male = 273, addon = 2, storageID = 10034})
  224.     outfit_node:addChildKeywordNode(yesNode)
  225.     outfit_node:addChildKeywordNode(noNode)
  226.  
  227. -- demonhunter (done)(custom)
  228. local outfit_node = keywordHandler:addKeyword({'first demonhunter addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5905,30}, {5906,40}, {5954,50}, {6500,50}, {2151,100}}, outfit_female = 288, outfit_male = 289, addon = 1, storageID = 10035})
  229.     outfit_node:addChildKeywordNode(yesNode)
  230.     outfit_node:addChildKeywordNode(noNode)
  231. local outfit_node = keywordHandler:addKeyword({'second demonhunter addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{5906,50}, {6500,200}, {2151,100}}, outfit_female = 288, outfit_male = 289, addon = 2, storageID = 10036})
  232.     outfit_node:addChildKeywordNode(yesNode)
  233.     outfit_node:addChildKeywordNode(noNode)
  234.  
  235. -- nightmare (done)(custom)
  236. local outfit_node = keywordHandler:addKeyword({'first nightmare addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6500,1500}}, outfit_female = 269, outfit_male = 268, addon = 1, storageID = 10037})
  237.     outfit_node:addChildKeywordNode(yesNode)
  238.     outfit_node:addChildKeywordNode(noNode)
  239. local outfit_node = keywordHandler:addKeyword({'second nightmare addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6500,1500}}, outfit_female = 269, outfit_male = 268, addon = 2, storageID = 10038})
  240.     outfit_node:addChildKeywordNode(yesNode)
  241.     outfit_node:addChildKeywordNode(noNode)
  242.  
  243. -- brotherhood (done)(custom)
  244. local outfit_node = keywordHandler:addKeyword({'first brotherhood addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6500,1500}}, outfit_female = 279, outfit_male = 278, addon = 1, storageID = 10039})
  245.     outfit_node:addChildKeywordNode(yesNode)
  246.     outfit_node:addChildKeywordNode(noNode)
  247. local outfit_node = keywordHandler:addKeyword({'second brotherhood addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{6500,1500}}, outfit_female = 279, outfit_male = 278, addon = 2, storageID = 10040})
  248.     outfit_node:addChildKeywordNode(yesNode)
  249.     outfit_node:addChildKeywordNode(noNode)
  250.  
  251. -- yalaharian (done)(custom)
  252. local outfit_node = keywordHandler:addKeyword({'first yalaharian addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{9955,1}}, outfit_female = 324, outfit_male = 325, addon = 1, storageID = 10041})
  253.     outfit_node:addChildKeywordNode(yesNode)
  254.     outfit_node:addChildKeywordNode(noNode)
  255. local outfit_node = keywordHandler:addKeyword({'second yalaharian addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{9955,1}}, outfit_female = 324, outfit_male = 325, addon = 2, storageID = 10041})
  256.     outfit_node:addChildKeywordNode(yesNode)
  257.     outfit_node:addChildKeywordNode(noNode)
  258.  
  259. -- warmaster (done)(custom)
  260. local outfit_node = keywordHandler:addKeyword({'first warmaster addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{11112,1}}, outfit_female = 336, outfit_male = 335, addon = 1, storageID = 10042})
  261.     outfit_node:addChildKeywordNode(yesNode)
  262.     outfit_node:addChildKeywordNode(noNode)
  263. local outfit_node = keywordHandler:addKeyword({'second warmaster addon'}, playerBuyAddonNPC, {premium = true, cost = 0, items = {{11111,1}}, outfit_female = 336, outfit_male = 335, addon = 2, storageID = 10043})
  264.     outfit_node:addChildKeywordNode(yesNode)
  265.     outfit_node:addChildKeywordNode(noNode)
  266.  
  267. -- wayfarer (done)(custom)
  268. local outfit_node = keywordHandler:addKeyword({'first wayfarer addon'}, playerBuyAddonNPC, {premium = true, cost = 500000, items = {}, outfit_female = 366, outfit_male = 367, addon = 1, storageID = 10044})
  269.     outfit_node:addChildKeywordNode(yesNode)
  270.     outfit_node:addChildKeywordNode(noNode)
  271. local outfit_node = keywordHandler:addKeyword({'second wayfarer addon'}, playerBuyAddonNPC, {premium = true, cost = 1000000, items = {}, outfit_female = 366, outfit_male = 367, addon = 2, storageID = 10045})
  272.     outfit_node:addChildKeywordNode(yesNode)
  273.     outfit_node:addChildKeywordNode(noNode)
  274.  
  275. keywordHandler:addKeyword({'addons'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can give you {citizen}, {hunter}, {knight}, {mage}, {nobleman}, {summoner}, {warrior}, {barbarian}, {druid}, {wizard}, {oriental}, {pirate}, {assassin}, {beggar}, {shaman}, {norseman}, {nighmare}, {jester}, {yalaharian}, {brotherhood}, {warmaster} and {wayfarer} addons.'})
  276. keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'To buy the first addon say \'first NAME addon\', for the second addon say \'second NAME addon\'.'})
  277.  
  278. npcHandler:addModule(FocusModule:new())
Add Comment
Please, Sign In to add comment