Advertisement
Guest User

addons.lua

a guest
Mar 13th, 2015
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.67 KB | None | 0 0
  1. local keywordHandler = KeywordHandler:new()
  2. local npcHandler = NpcHandler:new(keywordHandler)
  3. local talkState = {}
  4. local rtnt = {}
  5. function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid)             end
  6. function onCreatureDisappear(cid)             npcHandler:onCreatureDisappear(cid)         end
  7. function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg)     end
  8. function onThink()                             npcHandler:onThink()                         end
  9.  
  10. npcHandler:setMessage(MESSAGE_GREET, "Greetings |PLAYERNAME|. I need your help and I'll reward you with nice addons if you help me! Just say {addons} or {help} if you don't know what to do.")
  11.  
  12. addoninfo = {
  13. ['first citizen addon'] = {cost = 0, items = {{5878,20}}, outfit_female = 136, outfit_male = 128, addon = 1, storageID = 10042},
  14. ['second citizen addon'] = {cost = 0, items = {{5890,50}, {5902,25}, {2480,1}}, outfit_female = 136, outfit_male = 128, addon = 2, storageID = 10043},
  15. ['first hunter addon'] = {cost = 0, items = {{5876,50}, {5948,50}, {5891,5}, {5887,1}, {5889,1}, {5888,1}}, outfit_female = 137, outfit_male = 129, addon = 1, storageID = 10044},
  16. ['second hunter addon'] = {cost = 0, items = {{5875,1}}, outfit_female = 137, outfit_male = 129, addon = 2, storageID = 10045},
  17. ['first knight addon'] = {cost = 0, items = {{5880,50}, {5892,1}}, outfit_female = 139, outfit_male = 131, addon = 1, storageID = 10046},
  18. ['second knight addon'] = {cost = 0, items = {{5893,50}, {11422,1}, {5885,1}, {5887,1}}, outfit_female = 139, outfit_male = 131, addon = 2, storageID = 10047},
  19. ['first mage addon'] = {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 = 10048},
  20. ['second mage addon'] = {cost = 0, items = {{5903,1}}, outfit_female = 138, outfit_male = 130, addon = 2, storageID = 10049},
  21. ['first summoner addon'] = {cost = 0, items = {{5878,20}}, outfit_female = 141, outfit_male = 133, addon = 1, storageID = 10050},
  22. ['second summoner addon'] = {cost = 0, items = {{5894,35}, {5911,20}, {5883,40}, {5922,35}, {5879,10}, {5881,30}, {5882,40}, {2392,3}, {5905,30}}, outfit_female = 141, outfit_male = 133, addon = 2, storageID = 10051},
  23. ['first barbarian addon'] = {cost = 0, items = {{5884,1}, {5885,1}, {5910,25}, {5911,25}, {5886,10}}, outfit_female = 147, outfit_male = 143, addon = 1, storageID = 10011},
  24. ['second barbarian addon'] = {cost = 0, items = {{5880,25}, {5892,1}, {5893,25}, {5876,25}}, outfit_female = 147, outfit_male = 143, addon = 2, storageID = 10012},
  25. ['first druid addon'] = {cost = 0, items = {{5896,20}, {5897,20}}, outfit_female = 148, outfit_male = 144, addon = 1, storageID = 10013},
  26. ['second druid addon'] = {cost = 0, items = {{5906,100}}, outfit_female = 148, outfit_male = 144, addon = 2, storageID = 10014},
  27. ['first nobleman addon'] = {cost = 300000, items = {}, outfit_female = 140, outfit_male = 132, addon = 1, storageID = 10015},
  28. ['second nobleman addon'] = {cost = 300000, items = {}, outfit_female = 140, outfit_male = 132, addon = 2, storageID = 10016},
  29. ['first oriental addon'] = {cost = 0, items = {{5945,1}}, outfit_female = 150, outfit_male = 146, addon = 1, storageID = 10017},
  30. ['second oriental addon'] = {cost = 0, items = {{5883,30}, {5895,30}, {5891,2}, {5912,30}}, outfit_female = 150, outfit_male = 146, addon = 2, storageID = 10018},
  31. ['first warrior addon'] = {cost = 0, items = {{5925,40}, {5899,40}, {5884,1}, {5919,1}}, outfit_female = 142, outfit_male = 134, addon = 1, storageID = 10019},
  32. ['second warrior addon'] = {cost = 0, items = {{5880,40}, {5887,1}}, outfit_female = 142, outfit_male = 134, addon = 2, storageID = 10020},
  33. ['first wizard addon'] = {cost = 0, items = {{2536,1}, {2492,1}, {2488,1}, {2123,1}}, outfit_female = 149, outfit_male = 145, addon = 1, storageID = 10021},
  34. ['second wizard addon'] = {cost = 0, items = {{5922,40}}, outfit_female = 149, outfit_male = 145, addon = 2, storageID = 10022},
  35. ['first assassin addon'] = {cost = 0, items = {{5912,20}, {5910,20}, {5911,20}, {5913,20}, {5914,20}, {5909,20}, {5886,10}}, outfit_female = 156, outfit_male = 152, addon = 1, storageID = 10023},
  36. ['second assassin addon'] = {cost = 0, items = {{5804,1}, {5930,10}}, outfit_female = 156, outfit_male = 152, addon = 2, storageID = 10024},
  37. ['first beggar addon'] = {cost = 0, items = {{5878,30}, {5921,20}, {5913,10}, {5894,10}}, outfit_female = 157, outfit_male = 153, addon = 1, storageID = 10025},
  38. ['second beggar addon'] = {cost = 0, items = {{5883,30}, {2160,2}}, outfit_female = 157, outfit_male = 153, addon = 2, storageID = 10026},
  39. ['first pirate addon'] = {cost = 0, items = {{6098,30}, {6126,30}, {6097,30}}, outfit_female = 155, outfit_male = 151, addon = 1, storageID = 10027},
  40. ['second pirate addon'] = {cost = 0, items = {{6101,1}, {6102,1}, {6100,1}, {6099,1}}, outfit_female = 155, outfit_male = 151, addon = 2, storageID = 10028},
  41. ['first shaman addon'] = {cost = 0, items = {{5810,5}, {3955,5}, {5015,1}}, outfit_female = 158, outfit_male = 154, addon = 1, storageID = 10029},
  42. ['second shaman addon'] = {cost = 0, items = {{3966,5}, {3967,5}}, outfit_female = 158, outfit_male = 154, addon = 2, storageID = 10030},
  43. ['first norseman addon'] = {cost = 0, items = {{7290,5}}, outfit_female = 252, outfit_male = 251, addon = 1, storageID = 10031},
  44. ['second norseman addon'] = {cost = 0, items = {{7290,10}}, outfit_female = 252, outfit_male = 251, addon = 2, storageID = 10032},
  45. ['first jester addon'] = {cost = 0, items = {{5912,20}, {5913,20}, {5914,20}, {5909,20}}, outfit_female = 270, outfit_male = 273, addon = 1, storageID = 10033},
  46. ['second jester addon'] = {cost = 0, items = {{5912,20}, {5910,20}, {5911,20}, {5912,20}}, outfit_female = 270, outfit_male = 273, addon = 2, storageID = 10034},
  47. ['first demonhunter addon'] = {cost = 0, items = {{5905,30}, {5906,40}, {5954,20}, {6500,50}}, outfit_female = 288, outfit_male = 289, addon = 1, storageID = 10035},
  48. ['second demonhunter addon'] = {cost = 0, items = {{5906,50}, {6500,200}}, outfit_female = 288, outfit_male = 289, addon = 2, storageID = 10036},
  49. ['first nightmare addon'] = {cost = 0, items = {{6500,750}}, outfit_female = 269, outfit_male = 268, addon = 1, storageID = 10037},
  50. ['second nightmare addon'] = {cost = 0, items = {{6500,750}}, outfit_female = 269, outfit_male = 268, addon = 2, storageID = 10038},
  51. ['first brotherhood addon'] = {cost = 0, items = {{6500,750}}, outfit_female = 279, outfit_male = 278, addon = 1, storageID = 10039},
  52. ['second brotherhood addon'] = {cost = 0, items = {{6500,750}}, outfit_female = 279, outfit_male = 278, addon = 2, storageID = 10040},
  53. ['first yalaharian addon'] = {cost = 0, items = {{9955,1}}, outfit_female = 324, outfit_male = 325, addon = 1, storageID = 10041},
  54. ['second yalaharian addon'] = {cost = 0, items = {{9955,1}}, outfit_female = 324, outfit_male = 325, addon = 2, storageID = 10041}
  55. -- next storage 10052   -- next storage 10052   -- next storage 10052   -- next storage 10052   -- next storage 10052   -- next storage 10052   -- next storage 10052 --
  56. }
  57. local o = {'citizen', 'hunter', 'knight', 'mage', 'nobleman', 'summoner', 'warrior', 'barbarian', 'druid', 'wizard', 'oriental', 'pirate', 'assassin', 'beggar', 'shaman', 'norseman', 'nighmare', 'jester', 'yalaharian', 'brotherhood'}
  58. function creatureSayCallback(cid, type, msg)
  59. local talkUser = cid
  60.  
  61.     if(not npcHandler:isFocused(cid)) then
  62.         return false
  63.     end
  64.  
  65.     if addoninfo[msg] ~= nil then
  66.         if (getPlayerStorageValue(cid, addoninfo[msg].storageID) ~= -1) then
  67.                 npcHandler:say('You already have this addon!', cid)
  68.                 npcHandler:resetNpc()
  69.         else
  70.         local itemsTable = addoninfo[msg].items
  71.         local items_list = ''
  72.             if table.maxn(itemsTable) > 0 then
  73.                 for i = 1, table.maxn(itemsTable) do
  74.                     local item = itemsTable[i]
  75.                     items_list = items_list .. item[2] .. ' ' .. ItemType(item[1]):getName()
  76.                     if i ~= table.maxn(itemsTable) then
  77.                         items_list = items_list .. ', '
  78.                     end
  79.                 end
  80.             end
  81.         local text = ''
  82.             if (addoninfo[msg].cost > 0) then
  83.                 text = addoninfo[msg].cost .. ' gp'
  84.             elseif table.maxn(addoninfo[msg].items) then
  85.                 text = items_list
  86.             elseif (addoninfo[msg].cost > 0) and table.maxn(addoninfo[msg].items) then
  87.                 text = items_list .. ' and ' .. addoninfo[msg].cost .. ' gp'
  88.             end
  89.             npcHandler:say('For ' .. msg .. ' you will need ' .. text .. '. Do you have it all with you?', cid)
  90.             rtnt[talkUser] = msg
  91.             talkState[talkUser] = addoninfo[msg].storageID
  92.             return true
  93.         end
  94.     elseif msgcontains(msg, "yes") then
  95.         if (talkState[talkUser] > 10010 and talkState[talkUser] < 10100) then
  96.             local items_number = 0
  97.             if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
  98.                 for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
  99.                     local item = addoninfo[rtnt[talkUser]].items[i]
  100.                     if (getPlayerItemCount(cid,item[1]) >= item[2]) then
  101.                         items_number = items_number + 1
  102.                     end
  103.                 end
  104.             end
  105.             if(getPlayerMoney(cid) >= addoninfo[rtnt[talkUser]].cost) and (items_number == table.maxn(addoninfo[rtnt[talkUser]].items)) then
  106.                 doPlayerRemoveMoney(cid, addoninfo[rtnt[talkUser]].cost)
  107.                 if table.maxn(addoninfo[rtnt[talkUser]].items) > 0 then
  108.                     for i = 1, table.maxn(addoninfo[rtnt[talkUser]].items) do
  109.                         local item = addoninfo[rtnt[talkUser]].items[i]
  110.                         doPlayerRemoveItem(cid,item[1],item[2])
  111.                     end
  112.                 end
  113.                 doPlayerAddOutfit(cid, addoninfo[rtnt[talkUser]].outfit_male, addoninfo[rtnt[talkUser]].addon)
  114.                 doPlayerAddOutfit(cid, addoninfo[rtnt[talkUser]].outfit_female, addoninfo[rtnt[talkUser]].addon)
  115.                 setPlayerStorageValue(cid,addoninfo[rtnt[talkUser]].storageID,1)
  116.                 npcHandler:say('Here you are.', cid)
  117.             else
  118.                 npcHandler:say('You do not have needed items!', cid)
  119.             end
  120.             rtnt[talkUser] = nil
  121.             talkState[talkUser] = 0
  122.             npcHandler:resetNpc()
  123.             return true
  124.         end
  125.     elseif msgcontains(msg, "addon") then
  126.         npcHandler:say('I can give you addons for {' .. table.concat(o, "}, {") .. '} outfits.', cid)
  127.         rtnt[talkUser] = nil
  128.         talkState[talkUser] = 0
  129.         npcHandler:resetNpc()
  130.         return true
  131.     elseif msgcontains(msg, "help") then
  132.         npcHandler:say('To buy the first addon say \'first NAME addon\', for the second addon say \'second NAME addon\'.', cid)
  133.         rtnt[talkUser] = nil
  134.         talkState[talkUser] = 0
  135.         npcHandler:resetNpc()
  136.         return true
  137.     else
  138.         if talkState[talkUser] ~= nil then
  139.             if talkState[talkUser] > 0 then
  140.             npcHandler:say('Come back when you get these items.', cid)
  141.             rtnt[talkUser] = nil
  142.             talkState[talkUser] = 0
  143.             npcHandler:resetNpc()
  144.             return true
  145.             end
  146.         end
  147.     end
  148.     return true
  149. end
  150.  
  151. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  152. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement