Ir para conteúdo

Featured Replies

Postado

.Qual servidor ou website você utiliza como base? otx

 

Qual o motivo deste tópico? estou tentando implementar um sistema de task por client module no otc. Adicionei os modules no client, mas está ocorrendo um erro ao ler a lib da task, alguém poderia verificar pra mim e ver se tem algum erro?

 

 

 

Você tem o código disponível? Se tiver publique-o aqui: 

 TABLE_RANKS_OTC = {
   [-1] = {"D"},
   [0] = {"D","C"},
   [1] = {"D","C","B"},
   [2] = {"D","C","B","A"},
   [3] = {"D","C","B","A","S"}
} 

TABLE_RANK_LEVEL = {
   ["D"] = {{1,49}, -1, points = 1},
   ["C"] = {{50,79}, 0, points = 25},
   ["B"] = {{80,129}, 1, points = 999},
   ["A"] = {{130,199}, 2, points = 999},
   ["S"] = {{200,math.huge}, 3, points = 999}
}      

TABLE_RANKS = {"D","C","B","A","S"}
TABLE_DELAY_SAMPLER = 59*10 -- 10 minutos

TABLE_TASKS = { 
  ["rat"]                 = {id = 0,  level = 01, count = 040, exp = 550,   point = 1, delay = (59*1), lookType = {327}, msg = "You can kill the boss Big Rat in the sewer of Goa Kingdom." },
  ["beggar"]              = {id = 1,  level = 01, count = 040, exp = 600,   point = 1, delay = (59*3), lookType = {256,153,273}},
  ["joker bee/god wind"]  = {id = 2,  level = 05, count = 070, exp = 900,   point = 3, delay = (59*3), lookType = {51,53}, msg = "You can kill the Amethite in one of the mountains of Goa Kingdom." },
  ["spider"]              = {id = 3,  level = 05, count = 080, exp = 1000,  point = 3, delay = (59*5), lookType = {276}},
  ["slug"]                = {id = 4,  level = 05, count = 080, exp = 1150,  point = 3, delay = (59*5), lookType = {34}},
  ["hedgehog"]            = {id = 5,  level = 05, count = 060, exp = 900,   point = 2, delay = (59*5), lookType = {283}}, 
  ["rotworm"]             = {id = 6,  level = 10, count = 080, exp = 1350,  point = 3, lookType = {287, 288}},
  ["rocky boar"]          = {id = 7,  level = 10, count = 100, exp = 1850,  point = 4, lookType = {302}, msg = "You can kill the Enraged Rocky Boar in one of the mountains of Goa Kingdom." },
  ["arboreal spectrum"]   = {id = 8,  level = 20, count = 150, exp = 4500,  point = 10, lookType = {322}}, 
  ["salamander"]          = {id = 9,  level = 20, count = 150, exp = 3000,  point = 9, lookType = {283}}, 
  ["slime"]               = {id = 10, level = 25, count = 070, exp = 3000,  point = 6, lookType = {357}, msg = "You can kill the Goome in the slime cave of Shell Town."},
  ["imp"]                 = {id = 11, level = 25, count = 070, exp = 3500,  point = 6, lookType = {317}, msg = "You can kill the Dharkos in the imp cave of Shell Town."},
  ["ladybug"]             = {id = 12, level = 15, count = 200, exp = 3100,  point = 8, lookType = {433}, msg = "You can kill the Cydaea in the ladybug mountain of Shell Town."},
  ["boar"]                = {id = 13, level = 25, count = 300, exp = 10000, point = 17, lookType = {291}, msg = "You can kill the Hunger in the florest of Orange Town."},
  ["crocodile"]           = {id = 14, level = 25, count = 300, exp = 10000, point = 17, lookType = {309}},
  ["crypt shambler"]      = {id = 15, level = 25, count = 200, exp = 12000, point = 19, lookType = {414}}, 
  ["dwarves"]             = {id = 16, level = 20, count = 350, exp = 8500,  point = 14, lookType = {447, 448, 449}, msg = "You can kill the Grief in the mine of Orange Town."},
  ["giant lobster"]       = {id = 17, level = 30, count = 200, exp = 14500, point = 22, delay = (59*15), lookType = {102}, msg = "You can kill the Yaomo in a cave of Syrup Village."},
  ["spikeshell tortoise"] = {id = 18, level = 30, count = 200, exp = 17000, point = 24, delay = (59*15), lookType = {415}}, 
  ["coryms"]              = {id = 19, level = 25, count = 500, exp = 15000, point = 30, lookType = {451, 452, 453}},
  ["tremor"]              = {id = 20, level = 45, count = 150, exp = 18000, point = 35, delay = (59*20), lookType = {436}, msg = "You can kill the Laken in the rock mountain of Syrup Village."},
  ["wyvern"]              = {id = 21, level = 30, count = 150, exp = 15500, point = 26, delay = (59*20), lookType = {361}, msg = "You can kill the Toxic Fiend in the rock mountain of Cocoyashi Village."},
  ["dragon"]              = {id = 22, level = 50, count = 300, exp = 23500, point = 1, delay = (59*30), lookType = {313,459}},
  ["gosme"]               = {id = 23, level = 10, count = 300, exp = 5600,  point = 9, lookType = {83}}, 
  ["cobra"]               = {id = 24, level = 15, count = 150, exp = 3150,  point = 9, lookType = {81}},
  ["tortoise"]            = {id = 25, level = 20, count = 200, exp = 3500,  point = 10, lookType = {461}, msg = "You can kill the boss Dahu below the mountain of Syrup Village." },
  ["poisonous toad"]      = {id = 26, level = 20, count = 200, exp = 4500,  point = 13, lookType = {297}},
  ["orcs"]                = {id = 27, level = 20, count = 250, exp = 4500,  point = 14, lookType = {380, 381, 379, 382, 386}},
  ["buffalo"]             = {id = 28, level = 25, count = 300, exp = 10000, point = 17, lookType = {80}},
  ["grotesque"]           = {id = 29, level = 25, count = 200, exp = 14500, point = 22, lookType = {419}, msg = "You can kill the boss Greek in the undeads of Orange Town." },
  ["scarlet widow"]       = {id = 30, level = 30, count = 150, exp = 14500, point = 28, delay = (59*20), lookType = {315}},
  ["fierce crab"]         = {id = 31, level = 40, count = 200, exp = 21000, point = 35, delay = (59*20), lookType = {416}, msg = "You can kill the boss Karkinos in the Fierce Crab cave of Syrup Village." },
  ["venom spider"]        = {id = 32, level = 45, count = 250, exp = 18000, point = 33, delay = (59*20), lookType = {465}},
  ["necromancer"]         = {id = 33, level = 50, count = 500, exp = 25000, point = 50, delay = (59*30), lookType = {418}, msg = "You can kill the boss Mergos in the undeads of Orange Town." },
  ["giant spider"]        = {id = 34, level = 50, count = 200, exp = 23000, point = 1, delay = (59*30), lookType = {316}, msg = "You can kill the boss Freja the Queen in the Giant Spider cave of Loguetown." },
  ["bonebeast"]           = {id = 35, level = 50, count = 100, exp = 15000, point = 1, delay = (59*30), lookType = {90},  msg = "You can kill the boss Tibicena in the undeads cave of Orange Town." },
  ["trolls"]              = {id = 36, level = 50, count = 500, exp = 24000, point = 1, delay = (59*30), lookType = {352, 353, 354, 355}, msg = "You can kill the boss Kappa in the trolls cave of Loguetown." },
  ["swamp thing"]         = {id = 37, level = 50, count = 225, exp = 22000, point = 1, delay = (59*30), lookType = {483}},
  ["swamp monster"]       = {id = 38, level = 55, count = 225, exp = 23500, point = 1, delay = (59*30), lookType = {484}, msg = "You can kill the boss Amygdala in the swamp mountain of Loguetown." },
  ["fishmans"]            = {id = 39, level = 55, count = 500, exp = 26000, point = 1, delay = (59*30), lookType = {408, 405, 404, 406, 407}, msg = "You can kill the boss Rom the Fishman in the fishman cave of Cocoyashi Village." },
  ["ducksheep"]           = {id = 40, level = 60, count = 150, exp = 17000, point = 1, delay = (59*30), lookType = {400}, msg = "You can kill the boss Orthrus in the Island of Rare Animals." },
  ["zebird"]              = {id = 41, level = 60, count = 150, exp = 20500, point = 1, delay = (59*30), lookType = {395}},
  ["rhinoroo"]            = {id = 42, level = 60, count = 300, exp = 26000, point = 1, delay = (59*30), lookType = {402}, msg = "You can kill the boss Panes in the Rhinoroo cave of the Island of Rare Animals." },  
}

TABLE_TASKS_MONSTERS = { -- NOME DOS BIXOS MINUSCULO !!!!!!!!!!!!!
  ["shabby beggar"]      = "beggar",
  ["crazed beggar"]      = "beggar",
  ["god wind"]           = "joker bee/god wind",
  ["joker bee"]          = "joker bee/god wind",
  ["big rotworm"]        = "rotworm",
  ["dwarf miner"]        = "dwarves",
  ["dwarf warrior"]      = "dwarves",
  ["dwarf brave"]        = "dwarves",
  ["corym charlatan"]    = "coryms",
  ["corym skirmisher"]   = "coryms",
  ["corym vanguard"]     = "coryms",
  ["dragon"]             = "dragon",
  ["dirt dragon"]        = "dragon",
  ["orc"]                = "orcs", 
  ["orc warrior"]        = "orcs",
  ["orc creeper"]        = "orcs",
  ["orc shaman"]         = "orcs",
  ["orc rider"]          = "orcs",
  ["troll"]              = "trolls",
  ["troll warrior"]      = "trolls",
  ["troll berserker"]    = "trolls",
  ["troll commander"]    = "trolls",
  ["fishman punk"]       = "fishmans",
  ["fishman bandit"]     = "fishmans",
  ["fishman thug"]       = "fishmans",
  ["sabresword fishman"] = "fishmans",
  ["fishman lancer"]     = "fishmans",
}

TABLE_TASK_UNDEAD_SOPHIA = { -- ['nome do bixo minusculo'] = pontos_que_da_na_task_da_sophia, 
  ['vielmond skeleton']      = 1,
  ['vielmond ghost']         = 1,
  ['vielmond shambler']      = 1,
  ['vielmond raise']         = 1,
  ['vielmond grotesque']     = 1,
}

TABLE_TASK_BUSINESS_AROUND_THE_WORLD = {
  ['troll']           = {count = 30, storage_multiplier = 1000000},
  ['troll warrior']   = {count = 20, storage_multiplier = 10000},
  ['troll berserker'] = {count = 10, storage_multiplier = 100},
  ['troll commander'] = {count =  2, storage_multiplier = 1},
}
TOTAL_VALUE_FROM_TASK_BUSINESS_AROUND_THE_WORLD = table.foldr(TABLE_TASK_BUSINESS_AROUND_THE_WORLD, 0, function (acc, task) return acc + task.count * task.storage_multiplier end)

TABLE_TASK_SAVING_BUGGY_BIRDS = {
  ['baby bird']  = {count = 250, storage_multiplier = 1},
  ['big bird']   = {count =  80, storage_multiplier = 1000},
}
TOTAL_VALUE_FROM_TASK_SAVING_BUGGY_BIRDS = table.foldr(TABLE_TASK_SAVING_BUGGY_BIRDS, 0, function (acc, task) return acc + task.count * task.storage_multiplier end)
-------------------------------------------------------------------------------- 
task = {
  avaiable = function(cid, taskname)
    return true      
  end, 

  getStorage = function(index, offset)  
    return STORAGE_TASK.START + (index * STORAGE_TASK.CONST.OFFSET_COUNT) + offset
  end,

  finished = function(cid, taskname) -- se matou all e ja reportou no npc   
    return getPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.FINISHED)) == 1
  end,      

  kills = function(cid, taskname) -- quantidade de vezes que ja matou determinado bixo
    return getPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.KILLS))
  end,
  
  killedNeededCount = function(cid, taskname)
    return task.kills(cid, taskname) >= TABLE_TASKS[taskname].count
  end,
  
  slot = function(cid, number) -- tem no maximo "STORAGE_TASK.CONST.MAX_TASKS_TOGETHER" de slots
    if number > STORAGE_TASK.CONST.MAX_TASKS_TOGETHER then
      print("[ERROR] lib_Tasks.lua excedeu o limite de slots!!!!!!!!!!!!!!!!!!!!!!")
    end         
    return getPlayerStorageValue(cid, STORAGE_TASK.ACTIVE_NAMES + number) 
  end,                        
  
  doing = function(cid, taskname) -- ve se essa task ja nao esta sendo feita por mim
    for i = 1, STORAGE_TASK.CONST.MAX_TASKS_TOGETHER do
      if task.slot(cid, i) == taskname then
        return true
      end
    end
    return false -- nao esta fazendo esta task  
  end, 
  
  doEraseSlot = function(cid, taskname)
    for i = 1, STORAGE_TASK.CONST.MAX_TASKS_TOGETHER do
      if task.slot(cid, i) == taskname then
        setPlayerStorageValue(cid, STORAGE_TASK.ACTIVE_NAMES + i, "")
        break
      end
    end
  end,
  
  doSaveSlot = function(cid, taskname)
    if task.doing(cid, taskname) then -- ja esta fazendo essa task em algum slot 
      return false
    end
    for i = 1, STORAGE_TASK.CONST.MAX_TASKS_TOGETHER do
      if not TABLE_TASKS[ task.slot(cid, i) ]  then -- linha vazia   
        setPlayerStorageValue(cid, STORAGE_TASK.ACTIVE_NAMES + i, taskname)
        return true  
      end   
    end
    
    return false -- nao encontrou nenhum slot disponivel 
  end,
  
  doSetKills = function(cid, taskname, count) -- define a quantidade de monstros matados em determinado slot 
    setPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.KILLS), count)  
    task.doParseTask(cid, taskname)
  end,  
  
  doSetBossKill = function(cid, taskname, count)
    setPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.KILLED_BOSS), count)
  end,
  
  doSetFinished = function(cid, taskname, count) -- define se ja terminou (-1 = nunca tentou, 0 = não terminou, 1 = terminou)
    setPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.FINISHED), count)
  end,
  
  doParseTask = function(cid, taskname)
     local __buffer = {}                 
     local rank = ((getPlayerStorageValue(cid,STORAGE_TASK.VIEW) == -1) and "D" or getPlayerStorageValue(cid,STORAGE_TASK.VIEW))
     local avaiableTasks = getAvaiableTasks(cid)
     for creature, taskInfo in pairs(avaiableTasks) do
        if taskInfo.lookType then
           if TABLE_RANK_LEVEL[rank] then
              if getPlayerStorageValue(cid, STORAGE_TASK.RANK) >= TABLE_RANK_LEVEL[rank][2] then
                 if getPlayerLevel(cid) >= TABLE_RANK_LEVEL[rank][1][1] and taskInfo.level >= TABLE_RANK_LEVEL[rank][1][1] and taskInfo.level <= TABLE_RANK_LEVEL[rank][1][2] then      
                    if creature == taskname then
                       __buffer[1] = {}    
                       __buffer[1].id = creature                               
                       __buffer[1].level = taskInfo.level                                               
                       __buffer[1].lookType = taskInfo.lookType
                       __buffer[1].reward = taskInfo.exp.." Experience and "..taskInfo.point.." Point(s)."                        
                       __buffer[1].doing = task.doing(cid, creature)
                       if taskInfo.msg then
                          __buffer[1].msg = taskInfo.msg     
                       end
                       __buffer[1].count = taskInfo.count 
                       __buffer[1].kills = (task.kills(cid, creature) == -1) and 0 or task.kills(cid, creature)
                       break
                    end
                 end
              end
           end
        end
     end
     doSendPlayerExtendedOpcode(cid, GameServerOpcodes.TaskModule, table.tostring(__buffer))
  end,
  
  doParseTasks = function(cid)   
     function compare(a,b)
        return a.level < b.level
     end
     local __buffer = {}  
     local __resetBuffer = {}              
     local rank = ((getPlayerStorageValue(cid,STORAGE_TASK.VIEW) == -1) and "D" or getPlayerStorageValue(cid,STORAGE_TASK.VIEW))
     local avaiableTasks = getAvaiableTasks(cid)
     for creature, taskInfo in pairs(avaiableTasks) do
        if taskInfo.lookType then
           if TABLE_RANK_LEVEL[rank] then
              if getPlayerStorageValue(cid, STORAGE_TASK.RANK) >= TABLE_RANK_LEVEL[rank][2] then
                 if getPlayerLevel(cid) >= TABLE_RANK_LEVEL[rank][1][1] and taskInfo.level >= TABLE_RANK_LEVEL[rank][1][1] and taskInfo.level <= TABLE_RANK_LEVEL[rank][1][2] then  
                    local bufferid = #__buffer + 1
                    __buffer[bufferid] = {}    
                    __buffer[bufferid].id = creature                               
                    __buffer[bufferid].level = taskInfo.level                                               
                    __buffer[bufferid].lookType = taskInfo.lookType
                    __buffer[bufferid].reward = taskInfo.exp.." Experience and "..taskInfo.point.." Point(s)."                        
                    __buffer[bufferid].doing = task.doing(cid, creature)
                    if taskInfo.msg then
                       __buffer[bufferid].msg = taskInfo.msg     
                    end
                    __buffer[bufferid].count = taskInfo.count 
                    __buffer[bufferid].kills = (task.kills(cid, creature) == -1) and 0 or task.kills(cid, creature)
                    table.sort(__buffer, compare)
                 end
              end
           end
        end                                                  
     end                             
     doSendPlayerExtendedOpcode(cid, GameServerOpcodes.TaskModule, "[resetList]")
     doSendPlayerExtendedOpcode(cid, GameServerOpcodes.TaskModule, table.tostring(__buffer))
  end,
  
  doParsePlayer = function(cid)
     local ranks = TABLE_RANKS_OTC[getPlayerStorageValue(cid, STORAGE_TASK.RANK)]
     local __buffer = {}
     __buffer["[pointsHave]"] = getPlayerStorageValue(cid, STORAGE_TASK.POINTS)       
     if ranks then
        __buffer["[unlockedRanks]"] = ranks
     end                    
     doSendPlayerExtendedOpcode(cid, GameServerOpcodes.TaskModule, table.tostring(__buffer))
  end,
  
  doCancel = function(cid, taskname) -- cancelar slot de task (ou por cancelar ou quando termina mesmo) 
     if task.doing(cid, taskname) then    
        task.doEraseSlot(cid, taskname)
        task.doSetBossKill(cid, taskname, 0)         
        task.doSetFinished(cid, taskname, 0)  
        task.doSetKills(cid, taskname, 0)  
        return true
     end
     return false     
  end,
  
  doStart = function(cid, taskname) -- se o storage == 0, entao ele ja comecou essa task alguma vez na vida 
    task.doSetFinished(cid, taskname, 0) 
    setPlayerStorageValue(cid, STORAGE_TASK.APPEAR_QUESTLOG, 0) -- aparecer na quest log    
    task.doSetKills(cid, taskname, 0)
  end,
  
  doComplete = function(cid, taskname)  
    if not TABLE_TASKS[taskname].delay then
       TABLE_TASKS[taskname].delay = TABLE_DELAY_SAMPLER
    end 
    doPlayerAddExp(cid, TABLE_TASKS[taskname].exp)
    setPlayerStorageValue(cid, task.getStorage(TABLE_TASKS[taskname].id, STORAGE_TASK.CONST.OFFSET.DELAY), os.time() + TABLE_TASKS[taskname].delay)
    setPlayerStorageValue(cid, STORAGE_TASK.POINTS, TABLE_TASKS[taskname].point + getPlayerStorageValue(cid, STORAGE_TASK.POINTS))
    if TABLE_TASKS[taskname].msg ~= nil then
       doPlayerSendTextMessage(cid, 20, TABLE_TASKS[taskname].msg)
    end           
    task.doCancel(cid, taskname)     
    task.doSetFinished(cid, taskname, 1)
    task.doParsePlayer(cid)   
  end,
  
  getTaskTableByTarget = function(cid, targetname)
    --for index, v in pairs(TABLE_TASKS) do
    --  if isInArray(v.creatures, targetname) then
    --    return v
    --  end
    --end    
    --return nil -- daqui pra cima era o metodo antigo 
    if TABLE_TASKS[targetname] then
      return targetname, TABLE_TASKS[targetname] 
    elseif TABLE_TASKS_MONSTERS[targetname] then -- da mesma especie mas tem nome diferente Ex: dragon lord
      return TABLE_TASKS_MONSTERS[targetname], TABLE_TASKS[ TABLE_TASKS_MONSTERS[targetname] ]
    end
    return nil
  end,
  
}
--------------------------------------------------------------------------------

--[[ old 
function getAvaiableTasks(cid)
  local retorno = ""
  for index, v in pairs(TABLE_TASKS) do
    if task.avaiable(cid, index) then -- index de string 
      retorno = retorno .. "{" .. index .. "}, "
    end
  end
  return string.sub(retorno, 1, string.len(retorno)-2) -- pra retirar o ultimo caracter (virgula) da string
end       ]]


function getAvaiableTasks(cid)
  local retorno = {}
  for index, v in pairs(TABLE_TASKS) do
    if task.avaiable(cid, index) then -- index de string    
      retorno[index] = v
    end
  end
  return retorno
end 
              
function getDoingTasks(cid)
  local retorno = ""
  for indexName, v in pairs(TABLE_TASKS) do
    if task.doing(cid, indexName) then -- index de string 
      retorno = retorno .. "{" .. indexName .. "}, "
    end
  end
  return string.sub(retorno, 1, string.len(retorno)-2) -- pra retirar o ultimo caracter (virgula) da string
end
--------------------------------------------------------------------------------
local function doGenerateTaskQuestLog()  
  local questxml = '  <quest name="Tasks" startstorageid="' .. STORAGE_TASK.APPEAR_QUESTLOG .. '" startstoragevalue="0" endstoragevalue="1"> \n' 
  for name, task_line in pairs(TABLE_TASKS) do -- gerar cada quest log
    local storage = task.getStorage(task_line.id, STORAGE_TASK.CONST.OFFSET.FINISHED)
    questxml = questxml ..
               '      <mission name="' .. name .. '" storageid="' .. storage .. '" startvalue="0" endvalue="1"> \n' .. 
               '        <missionstate id="0" description="Kill ' .. task_line.count .. ' ' ..  name .. 's and report to take you prize."/> \n' .. 
               '      </mission> \n ' 
  end  
  questxml = questxml .. '  </quest>\n'
  local file = io.open("data\\XML\\quests.xml", "w")
  file:write(questxml)
  file:close()
end

--doGenerateTaskQuestLog()

 

 

Screenshot_17.png

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Conteúdo Similar

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.6k

Informação Importante

Confirmação de Termo