adrianoswatt

Swatt TaskSystem Library

Apr 1st, 2017
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.38 KB | None | 0 0
  1. -- ########################################################
  2. -- #####          Name: Adriano Swatt'                #####
  3. -- #####              Version: 3.0                    #####
  4. -- ########################################################
  5. -- #####        Developed by Adriano Swatt'           #####
  6. -- #####     Contact: [email protected]        #####
  7. -- #####     PERSONALIZED TASK SYSTEM BY SWATT'       #####
  8. -- ########################################################
  9.  
  10. -- [[ EXPLAIN // EXPLICAÇÃO // COMO CONFIGURAR ]] --
  11. -- storage = Storage Que Salva: Task Ativa/Repetição/Dia/Hora/Minute
  12. -- countSto = Storage Que Salva Quantidade que Matou
  13. -- count = Quantidade Total Que Precisará Matar
  14. -- price = Preço da Task em Gold Coins
  15. -- repeated = Quantas Vezes Pode Realizar a Task
  16. -- inDay = Day Value: Quantos dias para realizar // false: se a task fica ativa até a conclusão
  17. -- awards = [1] = {id = Premio, multiply = quantidade} // seguindo modelo // usar [1] = {id = "exp", multiply = QUANTIDADE}
  18. -- DICA: Deixe sempre a Experiência por último
  19. _SETTING_TASK_SYSTEM_CONFIG = {
  20.     taskAtSameTime = 3, -- Quantas Tasks Ativas Ao Mesmo Tempo
  21. }
  22.  
  23. _MONSTERS_TASK_SYSTEM_CONFIG = {
  24.     ["minotaur"] = {storage = 20001, countSto = 30001, count = 10, price = 5000, repeated = 5, inDay = false,
  25.         mlist = {"minotaur", "minotaur archer", "minotaur guard"},
  26.         awards = {
  27.             [1] = {id = 2430, multiply = 1},
  28.             [2] = {id = 2160, multiply = 2},
  29.             [3] = {id = "exp", multiply = 5000}
  30.         }
  31.     },
  32.     -- [[ SPACE ]] --
  33.     ["cyclops"] = {storage = 20002, countSto = 30002, count = 15, price = 7000, repeated = 3, inDay = false,
  34.         mlist = {"cyclops", "cyclops drone", "cyclops smith"},
  35.         awards = {
  36.             [1] = {id = 2195, multiply = 1},
  37.             [2] = {id = 2160, multiply = 5},
  38.             [3] = {id = "exp", multiply = 15000}
  39.         }
  40.     },
  41.     -- [[ SPACE ]] --
  42.     ["demon"] = {storage = 20003, countSto = 30003, count = 6666, price = 50000, repeated = 3, inDay = 5,
  43.         mlist = {"demon"},
  44.         awards = {
  45.             [1] = {id = 2195, multiply = 1},
  46.             [2] = {id = 2160, multiply = 10},          
  47.             [3] = {id = "exp", multiply = 100000}
  48.         }
  49.     },
  50.     -- [[ SPACE ]] --
  51.     ["orc"] = {storage = 20004, countSto = 30004, count = 20, price = 5000, repeated = 3, inDay = 5,
  52.         mlist = {"orc", "orc berserker", "orc leader", "orc warrior"},
  53.         awards = {
  54.             [1] = {id = 2195, multiply = 1},
  55.             [2] = {id = 6561, multiply = 1},
  56.             [3] = {id = 2160, multiply = 10},          
  57.             [4] = {id = "exp", multiply = 100000}
  58.         }
  59.     },
  60. }
  61.  
  62. -- [[ Storage: ativo (1) / repetição / Prazo  ]] --
  63. function checkPlayerIsInTask(cid) -- RETURN: True if he can do some task // MonsterName if he can't
  64.     getSto = doOrganizeTaskSto(_MONSTERS_TASK_SYSTEM_CONFIG)
  65.     if isPlayer(cid) then
  66.         pTaskTab = {}
  67.         for a = getSto[1], getSto[#getSto] do
  68.             if getPlayerStorageValue(cid, a) ~= -1 then
  69.                 onCheck = doCutTaskStorage(cid, a, "/")
  70.                 if #onCheck > 0 then
  71.                     active = tonumber(onCheck[1]:sub(2, 2))
  72.                     if active >= 1 then
  73.                         mName = whatTaskIsActive(cid, a)
  74.                         table.insert(pTaskTab, mName)
  75.                     end
  76.                 end        
  77.             end    
  78.         end
  79.         return pTaskTab
  80.     end
  81. return true
  82. end
  83.  
  84. function checkPlayerRepetationTask(cid) -- RETURN: List of Repetation Tasks
  85.     getSto = doOrganizeTaskSto(_MONSTERS_TASK_SYSTEM_CONFIG)
  86.     if isPlayer(cid) then
  87.         pTaskTab = {}
  88.         for a = getSto[1], getSto[#getSto] do
  89.             if getPlayerStorageValue(cid, a) ~= -1 then
  90.                 onCheck = doCutTaskStorage(cid, a, "/")
  91.                 if #onCheck > 0 then
  92.                     active = tonumber(onCheck[2])
  93.                     if active >= 1 then
  94.                         mName = whatTaskIsActive(cid, a)
  95.                         table.insert(pTaskTab, mName)
  96.                     end
  97.                 end        
  98.             end    
  99.         end
  100.         return pTaskTab
  101.     end
  102. return true
  103. end
  104.  
  105. function checkAlreadyDoingThisTask(cid, name, list) -- Return Monster Name if Can Do, or false if can't
  106.     cfg = _MONSTERS_TASK_SYSTEM_CONFIG
  107.     for i = 1, #list do
  108.         getArray = cfg[list[i]].mlist
  109.         if getArray then
  110.             if isInArray(getArray, name) then
  111.                 return list[i]
  112.             end
  113.         end
  114.     end
  115. return false
  116. end
  117.  
  118. function getInfoPlayerTask(cid, mName) -- Returns: [1] Repetition, [2] full date from Especific Task.
  119. local infoTab = {}
  120.     getList = _MONSTERS_TASK_SYSTEM_CONFIG
  121.     if isPlayer(cid) then
  122.         getInfo = getList[mName:lower()]
  123.         if getInfo then
  124.             if getPlayerStorageValue(cid, getInfo.storage) ~= -1 then
  125.                 local onCut = doCutTaskStorage(cid, getInfo.storage, "/")
  126.                 if #onCut > 0 then
  127.                     for a = 2, 3 do
  128.                         table.insert(infoTab, tonumber(onCut[a]))
  129.                     end
  130.                     return infoTab
  131.                 else
  132.                     return true
  133.                 end
  134.             else
  135.                 return false
  136.             end
  137.         end
  138.     end
  139. end
  140.  
  141. function doCutTaskStorage(cid, storageKey, cutType) -- cutType [Ex: ","]
  142. local cutSto = {}
  143.     local string = tostring(getPlayerStorageValue(cid, storageKey))
  144.     local cutSto = string:explode(cutType)
  145.     if #cutSto > 0 then
  146.         for i = 1, #cutSto do
  147.             table.insert(cutSto, cutSto[i])
  148.         end
  149.         return cutSto
  150.     else
  151.         return true
  152.     end
  153. end
  154.  
  155. function whatTaskIsActive(cid, stoKey) -- Retorna Nome das Task Ativa
  156.     taskList = _MONSTERS_TASK_SYSTEM_CONFIG
  157.     for index, result in pairs(taskList) do
  158.         if result.storage == stoKey then
  159.             return index
  160.         end
  161.     end
  162. end
  163.  
  164. function getAwardsList(cid, list) -- Retorna Lista de Premiação
  165.     local awardList = ''
  166.     get = list
  167.     for a = 1, #list do
  168.         if isNumber(list[a].id) then
  169.             if list[a].multiply <= 1 then
  170.                 awardList = awardList.."{"..list[a].multiply.."x "..getItemNameById(list[a].id).."}, "
  171.             else
  172.                 awardList = awardList.."{"..list[a].multiply.."x "..getItemPluralNameById(list[a].id).."}, "
  173.             end
  174.         else
  175.             cawardList = awardList:sub(1, (#awardList-2))
  176.             awardList = cawardList.." and {"..list[a].multiply.." experience points}"
  177.         end
  178.     end
  179. return awardList
  180. end
  181.  
  182. function doGiveTaskAwards(cid, list) -- Entrega Lista de Prêmios
  183.     if isPlayer(cid) then
  184.         for a = 1, #list do
  185.             if isNumber(list[a].id) then
  186.                 doPlayerAddItem(cid, list[a].id, list[a].multiply)
  187.             else
  188.                 doPlayerAddExp(cid, list[a].multiply)
  189.             end
  190.         end
  191.     end
  192. return true
  193. end
  194.  
  195. function doGiveTaskMonsterList(cid, list) -- Retorna Lista de Task Ativas [Tabela Monster Names]
  196.     if isPlayer(cid) then
  197.         name = ""
  198.         for a = 1, #list do
  199.             if a == 1 then
  200.                 name = "{"..list[a].."}"
  201.             elseif a > 1 and a < #list then
  202.                 name = ""..name..", {"..list[a].."}"
  203.             else
  204.                 name = ""..name.." and {"..list[a].."}"
  205.             end
  206.         end
  207.     end
  208. return name
  209. end
  210.  
  211. function doCloseTimedTask(cid, monster)
  212.     getInfo = getInfoPlayerTask(cid, monster)
  213.     taskList = _MONSTERS_TASK_SYSTEM_CONFIG
  214.     getM = taskList[monster]
  215.     if getM then
  216.         if getInfo then
  217.             repet = getInfo[1]
  218.             data = getInfo[2]
  219.             newValue = "&0/"..repet.."/"..data..""
  220.             setPlayerStorageValue(cid, getM.storage, newValue)
  221.             setPlayerStorageValue(cid, getM.countSto, 0)
  222.         end
  223.     end
  224. end
  225.  
  226. function doPlayerDonePersoTask(cid)
  227.     taskList = checkPlayerIsInTask(cid)
  228.     if #taskList > 0 then
  229.         mList = _MONSTERS_TASK_SYSTEM_CONFIG
  230.         for i = 1, #taskList do
  231.             task = mList[taskList[i]]
  232.             if task then
  233.                 killeds = getPlayerStorageValue(cid, task.countSto)
  234.                 if killeds == task.count then
  235.                     return taskList[i]
  236.                 end
  237.             end
  238.         end
  239.     else
  240.         return false
  241.     end
  242. end
  243.  
  244. function doOrganizeTaskSto(taskList) -- Retorna Primeira e Última Storage de Todas Tasks
  245. local tabSto = {}
  246.     taskList = _MONSTERS_TASK_SYSTEM_CONFIG
  247.     for index, result in pairs(taskList) do
  248.         if result.storage then
  249.             table.insert(tabSto, result.storage)
  250.         end
  251.     end
  252.     table.sort(tabSto, function(a, b) return a < b end)
  253. return tabSto
  254. end
Advertisement
Add Comment
Please, Sign In to add comment