Advertisement
Guest User

monsteritemsmissions

a guest
Mar 16th, 2015
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.93 KB | None | 0 0
  1. -- Collecting items and monster missions by Limos
  2. local keywordHandler = KeywordHandler:new()
  3. local npcHandler = NpcHandler:new(keywordHandler)
  4. NpcSystem.parseParameters(npcHandler)
  5.  
  6. local talkState = {}
  7.  
  8. function onCreatureAppear(cid)           npcHandler:onCreatureAppear(cid) end
  9. function onCreatureDisappear(cid)          npcHandler:onCreatureDisappear(cid) end
  10. function onCreatureSay(cid, type, msg)         npcHandler:onCreatureSay(cid, type, msg) end
  11. function onThink()              npcHandler:onThink() end
  12.  
  13. local missions = {
  14.     [1] = {
  15.         items = {
  16.             {id = 5890, count = 12},
  17.             {id = 5878, count = 20},
  18.             {id = 5894, count = 8}
  19.         },
  20.         message = "Great, for your first mission you need to collect some items, I need",
  21.         level = 15, -- minimum level voor this mission
  22.         rewarditems = {
  23.             {id = 2160, count = 1},
  24.             {id = 2152, count = 1}
  25.         },
  26.         rewardexp = 15000
  27.     },
  28.     [2] = {
  29.         monsters = {
  30.             {name = "Rats", count = 20, storage = 21900},
  31.             {name = "Rotworms", count = 26, storage = 21901}
  32.         },
  33.         message = "Thanks, for your next mission kill",
  34.         level = 30,
  35.         rewarditems = {
  36.             {id = 2160, count = 5}
  37.         },
  38.         rewardexp = 40000
  39.     },
  40.     [3] = {
  41.         items = {
  42.             {id = 5920, count = 45},
  43.             {id = 5877, count = 22}
  44.         },
  45.         message = "Awesome, now get",
  46.         level = 50,
  47.         rewarditems = {
  48.             {id = 2160, count = 15}
  49.         },
  50.         rewardexp = 100000
  51.     },
  52.     [4] = {
  53.         monsters = {
  54.             {name = "Dragon Lords", count = 25, storage = 21902}
  55.         },
  56.         message = "Good job, now kill",
  57.         level = 70,
  58.         rewarditems = {
  59.             {id = 2160, count = 25}
  60.         },
  61.         rewardexp = 200000
  62.     },
  63.     [5] = {
  64.         items = {
  65.             {id = 5906, count = 35},
  66.             {id = 5882, count = 42},
  67.             {id = 4850, count = 1}
  68.         },
  69.         message = "Good, now your final mission, there are a few more items you need to get,",
  70.         level = 100,
  71.         rewarditems = {
  72.             {id = 2160, count = 50}
  73.         },
  74.         rewardexp = 450000
  75.     }
  76. }
  77.  
  78. local storage = 45551
  79.  
  80. local function getItemsMonstersFromTable(imtable)
  81.         local text = ""
  82.         for v = 1, #imtable do
  83.                 local ret = ", "
  84.                 if v == 1 then
  85.                         ret = ""
  86.                 elseif v == #imtable then
  87.                         ret = " and "
  88.                 end
  89.                 text = text .. ret
  90.                 count = imtable[v].count
  91.                 if imtable[v].id then
  92.                         info = getItemInfo(imtable[v].id)
  93.                         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  94.                 else
  95.                         text = text .. count .." "..imtable[v].name
  96.                 end
  97.         end
  98.         return text
  99. end
  100.  
  101. function creatureSayCallback(cid, type, msg)
  102.  
  103.         local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
  104.  
  105.         if not npcHandler:isFocused(cid) then
  106.                 return false
  107.         end
  108.        
  109.         local x = missions[getPlayerStorageValue(cid, storage)]
  110.  
  111.         if msgcontains(msg, 'mission') or msgcontains(msg, 'quest') then
  112.                 if getPlayerStorageValue(cid, storage) == -1 then
  113.                         selfSay("I have several missions for you, do you accept the challenge?", cid)
  114.                         talkState[talkUser] = 1
  115.                 elseif x then
  116.                         if getPlayerLevel(cid) >= x.level then
  117.                                 local mess = x.items and "get "..getItemsMonstersFromTable(x.items) or "kill "..getItemsMonstersFromTable(x.monsters)
  118.                                 selfSay("Did you "..mess.."?", cid)
  119.                                 talkState[talkUser] = 1
  120.                         else
  121.                                 selfSay("The mission I gave you is for level "..x.level..", come back later.", cid)
  122.                         end
  123.                 else
  124.                         selfSay("You already did all the missions, great job though.", cid)
  125.                         npcHandler:releaseFocus(cid)
  126.                 end
  127.         elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
  128.                 if getPlayerStorageValue(cid, storage) == -1 then
  129.                         setPlayerStorageValue(cid, storage, 1)
  130.                         local x = missions[getPlayerStorageValue(cid, storage)]
  131.                         local imtable = x.items or x.monsters
  132.                         selfSay(x.message.." "..getItemsMonstersFromTable(imtable)..".", cid)
  133.                 elseif x then
  134.                         local imtable = x.items or x.monsters
  135.                         local amount = 0
  136.                         for it = 1, #imtable do
  137.                                 local check = x.items and getPlayerItemCount(cid, imtable[it].id) or getPlayerStorageValue(cid, imtable[it].storage)
  138.                                 if check >= imtable[it].count then
  139.                                         amount = amount + 1
  140.                                 end
  141.                         end
  142.                         if amount == #imtable then
  143.                                 if x.items then
  144.                                         for it = 1, #x.items do
  145.                                                 doPlayerRemoveItem(cid, x.items[it].id, x.items[it].count)
  146.                                         end
  147.                                 end
  148.                                 if x.rewarditems then
  149.                                         for r = 1, #x.rewarditems do
  150.                                                 doPlayerAddItem(cid, x.rewarditems[r].id, x.rewarditems[r].count)
  151.                                         end
  152.                                         doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..getItemsMonstersFromTable(x.rewarditems)..".")
  153.                                 end
  154.                                 if x.rewardexp then
  155.                                         doPlayerAddExp(cid, x.rewardexp)
  156.                                         doPlayerSendTextMessage(cid, MESSAGE_EVENT_DEFAULT, "You received "..x.rewardexp.." experience.")
  157.                                 end
  158.                                 setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) + 1)
  159.                                 local x = missions[getPlayerStorageValue(cid, storage)]
  160.                                 if x then
  161.                                         selfSay(x.message.." "..getItemsMonstersFromTable(x.items or x.monsters)..".", cid)
  162.                                 else
  163.                                         selfSay("Well done! You did a great job on all your missions.", cid)
  164.                                 end
  165.                         else
  166.                                 local n = 0
  167.                                 for i = 1, #imtable do
  168.                                         local check = x.items and getPlayerItemCount(cid, imtable[i].id) or getPlayerStorageValue(cid, imtable[i].storage)
  169.                                         if check < imtable[i].count then
  170.                                                 n = n + 1
  171.                                         end
  172.                                 end
  173.                                 local text = ""
  174.                                 local c = 0
  175.                                 for v = 1, #imtable do
  176.                                         local check = x.items and getPlayerItemCount(cid, imtable[v].id) or getPlayerStorageValue(cid, imtable[v].storage)
  177.                                         if check < imtable[v].count then
  178.                                                 c = c + 1
  179.                                                 local ret = ", "
  180.                                                 if c == 1 then
  181.                                                         ret = ""
  182.                                                 elseif c == n then
  183.                                                         ret = " and "
  184.                                                 end
  185.                                                 text = text .. ret
  186.                                                 if x.items then
  187.                                                         local count, info = imtable[v].count - getPlayerItemCount(cid, imtable[v].id), getItemInfo(imtable[v].id)
  188.                                                         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
  189.                                                 else
  190.                                                         local count = imtable[v].count - (getPlayerStorageValue(cid, imtable[v].storage) + 1)
  191.                                                         text = text .. count.." "..imtable[v].name
  192.                                                 end
  193.                                         end
  194.                                 end
  195.                                 selfSay(x.items and "You don't have all items, you still need to get "..text.."." or "You didn't kill all monsters, you still need to kill "..text..".", cid)
  196.                         end
  197.                 end
  198.                 talkState[talkUser] = 0
  199.         elseif msgcontains(msg, 'no') and talkState[talkUser] == 1 then
  200.                 selfSay("Oh well, I guess not then.", cid)
  201.         end
  202.         return true
  203. end
  204.  
  205. npcHandler:setMessage(MESSAGE_FAREWELL, "Bye!")
  206. npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye, have a nice day!")
  207. npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
  208. npcHandler:addModule(FocusModule:new())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement