• TibiaFace

    Tibiaface | Una comunidad Open Tibia donde encontras : mapas, scripts, Otserver, npc y amigos etc ...

    .
    demo menumenu

    Afiliados



    Votar:

    [Actions] script

    Compartir:

    Ver el tema anterior Ver el tema siguiente Ir abajo  Mensaje (Página 1 de 1.)

    1default [Actions] script el Lun Dic 16, 2019 5:12 pm

    ivansho92

    ivansho92
    Miembro
    Miembro
    Descripcion escribió:Hola quería saber si sería posible un daily task system para tefs 1.3 en el cual consista hacer muchas misiones claro, una por día y al final de digamos unas 50 task pueda darles un outfit, es posible?
    Imagen Explicativa escribió:Imagen Explicativa: [Actions] script Tibiaf10
    Version del Scripts: TFs 1.x

    2default Re: [Actions] script el Lun Dic 16, 2019 10:54 pm

    [Admin] God Maya

    [Admin] God Maya
    Administrador
    Administrador
    agregar esto a global.lua

    Código:
    dofile('data/lib/task system.lua')

    en lib creas un archivo llamado task system.lua

    Código:

    task_monsters = {
      [1] = {name = "monster1", mons_list = {"monster_t2", "monster_t3"},  storage = 30000, amount = 20, exp = 5000, pointsTask = {1, 1}, items = {{id = 2157, count = 1}, {id = 2160, count = 3}}},
      [2] = {name = "monster2", mons_list = {"", ""}, storage = 30001, amount = 10, exp = 10000, pointsTask = {1, 1}, items = {{id = 10521, count = 1}, {id = 2160, count = 5}}},
      [3] = {name = "monster3", mons_list = {"", ""}, storage = 30002, amount = 10, exp = 18000, pointsTask = {1, 1}, items = {{id = 2195, count = 1}, {id = 2160, count = 8}}},
      [4] = {name = "monster4", mons_list = {"", ""}, storage = 30003, amount = 10, exp = 20000, pointsTask = {1, 1}, items = {{id = 2520, count = 1}, {id = 2160, count = 10}}}
    }

    task_daily = {
      [1] = {name = "monsterDay1", mons_list = {"monsterDay1_t2", "monsterDay1_t3"}, storage = 40000, amount = 10, exp = 5000, pointsTask = {1, 1}, items = {{id = 2157, count = 1}, {id = 2160, count = 3}}},
      [2] = {name = "monsterDay2", mons_list = {"", ""}, storage = 40001, amount = 10, exp = 10000, pointsTask = {1, 1}, items = {{id = 10521, count = 1}, {id = 2160, count = 5}}},
      [3] = {name = "monsterDay3", mons_list = {"", ""}, storage = 40002, amount = 10, exp = 18000, pointsTask = {1, 1}, items = {{id = 2195, count = 1}, {id = 2160, count = 8}}},
      [4] = {name = "monsterDay4", mons_list = {"", ""}, storage = 40003, amount = 10, exp = 20000, pointsTask = {1, 1}, items = {{id = 2520, count = 1}, {id = 2160, count = 10}}}
    }

    task_storage = 20020 -- storage que verifica se está fazendo alguma task e ver qual task é - task normal
    task_points = 20021 -- storage que retorna a quantidade de pontos task que o player tem.
    task_sto_time = 20022 -- storage de delay para não poder fazer a task novamente caso ela for abandonada.
    task_time = 20 -- tempo em horas em que o player ficará sem fazer a task como punição
    task_rank = 20023 -- storage do rank task
    taskd_storage = 20024 -- storage que verifica se está fazendo alguma task e ver qual task é - task daily
    time_daySto = 20025 -- storage do tempo da task daily, no caso para verificar e add 24 horas para fazer novamente a task daily


    local ranks_task = {
    [{1, 20}] = "Newbie",
    [{21, 50}] = "Elite",
    [{51, 100}] = "Master",
    [{101, 200}] = "Destroyer",      
    [{201, math.huge}] = "Juggernaut"
    }

    local RankSequence = {
    ["Newbie"] = 1,
    ["Elite"] = 2,
    ["Master"] = 3,
    ["Destroyer"] = 4,
    ["Juggernaut"] = 5,
    }

    function rankIsEqualOrHigher(myRank, RankCheck)
       local ret_1 = RankSequence[myRank]
       local ret_2 = RankSequence[RankCheck]
       return ret_1 >= ret_2
    end

    function getTaskInfos(player)
       local player = Player(player)
       return task_monsters[player:getStorageValue(task_storage)] or false
    end

    function getTaskDailyInfo(player)
       local player = Player(player)
       return task_daily[player:getStorageValue(taskd_storage)] or false
    end


    function taskPoints_get(player)
       local player = Player(player)
       if player:getStorageValue(task_points) == -1 then
          return 0
       end
       return player:getStorageValue(task_points)
    end

    function taskPoints_add(player, count)
       local player = Player(player)
       return player:setStorageValue(task_points, taskPoints_get(player) + count)
    end

    function taskPoints_remove(player, count)
       local player = Player(player)
       return player:setStorageValue(task_points, taskPoints_get(player) - count)
    end

    function taskRank_get(player)
       local player = Player(player)
       if player:getStorageValue(task_rank) == -1 then
          return 1
       end
       return player:getStorageValue(task_rank)
    end

    function taskRank_add(player, count)
       local player = Player(player)
       return player:setStorageValue(task_rank, taskRank_get(player) + count)
    end

    function getRankTask(player)
       local pontos = taskRank_get(player)
       local ret
       for _, z in pairs(ranks_task) do
          if pontos >= _[1] and pontos <= _[2] then
             ret = z
          end
       end
       return ret
    end

    function getItemsFromTable(itemtable)
        local text = ""
        for v = 1, #itemtable do
            count, info = itemtable[v].count, ItemType(itemtable[v].id)
            local ret = ", "
            if v == 1 then
                ret = ""
            elseif v == #itemtable then
                ret = " - "
            end
            text = text .. ret
            text = text .. (count > 1 and count or info:getArticle()).." "..(count > 1 and info:getPluralName() or info:getName())
        end
        return text
    end

    data/npc cree un arquivo.xml llamado task.xml

    Código:

    <?xml version="1.0" encoding="UTF-8"?>
    <npc name="NPC Task" script="task system.lua" walkinterval="0" floorchange="0">
    <health now="150" max="150"/>
    <look type="430"/>
    <parameters>
    <parameter key="message_greet" value="Hello |PLAYERNAME|. I'm in charge of delivering missions to the players. Would you like to do a {normal} task, {daily} task, {receive} your reward from a task or {abandon} a task ? You can also see the {normal task list} and the {daily task list}."/>
    <parameter key="message_farewell" value="See you later." />
          <parameter key="message_walkaway" value="See you later." />
            </parameters>
    </npc>

    task system.lua

    Código:

    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)
    local keywordHandler = KeywordHandler:new()
    local npcHandler = NpcHandler:new(keywordHandler)
    NpcSystem.parseParameters(npcHandler)

    function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
    function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
    function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
    function onThink() npcHandler:onThink() end
    function onPlayerCloseChannel(cid) npcHandler:onPlayerCloseChannel(cid) end

    npcHandler:addModule(FocusModule:new())

    function creatureSayCallback(cid, type, msg)
       if(not npcHandler:isFocused(cid)) then
          return false
       end
    local player = Player(cid)
    local msg = msg:lower()
    ------------------------------------------------------------------
    if npcHandler.topic[cid] == 0 and msg == 'normal' then
       npcHandler:say("Great. Which monster task would you like to do ?", cid)
       npcHandler.topic[cid] = 1
    elseif npcHandler.topic[cid] == 1 then
       if player:getStorageValue(task_sto_time) < os.time() then
          if player:getStorageValue(task_storage) == -1 then
             for mon, l in ipairs(task_monsters) do
                if msg == l.name then
                   npcHandler:say("Okay, you're now doing the {"..l.name:gsub("^%l", string.upper).."} task,  you need to kill "..l.amount.." of them. Good luck!", cid)
                   player:setStorageValue(task_storage, mon)
                   player:setStorageValue(l.storage, 0)
                   npcHandler.topic[cid] = 0
                   npcHandler:releaseFocus(cid)
                   break
                elseif mon == #task_monsters then
                   npcHandler:say("Sorry but we don't have this task.", cid)
                   npcHandler.topic[cid] = 0
                   npcHandler:releaseFocus(cid)
                end
             end
          else
             npcHandler:say("You're already doing a task. You can only do one at a time. Say {!task} to see information about your current task.", cid)
             npcHandler.topic[cid] = 0
             npcHandler:releaseFocus(cid)
          end
       else
          npcHandler:say("I'm not allowed to give you any task because you have abandoned the previous one. Wait for the "..task_time.." hours of punishment to end.", cid)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       end
    elseif npcHandler.topic[cid] == 0 and msg == 'daily' then
       if player:getStorageValue(time_daySto) < os.time() then
          npcHandler:say("Remember, it is of great importance that the daily tasks are done. Now tell me, which monster task would you like to do? ", cid)
          npcHandler.topic[cid] = 2
       else
          npcHandler:say('You have completed a daily task today, expect to spend as 24 hours to do it again.', cid)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       end
    elseif npcHandler.topic[cid] == 2 then
       if player:getStorageValue(task_sto_time) < os.time() then
          if player:getStorageValue(taskd_storage) == -1 then
             for mon, l in ipairs(task_daily) do
                if msg == l.name then
                   npcHandler:say("Very well, you're now doing the daily {"..l.name:gsub("^%l", string.upper).."} task, you need to kill "..l.amount.." of them. Good luck!", cid)
                   player:setStorageValue(taskd_storage, mon)
                   player:setStorageValue(l.storage, 0)
                   npcHandler.topic[cid] = 0
                   npcHandler:releaseFocus(cid)
                   break
                elseif mon == #task_daily then
                   npcHandler:say("Sorry we don't have this daily task.", cid)
                   npcHandler.topic[cid] = 0
                   npcHandler:releaseFocus(cid)
                end
             end
          else
             npcHandler:say("You're already doing a daily task. You can only do one per day. Say {!task} to see information about your current task.", cid)
             npcHandler.topic[cid] = 0
             npcHandler:releaseFocus(cid)
          end
       else
          npcHandler:say("I'm not allowed to give you any task because you have abandoned the previous one. Wait for the "..task_time.." hours of punishment to end.", cid)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       end
    elseif msg == 'receive' then
       if npcHandler.topic[cid] == 0 then
          npcHandler:say("What kind of task did you finish, {normal} or {daily} ?", cid)
          npcHandler.topic[cid] = 3
       end
    elseif npcHandler.topic[cid] == 3 then
       if msgcontains(msg, 'normal') then
       local ret_t = getTaskInfos(player)
          if ret_t then
             if player:getStorageValue(ret_t.storage) == ret_t.amount then
                local pt1 = ret_t.pointsTask[1]
                local pt2 = ret_t.pointsTask[2]
                local txt = 'Thanks for finishing the task, your awards are: '..(pt1 > 1 and pt1..' task points' or pt1 <= 1 and pt1..' task point')..' and '..(pt2 > 1 and pt2..' rank points' or pt2 <= 1 and pt2..' rank point')..', '
                if #getItemsFromTable(ret_t.items) > 0 then
                   txt = txt..'in addition to winning: '..getItemsFromTable(ret_t.items)..', '
                for g = 1, #ret_t.items do
                   player:addItem(ret_t.items[g].id, ret_t.items[g].count)
                end
                end

                local exp = ret_t.exp
                if exp > 0 then
                   txt = txt..'I will also give you '..exp..' experience, '
                   player:addExperience(exp)
                end
    
                taskPoints_add(player, pt1)
                taskRank_add(player, pt2)
                player:setStorageValue(ret_t.storage, -1)
                player:setStorageValue(task_storage, -1)
                npcHandler:say(txt..'thanks again and see you again!', cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
             else
                npcHandler:say('You have not finished your current task yet. You will receive it when you finish.', cid)
                npcHandler.topic[cid] = 0
                npcHandler:releaseFocus(cid)
             end
          else
             npcHandler:say("You aren't doing any tasks.", cid)
             npcHandler.topic[cid] = 0
             npcHandler:releaseFocus(cid)
          end
       elseif npcHandler.topic[cid] == 3 and msg == 'daily' then
          if player:getStorageValue(time_daySto)-os.time() <= 0 then
          local ret_td = getTaskDailyInfo(player)
             if ret_td then
                if getTaskDailyInfo(player) then
                   if player:getStorageValue(getTaskDailyInfo(player).storage) == getTaskDailyInfo(player).amount then
                   local pt1 = getTaskDailyInfo(player).pointsTask[1]
                   local pt2 = getTaskDailyInfo(player).pointsTask[2]
                   local txt = 'Thanks for finishing the task, your awards are: '..(pt1 > 1 and pt1..' task points' or pt1 <= 1 and pt1..' task point')..' e '..(pt2 > 1 and pt2..' rank points' or pt2 <= 1 and pt2..' rank point')..', '
                      if #getTaskDailyInfo(player).items > 0 then
                         txt = txt..'in addition to winning: '..getItemsFromTable(getTaskDailyInfo(player).items)..', '
                      for g = 1, #getTaskDailyInfo(player).items do
                         player:addItem(getTaskDailyInfo(player).items[g].id, getTaskDailyInfo(player).items[g].count)
                      end
                      end
                      local exp = getTaskDailyInfo(player).exp
                      if exp > 0 then
                         txt = txt..'I will also give you '..exp..' experience, '
                         player:addExperience(exp)
                      end
                      npcHandler:say(txt..' thanks again and see you again!', cid)
                      taskPoints_add(player, pt1)
                      taskRank_add(player, pt2)
                      player:setStorageValue(getTaskDailyInfo(player).storage, -1)
                      player:setStorageValue(taskd_storage, -1)
                      player:setStorageValue(time_daySto, 1*60*60*24+os.time())
                      npcHandler.topic[cid] = 0
                      npcHandler:releaseFocus(cid)
                   else
                      npcHandler:say('You have not finished your current task yet. You will receive it when you finish.', cid)
                      npcHandler.topic[cid] = 0
                      npcHandler:releaseFocus(cid)
                   end
                else
                   npcHandler:say("You aren't doing any tasks.", cid)
                   npcHandler.topic[cid] = 0
                   npcHandler:releaseFocus(cid)
                end
             end
          else
             npcHandler:say("You've done a daily task, wait 24 hours to do another one again.", cid)
             npcHandler.topic[cid] = 0
             npcHandler:releaseFocus(cid)
          end
       end

    elseif msg == 'abandon' then
       if npcHandler.topic[cid] == 0 then
          npcHandler:say("Aff, what kind of task do you want to quit, {normal} or {daily}?", cid)
          npcHandler.topic[cid] = 4
       end
    elseif npcHandler.topic[cid] == 4 and msgcontains(msg, 'normal') then
       local ret_t = getTaskInfos(player)
       if ret_t then
          npcHandler:say('Unfortunate this situation, had faith that you would bring me this task done, but I was wrong. As punishment will be '..task_time..' hours without being able to do any task.', cid)
          player:setStorageValue(task_sto_time, os.time()+task_time*60*60)
          player:setStorageValue(ret_t.storage, -1)
          player:setStorageValue(task_storage, -1)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       else
          npcHandler:say("You're not doing any task to be able to abandon it.", cid)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       end
    elseif npcHandler.topic[cid] == 4 and msg == 'daily' then
       local ret_td = getTaskDailyInfo(player)
       if ret_td then
          npcHandler:say('Unfortunate this situation, had faith that you would bring me this task done, but I was wrong. As punishment will be '..task_time..' hours without being able to do any task.', cid)
          player:setStorageValue(task_sto_time, os.time()+task_time*60*60)
          player:setStorageValue(ret_td.storage, -1)
          player:setStorageValue(taskd_storage, -1)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       else
          npcHandler:say("You're not doing any daily tasks to be able to abandon it.", cid)
          npcHandler.topic[cid] = 0
          npcHandler:releaseFocus(cid)
       end
    elseif msg == "normal task list" then
       local text = "----**| -> Normal Tasks <- |**----\n\n"
          for _, d in pairs(task_monsters) do
             text = text .."------ [*] "..d.name.." [*] ------ \n[+] Amount [+] -> ["..(player:getStorageValue(d.storage) + 1).."/"..d.amount.."]:\n[+] Awards [+] -> "..(#d.items > 1 and getItemsFromTable(d.items).." - " or "")..""..d.exp.." experience \n\n"
          end
    
          player:showTextDialog(1949, "" .. text)
          npcHandler:say("Here is the list of normal tasks.", cid)
    elseif msg == "daily task list" then
       local text = "----**| -> Tasks Dailys <- |**----\n\n"
          for _, d in pairs(task_daily) do
             text = text .."------ [*] "..d.name.." [*] ------ \n[+] Amount [+] -> ["..(player:getStorageValue(d.storage) + 1).."/"..d.amount.."]:\n[+] Awards [+] -> "..(#d.items > 1 and getItemsFromTable(d.items).." - " or "")..""..d.exp.." experience \n\n"
          end
    
          player:showTextDialog(1949, "" .. text)
          npcHandler:say("Here is the daily tasks list.", cid)
    end
    end
    
    npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)


    data/talkactions talkactions.xml

    Código:
    <talkaction words="!task" separator=" " script="task system.lua" />

    Código:

    function onSay(player, words, param)
       local text = '---------------------------**| -> Tasks System Infos <- |**---------------------------\n'

       if param:lower() == "me" then
          text = text .. '[+] Task Points [+]: You have '..taskPoints_get(player)..' task points.\n[+] Task Rank Points [+]: Você tem '..taskRank_get(player)..' rank points.\n[+] Rank Task [+]: '..getRankTask(player)..''
          return false,  player:popupFYI(text)
       end

       local ret_t = getTaskInfos(player)
       if ret_t then
          text = text .. '\n\n      [ -> ----- [+] Normal Task [+] ----- <- ]\n      \n[*] Current Task [*]: '..ret_t.name..' - You need to kill: '..ret_t.amount..'.\n[*] Awards [*]: '..getItemsFromTable(ret_t.items)..' - '..ret_t.pointsTask[1]..' Task Points - '..ret_t.pointsTask[2]..' Task Ranks. \n[*] Progress [*]: ['..(player:getStorageValue(ret_t.storage))..'/'..ret_t.amount..']\n[*] Task Status [*]: '..(player:getStorageValue(ret_t.storage) == ret_t.amount and 'Complete' or 'Incomplete')..'!'         
       else
          text = text .. "\n\n      [ -> ----- [+] Normal Task [+] ----- <- ]\n      \n--- You aren't doing any Daily Task."
       end

       local ret_td = getTaskDailyInfo(player)
       if ret_td then
          text = text .. '\n\n\n      [ -> ----- [+] Daily Task [+] ----- <- ]\n      \n[*] Current Task [*]: '..ret_td.name..' - You need to kill: '..ret_td.amount..'.\n[*] Awards [*]: '..getItemsFromTable(ret_td.items)..' - '..ret_td.pointsTask[1]..' Task Points - '..ret_td.pointsTask[2]..' Task Ranks \n[*] Progress [*]: ['..(player:getStorageValue(ret_td.storage))..'/'..ret_td.amount..']\n[*] Task Status [*]: '..(player:getStorageValue(ret_td.storage) == ret_td.amount and 'Complete' or 'Incomplete')..'!'         
       else
          text = text .. "\n\n\n      [ -> ----- [+] Daily Task [+] ----- <- ]\n      \n--- You aren't doing any Daily Task."
       end
    
       return false,  player:popupFYI(text)
    end

    data/creaturescripts creaturescripts.xml

    Código:

    <event type="kill" name="tasksystem" script="task system.lua"/>

    Código:

    function onKill(player, target)
       if target:isPlayer()  or target:getMaster() then
          return true
       end

       local mon_name = target:getName():lower()

       local ret_t = getTaskInfos(player)
       if ret_t then
          if mon_name == ret_t.name or isInArray(ret_t.mons_list, mon_name) then
          local sto_value = player:getStorageValue(ret_t.storage)
             if sto_value < ret_t.amount then
                sto_value = sto_value + 1
                player:setStorageValue(ret_t.storage, sto_value)
                if sto_value < ret_t.amount then
                   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System] Killed ['..(sto_value)..'/'..ret_t.amount..'] '..mon_name..'.')
                else
                   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System] Killed You finished your task.')
                end
             end
          end
       end

       local ret_td = getTaskDailyInfo(player)
       if ret_td then
          if mon_name == ret_td.name or isInArray(ret_td.mons_list, mon_name) then
             local sto_value = player:getStorageValue(ret_td.storage)
             if sto_value < ret_td.amount then
                sto_value = sto_value + 1
                player:setStorageValue(ret_td.storage, sto_value)
                if sto_value < ret_td.amount then
                   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System Daily] Killed ['..(sto_value)..'/'..ret_td.amount..'] '..mon_name..'.')
                else
                   player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Task System Daily] Killed You finished your task.')
                end
             end
          end
       end

       return true
    end

    en login.lua

    Código:
    player:registerEvent("tasksystem")

    o

    Código:
    'tasksystem',

    data/events/scripts/ player.lua


    antes de esta linea

    Código:
    self:sendTextMessage(MESSAGE_INFO_DESCR, description)

    pegar esto

    Código:

    if thing:isCreature() then
          if thing:isPlayer() then
             description = string.format("%s\nTask Rank: "..getRankTask(thing), description)
          end
       end




    [Actions] script YNU5B25
    https://www.tibiaface.com

    3default Re: [Actions] script el Lun Dic 16, 2019 11:11 pm

    ivansho92

    ivansho92
    Miembro
    Miembro
    lo testeo, muchas gracias bro

    Contenido patrocinado


    Ver el tema anterior Ver el tema siguiente Volver arriba  Mensaje (Página 1 de 1.)

    Permisos de este foro:
    No puedes responder a temas en este foro.

     

    BienvenidosTibiaFace es una comunidad de Open Tibia. Para participar debes estar registrado (click para Regístrate).