quest pvp_manager begin
   state start begin
      when login with game.get_event_flag("budokan_open") > 0 and pc.get_map_index() != 112 begin
         q.set_icon("scroll_open_blue.tga")
         send_letter("*Intra la Dojang")
      end
              when button or info begin
                        say_title("Turneul Dojang")
         say("")
         if game.get_event_flag("budokan_open") == 2 then
            say("Arena pentru Turneul Dojang este acum deschisa!")
            say("")
            say("Alatura-te si tu pentru a lupta in ring ")
            say("contra celorlalti jucatori intr-o lupta")
            say("pentru glorie, onoare si faima!")
            say("")
            local s = select("Du-ma acolo acum!","Nu multumesc.")
            if s == 1 then
               pc.warp(857300, 4400)
            end
         else
            say("Arena Dojang se va deschide in curand.")
            say("")
            say("Alatura-te si tu pentru a lupta in ring ")
            say("contra celorlalti jucatori intr-o lupta")
            say("pentru glorie, onoare si faima!")
            say("")
            say("Cand intrarea va fii deschisa, vei putea intra ")
            say("folosind aceast quest. Pregateste-ti echipamentul!")
            say("")
            local s = select("Voi fii pregatit!", "Voi urmarii ca spectator.")
            if s == 1 then
               return
            end

            say_title("Turneul Dojang")
            say("")
            say("Alege o actiune:")
            say("")
            ttype = select("Turneul Dojang : Deschidere", "Inchide")
            if ttype == 5 then
               return
            end

            pvp_manager.say_hof(ttype)
         end
      end

      when login with pc.get_map_index() == 112 and (pvp_attenders == nil or pvp_attenders[pvp_manager.get_my_attender_id()] == nil or (pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode != 1 and pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode != 2)) begin
         if party.is_party() then
            party.remove_player()
         end

         if pvp_attenders == nil then
            pvp_manager.guard_check_position()
            timer("pvp_guard_1", 20)
            return
         end

         if pvp_attenders[pvp_manager.get_my_attender_id()] == nil then
            pvp_manager.guard_check_position()
            timer("pvp_guard_1", 20)
            return
         end

         if pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode != 1 and pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode != 2 then
            pvp_manager.guard_check_position()
            timer("pvp_guard_1", 20)
         end
      end
      
      when pvp_guard_1.timer begin
         if pc.get_map_index() != 112 then
            return
         end
         pvp_manager.guard_check_position()
         timer("pvp_guard_2", 20)
      end
      when pvp_guard_2.timer begin
         if pc.get_map_index() != 112 then
            return
         end
         pvp_manager.guard_check_position()
         timer("pvp_guard_1", 20)
      end
      function guard_check_position()
         if pc.get_local_x() >= 84 and pc.get_local_y() >= 84 and pc.get_local_x() <= 116 and pc.get_local_y() <= 116 then --arena 1
            pvp_manager.guard_reset()
         end
         if pc.get_local_x() >= 84 and pc.get_local_y() >= 136 and pc.get_local_x() <= 116 and pc.get_local_y() <= 168 then --arena 2
            pvp_manager.guard_reset()
         end
         if pc.get_local_x() >= 136 and pc.get_local_y() >= 84 and pc.get_local_x() <= 168 and pc.get_local_y() <= 116 then --arena 3
            pvp_manager.guard_reset()
         end
         if pc.get_local_x() >= 136 and pc.get_local_y() >= 136 and pc.get_local_x() <= 168 and pc.get_local_y() <= 168 then --arena 4
            pvp_manager.guard_reset()
         end
      end
      
      function guard_reset()
         notice_in_map("AUTOPVP-GUARD: "..pc.getname().." a fost eliminat din arena.")
         pc.warp_local(pc.get_map_index(), 1112*100, 24*100)
      end
      
      when 20088.chat."Inchide Arena PvP" with pc.is_gm() and pc.get_map_index() == 112 begin
         say_title("Dojang:")
         say("Intarea in aceasta mapa este acum inchisa")
         say("iar fiecare jucator va fii teleportat in oras...")
         say("")
         warp_all_to_village( pc.get_map_index() , 1 )
         game.set_event_flag("budokan_open", 0)
      end
      
      when 20088.chat."Inapoi in oras" with pc.get_map_index() == 112 begin
         say_title("Maestrul Bataliilor")
         say("")
         say("Doresti sa parasesti arena si sa te intorci ")
         say("acasa, in oras?")
         say("")
         local s = select("Da", "Nu")
         if s == 1 then
            warp_to_village()
         end
      end

      when 20088.chat."GM: Intrerupe Turneul PvP" with pc.get_map_index() == 112 and pc.is_gm() and game.get_event_flag("pvp") != 0 begin
         say_title("Intrerupe Turneul PvP")
         say("")
         say("Chiar doresti sa intrerupi Turneul PvP?")
         say("")
         local s = select("Da", "Nu")
         if s == 1 then
            game.set_event_flag("pvp", 0)
            pvp_attenders = nil
            notice_all("Turneul Dojang a fost anulat.")
            say_title("Turneu Dojang anulat!")
            say("Turneul Dojang a fost anulat.")
            say("")
         end
      end

      when 20088.chat."GM: Incepe Turneul PvP" with pc.get_map_index() == 112 and pc.is_gm() and game.get_event_flag("pvp") == 0 begin

         local tournament_presets =
         {
         --   Min Lv       Max Lv        Reward vnum    Reward count
            {98,       99,         11971,         1 },
         }

         say_title("Incepe Turneul PvP")
         say("")
          local tournament = select("Turneul Dojang", "Inchide")

         if tournament < 5 then
            prize_vnum = tournament_presets[tournament][4]
            prize_count = tournament_presets[tournament][5]

                game.set_event_flag("pvp_price_vnum", prize_vnum)
            game.set_event_flag("pvp_price_count", prize_count)
            
            say_title("Start PvP-Tournament")
            say("")
            say("Premiul castigatorului va fii "..prize_count.."x "..item_name(prize_vnum))
            say("(vnum: "..prize_vnum..")")
            say("")
         end      

         local s = select("Start now", "Cancel")
         if s == 2 then
            return
         end

         say_title("Incepe Turneul Dojang")
         say("Turneul Dojang a inceput.")
         say("Oricine vrea sa participe se poate")
         say("inscrie aici.")
         say("")
         say("Inscrierile se pot inchide aici.")
           game.set_event_flag("pvp", 1)
         attender_count = 0
         game.set_event_flag("pvp_tournament", get_global_time())
         pvp_attenders = nil
         pvp_attenders = { }
         
         arena = {
                  -- arena 1
                  {
                     { 113, 100 },
                     { 88, 100 },
                     0,
                     "SLEEPING",
                     0,
                  },
                  -- arena 2
                  {
                     { 113, 152 },
                     { 88, 152 },
                     0,
                     "SLEEPING",
                     0,
                  },
                  -- arena 3
                  {
                     { 140, 152 },
                     { 164, 152 },
                     0,
                     "SLEEPING",
                     0,
                  },
                  -- arena 4
                  {
                     { 164, 100 },
                     { 140, 100 },
                     0,
                     "SLEEPING",
                     0,
                  },
               }
         
         notice_all("Inscrierile pentru Turneul Dojang au fost deschise!")
         notice_all("Castigatorul va primii "..game.get_event_flag("pvp_price_count").."x "..item_name(game.get_event_flag("pvp_price_vnum")).." ca premiu!")
      end
      
      when 20088.chat."Inscrie-te la Turneul PvP" with pc.get_map_index() == 112 and game.get_event_flag("pvp") == 1 begin
         say_title(mob_name(,)..":")
         say("")
         if game.get_event_flag("pvp_tournament") == pc.getqf("pvp_tournament") then
            say("Te-ai inscris deja la Turneu.")
            say("")
            return
         end
         ----"123456789012345678901234567890123456789012345678901234567890"|

         say("Bun venit la Dojang. In Turneu vei lupta")
         say("impotriva altor jucatori.")
         say("")
         say("Infrange toti participantii pentru a iti primii premiul")
         say("si a iti castiga un loc in Hala Eroilor!")
         say("")
         say("Doresti sa accepti provocarea?)
         say("")
         local s = select("Vreau sa particip!", "Nu am nici o sansa..")
         say_title(mob_name(,)..":")
         say("")
         if s == 1 then
            say("Vei fii chemat cand iti va venii randul, dar ai grija.")
            say("Trebuie sa stai prin preajma, altfel vei fii descalificat.")
            say("")
            say("Mult noroc!")
            say("")
            
            pvp_attenders[attender_count+1] = {name = pc.getname(), level = pc.get_level(), partner = nil, winner = true, fight_mode = 0, arena = 0}
            pc.setqf("attender_id", attender_count+1)
            pc.setqf("pvp_tournament", game.get_event_flag("pvp_tournament"))
            attender_count = attender_count + 1
         elseif s == 2 then
            say("Intr-adevar, pari cam slab.")
            say("Am mai avut cazuri care s-au soldat")
            say("cu moartea la acest turneu.")
            say("")
         end
      end
      
      when ,.chat."Cati participanti sunt?" with pc.get_map_index() == 112 and pc.is_gm() and game.get_event_flag("pvp") == 1 begin
         say_title("PVP-Tournament")
         say("Deocamdata sunt "..tostring(attender_count).." playeri inscrisi.")
         say("Shall the registration be closed and betting")
         say("Ar trebuii sa incepem?")
         say("")
         local s = select("Inchide inscrierile.", "Continua cu inscrierile.")
         if s == 1 then
            say_title("Inchide inscrierile:")
            say("Inscrierile au fost inchise.")
             say("")
            game.set_event_flag("pvp", 2)
         end
      end
          when 20088.chat."Cine participa la turneu?" with pc.get_map_index() == 112 and game.get_event_flag("pvp") == 2 begin
         setskin(NOWINDOW)
         chat("Urmatorii playeri sunt participanti ai Turneului:")
         for i = 1, attender_count, 4 do
            local chatline = ""
            for j = i, i + 4, 1 do
               if pvp_attenders[j] != nil then
                  chatline = chatline..pvp_attenders[j].name.."   "
               end
            end
            syschat(chatline)
         end
         syschat("In total sunt "..attender_count.." participanti")
      end
      
      when 20088.chat."Cu cine voi concura in runda urmatoare?" with pc.get_map_index() == 112 and game.get_event_flag("pvp") == 3 and game.get_event_flag("pvp_tournament") == pc.getqf("pvp_tournament") begin
         say_title(mob_name(,)..":")
         say("")
         if pvp_manager.get_duel_partner() == nil then
            say("Nu este niciun oponent disponibil pentru tine momentan")
            say("")
            say("Daca nu iti vom gasii un adversar, vei avea norocul")
            say("de a trece in runda urmatoare fara sa lupti.")
            say("")
            return
         end
         say("In runda urmatoare vei lupta impotriva lui:")
         say("")
         say_reward(""..pvp_manager.get_duel_partner().."")
         say("")
      end
      
      
      function make_duel_list()
         duel_list = { }
         local i = 0
         for ai = 1, attender_count, 1 do
            if pvp_attenders[ai] != nil and pvp_attenders[ai].partner == nil and pvp_attenders[ai].winner == true then
               local partner_id = pvp_manager.findpartner(tostring(pvp_attenders[ai].name))
               if partner_id != nil then
                  pvp_attenders[ai].partner = tostring(pvp_attenders[partner_id].name)
                  pvp_attenders[partner_id].partner = tostring(pvp_attenders[ai].name)
                  duel_list[i] = {fighter_id1 = ai, fighter_id2 = partner_id}
                  i = i + 1
               end
            end
         end
         
         for ai = 1, attender_count, 1 do
            if pvp_attenders[ai] != nil and pvp_attenders[ai].partner == nil and pvp_attenders[ai].winner == true then
               local partner_id = pvp_manager.findpartner_for_partnerless(tostring(pvp_attenders[ai].name))
               if partner_id != nil then
                  pvp_attenders[ai].partner = tostring(pvp_attenders[partner_id].name)
                  pvp_attenders[partner_id].partner = tostring(pvp_attenders[ai].name)
                  duel_list[i] = {fighter_id1 = ai, fighter_id2 = partner_id}
                  i = i + 1
               end
            end
         end
      end
      
      
      function findpartner(name)
         local partner_id = nil
         for ai = 1, attender_count, 1 do
            if pvp_attenders[ai] != nil and pvp_attenders[ai].winner == true and tostring(pvp_attenders[ai].name) != name and pvp_attenders[ai].partner == nil and pvp_manager.is_player_in_map(tostring(pvp_attenders[ai].name)) == true then
                    partner_id = ai
            end
         end
         return tonumber(partner_id)
      end
      
      function findpartner_for_partnerless(name)
         local closest_level = nil
         local partner_id = nil
         for ai = 1, attender_count, 1 do
            if pvp_attenders[ai] != nil and pvp_attenders[ai].winner == true and tostring(pvp_attenders[ai].name) != name and pvp_attenders[ai].partner == nil and pvp_manager.is_player_in_map(tostring(pvp_attenders[ai].name)) == true then
                end
            end
         end
         return partner_id
      end
      
      function is_player_in_map(name)
         if pc.getname() == name then
            return true
         end
         local myname = pc.getname()
         local target = find_pc_by_name(name)
         local t = pc.select(target)
         if pc.getname() == myname then
            pc.select(t)
            return false
         end
         pc.select(t)
         return true
      end
      
      
      when 20088.chat."GM: Curata arenele" with pc.is_gm() and game.get_event_flag("pvp") == 3 begin
         for aArena = 1, 4, 1 do
            arena[aArena][3] = 0
            arena[aArena][4] = "SLEEPING"
         end
         pvp_manager.refresh_arenas()
      end
      
      -- not working
      --[[
      when 20088.chat."GM: Incheie lupta" with pc.is_gm() and game.get_event_flag("pvp") == 2 begin
         say_title("Incheie lupta:")
         say("In care arena doresti sa inchei lupta?")
         local s = select("Arena 1", "Arena 2", "Arena 3", "Arena 4", "Inapoi")
         
         if s == 5 then
            return
         end
         
         local fighter1 = nil
         local fighter2 = nil
         for ai = 1, attender_count, 1 do
            if pvp_attenders[ai].arena == s and pvp_attenders[ai].fight_mode != 0 then
               if fighter1 == nil then
                  fighter1 = ai
               else
                  fighter2 = ai
               end
            end
         end
         
         if fighter1 == nil then
            say_title("Incheie lupta:")
            say("Nu sunt lupte in desfasurare in aceasta arena.")
            say("")
            return
         end
         
         say_title("Incheie lupta:")
         say("Cine ar trebuii sa fie ales castigator cand lupta in arena "..s.." ")
         say("va trebuii sa fie inchisa?")
         local w = select(tostring(pvp_attenders[fighter1].name), tostring(pvp_attenders[fighter1].name), "Cancel")
         if w == 3 then
            return
         end
         
         if w == 1 then
            pvp_attenders[fighter2].winner = false
            notice_in_map(tostring(pvp_attenders[fighter1].name).." a castigat lupta impotriva lui "..tostring(pvp_attenders[fighter2].name).."!", pc.get_map_index())
            pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter1].name, 1112, 234))
            pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter2].name, 1112, 24))
         else
            pvp_attenders[fighter1].winner = false
            notice_in_map(tostring(pvp_attenders[fighter2].name).." a castigat lupta impotriva lui "..tostring(pvp_attenders[fighter1].name).."!", pc.get_map_index())
            pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter1].name, 1112, 24))
            pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter2].name, 1112, 234))
         end
         
         pvp_attenders[fighter1].fight_mode = 0
         pvp_attenders[fighter2].fight_mode = 0
         
         
         arena[s][3] = 0
         pvp_manager.refresh_arenas()
         
         say_title("Incheie lupta:")
         say("Lupta s-a incheiat.")
      end
      --]]
      
      when 20088.chat."GM: Premiul Turneului Dojang" with pc.is_gm() begin
         say_title("Premiu:")
         say("Premiul actual: "..game.get_event_flag("pvp_price_count").."x "..item_name(game.get_event_flag("pvp_price_vnum")).." (vnum: "..game.get_event_flag("pvp_price_vnum")..")")
         say("")
         local s = select("Schimba premiul", "Close")
         if s == 2 then
            return
         end
         say_title("Schimba premiul:")
         say("Introdu codul noului premiu:")
         say("")
         local vnum = input()
         say_title("Schimba premiul:")
         say("Alege cantitatea de premii pe care o va primii castigatorul")
         say("")
         local count = input()
         game.set_event_flag("pvp_price_count", count)
         game.set_event_flag("pvp_price_vnum", vnum)
         say_title("Schimba premiul:")
         say("Premiul a fost schimbat.")
         say("Noul premiu: "..count.."x "..item_name(vnum).." (vnum: "..vnum..")")
         say("")
      end

      
      function refresh_arenas()
         for aArena = 1, 4, 1 do
            if duel_list[duel_list_index] == nil then
               if playerless_mode == true then
                  pvp_manager.init_next_round()
               else
                  pvp_manager.fight_playerless()
               end
               return
            end
            if arena[aArena][3] == 0 then
               arena[aArena][3] = 1
               pvp_manager.fight_init(duel_list[duel_list_index].fighter_id1, duel_list[duel_list_index].fighter_id2, aArena)
            end
         end
      end
      

      function fight_init(pid1, pid2, arena_id)
         duel_list_index = duel_list_index + 1
         if pvp_manager.is_player_in_map(tostring(pvp_attenders[pid1].name)) == false then
            notice_in_map(tostring(pvp_attenders[pid1].name).." nu este online si a fost descalificat.", pc.get_map_index())
            pvp_attenders[pid1].winner = false
            pvp_attenders[pid2].partner = nil
            arena[arena_id][3] = 0
            pvp_manager.refresh_arenas()
            return
         end
         if pvp_manager.is_player_in_map(tostring(pvp_attenders[pid2].name)) == false then
            notice_in_map(tostring(pvp_attenders[pid2].name).." nu este online si a fost descalificat.", pc.get_map_index())
            pvp_attenders[pid2].winner = false
            pvp_attenders[pid1].partner = nil
            arena[arena_id][3] = 0
            pvp_manager.refresh_arenas()
            return
         end
         
         notice_in_map(tostring(pvp_attenders[pid1].name).." si "..tostring(pvp_attenders[pid2].name).." intrati in ring va rog!", pc.get_map_index())
         
         --[[
         local f1_accept = ask_fight(tostring(pvp_attenders[pid1].name), tostring(pvp_attenders[pid2].name))
         if f1_accept != CONFIRM_OK then
            notice_in_map(tostring(pvp_attenders[pid1].name).." a refuzat lupta impotriva "..tostring(pvp_attenders[pid2].name)..".", pc.get_map_index())
            pvp_attenders[pid1] = nil
            pvp_attenders[pid2].partner = nil
            pvp_manager.refresh_arenas()
            return
         end
         
         local f2_accept = confirm(find_pc_by_name(tostring(pvp_attenders[pid2].name)), "a refuzat lupta impotriva "..tostring(pvp_attenders[pid1].name).. " an?", 15)
         if f2_accept != CONFIRM_OK then
            notice_in_map(tostring(pvp_attenders[pid2].name).." a refuzat lupta impotriva  "..tostring(pvp_attenders[pid1].name)..".", pc.get_map_index())
            pvp_attenders[pid2] = nil
            pvp_attenders[pid1].partner = nil
            pvp_manager.refresh_arenas()
            return
         end
         ]]
         
         pvp_attenders[pid1].fight_mode = 1
         pvp_attenders[pid2].fight_mode = 1
         pvp_attenders[pid1].arena = arena_id
         pvp_attenders[pid2].arena = arena_id
         
         
         pvp_manager.local_pc_warp(tostring(pvp_attenders[pid1].name), arena[arena_id][1][1], arena[arena_id][1][2])
         pvp_manager.local_pc_warp(tostring(pvp_attenders[pid2].name), arena[arena_id][2][1], arena[arena_id][2][2])
      end
      
      when login with pc.get_map_index() == 112 and game.get_event_flag("pvp") == 3 and pvp_manager.get_fight_mode() == 1 begin
         affect.add(apply.MOV_SPEED, -10000, 2)
         affect.add_collect(apply.HP_REGEN, 5000, 30)
         affect.add_collect(apply.SP_REGEN, 5000, 30)
         affect.remove_good()
         affect.remove_bad()
         affect.remove(apply.AFFECT_JUMAGAP) -- Remove "Remove Magic"

         pvp_manager.set_fight_mode(2)
         if arena[pvp_manager.get_arena()][3] == 2 then
            arena[pvp_manager.get_arena()][5] = 30
            loop_timer("fight_start_countdown", 1)
         else
            timer("partner_timeout", 60)
         end
         arena[pvp_manager.get_arena()][3] = 2
      end      
      
      when partner_timeout.timer begin
         if pvp_manager.is_player_in_map(pvp_manager.get_duel_partner()) == true or game.get_event_flag("pvp") != 2 or pvp_manager.get_fight_mode() != 2 then
            return
         end
         pvp_manager.set_fight_mode(3)
         if arena[pvp_manager.get_arena()][3] == 3 then
            return
         end
         arena[pvp_manager.get_arena()][3] = 3
         notice_in_map(pc.getname().." a castigat lupta impotriva lui "..pvp_manager.get_duel_partner().." prin descalificare!", pc.get_map_index())
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
         pvp_attenders[pvp_manager.get_my_attender_id()].winner = true
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = false
         pc.warp_local(pc.get_map_index(), 111200, 23400)
      end

      when fight_start_countdown.timer begin
         if arena[pvp_manager.get_arena()][5] == -1 then
            return
         end
         local partner_vid = find_pc_by_name(pvp_manager.get_duel_partner())
         local my_vid = pc.get_vid()
         if arena[pvp_manager.get_arena()][5] == 0 then
            arena[pvp_manager.get_arena()][5] = -1
            --pc.select(partner_vid)
            --command("pvp "..my_vid)
            --pc.select(my_vid)
            --command("pvp "..partner_vid)
            pc.start_duel(partner_vid)
            notice_in_map("Lupta dintre "..pvp_manager.get_duel_partner().." si "..pc.get_name().." incepe!", pc.get_map_index())
            timer("fight_start_countdown_shutdown", 1)
         else
            pc.select(partner_vid)
            if math.mod(arena[pvp_manager.get_arena()][5], 5) == 0 then
               syschat("Lupta incepe in "..tostring(arena[pvp_manager.get_arena()][5]).." secunde.")
            end
            affect.add(apply.MOV_SPEED, -10000, 2)
            pc.select(my_vid)
            if math.mod(arena[pvp_manager.get_arena()][5], 5) == 0 then
               syschat("Lupta incepe in  "..tostring(arena[pvp_manager.get_arena()][5]).." secunde.")
            end
            affect.add(apply.MOV_SPEED, -10000, 2)
            arena[pvp_manager.get_arena()][5] = arena[pvp_manager.get_arena()][5] - 1
         end
      end
      
      when fight_start_countdown_shutdown.timer begin
         cleartimer("fight_start_countdown")
      end
      
      when logout with game.get_event_flag("pvp") == 3 and pc.get_map_index() == 112 and pvp_manager.get_fight_mode() == 2 begin
         pvp_manager.set_fight_mode(3)
         arena[pvp_manager.get_arena()][3] = 3
         notice_in_map(pvp_manager.get_duel_partner().." has won the fight against "..pc.getname().."!", pc.get_map_index())
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
         pvp_attenders[pvp_manager.get_my_attender_id()].winner = false
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = true
         
         local target = find_pc_by_name(pvp_manager.get_duel_partner())
         local t = pc.select(target)
         pc.change_gold(game.get_event_flag("pvp_round_gold")*pvp_round_num)
         pc.select(t)
         
         pvp_manager.local_pc_warp(pvp_manager.get_duel_partner(), 1112, 24)
      end
      
      when kill with game.get_event_flag("pvp") == 3 and pc.get_map_index() == 112 and npc.is_pc() and pvp_manager.get_fight_mode() == 2 begin
         pvp_manager.set_fight_mode(3)
         if arena[pvp_manager.get_arena()][3] == 3 then
            return
         end
         arena[pvp_manager.get_arena()][3] = 3
         notice_in_map(pc.getname().." a castigat lupta impotriva lui "..pvp_manager.get_duel_partner().."!", pc.get_map_index())
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
         pvp_attenders[pvp_manager.get_my_attender_id()].winner = true
         pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = false
         
         pc.change_gold(game.get_event_flag("pvp_round_gold")*pvp_round_num)
         
         timer("fight_end", 5)
      end
      
      when fight_end.timer begin
         pc.warp_local(pc.get_map_index(), 111200, 23400)
         pvp_manager.local_pc_warp(pvp_manager.get_duel_partner(), 1112, 24)
      end
      
      when letter with pc.get_map_index() == 112 and game.get_event_flag("pvp") == 3 and pvp_manager.get_fight_mode() == 3 begin
         pvp_manager.set_fight_mode(0)
         
         if pvp_attenders[pvp_manager.get_my_attender_id()].winner == true then
            arena[pvp_manager.get_arena()][3] = 0
            pvp_manager.refresh_arenas()
         end
      end
      
      function fight_playerless()
         for aArena = 1, 4, 1 do
            if arena[aArena][3] != 0 then
               return
            end
         end
         playerless_mode = true

         
         pvp_manager.make_duel_list()
         pvp_manager.refresh_arenas()
      end
      
      function init_next_round()
         for aArena = 1, 4, 1 do
            if arena[aArena][3] != 0 then
               return
            end
         end
         playerless_mode = false
         
         local winner_count = 0
         local winner_id = 0
         for ai = 1, attender_count, 1 do
            pvp_attenders[ai].partner = nil
            pvp_attenders[ai].fight_mode = 0
            if pvp_attenders[ai] != nil and pvp_attenders[ai].winner == true then
               winner_count = winner_count + 1
               winner_id = ai
            end
         end
         
         if winner_count == 1 then
            notice_all(pvp_attenders[winner_id].name.." a castigat Turneul Dojang!")
            notice_all(pvp_attenders[winner_id].name.." primeste "..game.get_event_flag("pvp_price_count").."x "..item_name(game.get_event_flag("pvp_price_vnum")).." ca premiu!")
            
            pvp_manager.distribute_bets(pvp_attenders[winner_id].name)
            
            local target = find_pc_by_name(pvp_attenders[winner_id].name)
            local t = pc.select(target)
            pc.give_item2(game.get_event_flag("pvp_price_vnum"), game.get_event_flag("pvp_price_count"))
            pc.select(t)
            notice_all("Turneul Dojang s-a incheiat.")
            game.set_event_flag("pvp", 0)
            
            if game.get_event_flag("pvp_tournament_type") ~= 0 and game.get_event_flag("pvp_tournament_type") < 5 then
               local player_found = false
               local new_content = ""
               local player_row = "%d\\t%s\\n"

               local f = io.open("data/"..pvp_manager.retrieve_hof_name(game.get_event_flag("pvp_tournament_type")), "r")
               if f ~= nil then
                  for line in f:lines() do
                     local data = string.split(line, "\\t") --format: [wins] [playername]

                     if new_content ~= "" then
                        new_content = new_content .. "\\n"
                     end

                     if tostring(data[2]) == pvp_attenders[winner_id].name and not player_found then
                        new_content = new_content .. string.format(player_row, tonumber(data[1]) + 1, pvp_attenders[winner_id].name)
                        player_found = true
                     else
                        new_content = new_content .. line
                     end
                  end
                  f:close()
               end

               if not player_found then
                  new_content = new_content .. "\\n" .. string.format(player_row, 1, pvp_attenders[winner_id].name)
               end

               pvp_manager.replace_hof(game.get_event_flag("pvp_tournament_type"), new_content)
            end

            game.set_event_flag("pvp_tournament_type", 0)
            pvp_attenders = nil
            return
         end
         
         pvp_manager.make_duel_list()
         duel_list_index = 0
         if winner_count == 2 then
            notice_all("Runda finala din Turneu incepe acum!")
         elseif winner_count <= 4 then
            notice_all("Runda semi-finala din Turneu incepe acum!")
         else
            notice_all("Urmatoarea runda din Turneu incepe acum!")
         end
         pvp_round_num = pvp_round_num + 1
         pvp_manager.refresh_arenas()
      end
      
      function distribute_bets(winner_name)
         --table.insert(betting_list, {pc.get_name(), bet_amount, player})
         local jackpot = 0
         local jackpot_winner_only = 0
         local winners = 0
         for i = 1, table.getn(betting_list), 1 do
            if betting_list[i][3] == winner_name then
               jackpot_winner_only = jackpot_winner_only + betting_list[i][2]
            end
            jackpot = jackpot + betting_list[i][2]
            winners = winners + 1
         end
         
         for i = 1, table.getn(betting_list), 1 do
            if betting_list[i][3] == winner_name then
               pvp_manager.give_jackpot_gold(betting_list[i][1], math.ceil( (betting_list[i][2] / jackpot_winner_only)*jackpot ))
            end
         end
         
      end
      
      function give_jackpot_gold(name, amount)
         local target = find_pc_by_name(name)
         if target == 0 then
            return
         end
         local t = pc.select(target)
         pc.change_money(amount)
         pc.select(t)
      end
      
      function local_pc_warp(name, x, y)
         local target = find_pc_by_name(name)
         local t = pc.select(target)
         pc.warp_local(pc.get_map_index(), x*100, y*100)
         pc.select(t)
      end
      
      function setqf_by_name(name, flag, value)
         local target = find_pc_by_name(name)
         local t = pc.select(target)
         pc.setqf(flag, value)
         pc.select(t)
      end
      
      function getqf_by_name(name, flag)
         local target = find_pc_by_name(name)
         local t = pc.select(target)
         local rflag = pc.getqf(flag)
         pc.select(t)
         return rflag
      end
      
      function get_attender_id_by_name(name)
         for ai = 1, attender_count, 1 do
            if tostring(pvp_attenders[ai].name) == name then
               return ai
            end
         end
         return 0
      end
      
      function get_my_attender_id()
         return pvp_manager.get_attender_id_by_name(pc.get_name())
      end
      
      function get_duel_partner()
         if pvp_attenders[pvp_manager.get_my_attender_id()] != nil and pvp_attenders[pvp_manager.get_my_attender_id()].partner != nil then
            return pvp_attenders[pvp_manager.get_my_attender_id()].partner
         else
            return nil
         end
      end
      
      function get_fight_mode()
         if pvp_attenders != nil and pvp_manager.get_my_attender_id() != 0 and pvp_attenders[pvp_manager.get_my_attender_id()] != nil and pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode != nil then
            return pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode
         else
            return 0
         end
      end
      
      function set_fight_mode(fmode)
         pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode = fmode
      end
      
      function get_arena()
         return pvp_attenders[pvp_manager.get_my_attender_id()].arena
      end
      
      function set_arena(id)
         pvp_attenders[pvp_manager.get_my_attender_id()].arena = id
      end
      
      function ask_fight(asker, target)
         return confirm(find_pc_by_name(target), "Te vei lupta impotriva "..asker.. "?", 15)
      end
      
      function retrieve_hof_name(tournament_num)
         local names = {"pvp_dojang"}
         return names[tournament_num]
      end

      function replace_hof(tnum, content)
         local f = io.open("data/"..pvp_manager.retrieve_hof_name(tnum), "w+")
         f:write(content)
         f:close()
      end

      function get_hof(tnum, offset, playerAmount)
         local f = io.open("data/"..pvp_manager.retrieve_hof_name(tnum), "r")
         if not f then 
            return function() return nil end 
         end

         local participants = {}
         for line in f:lines() do
            local data = string.split(line, "\t")
            if data[2] ~= nil then
               participants[data[2]] = tonumber(data[1])
            end
         end
         f:close()

         local sorter = function(tb,a,b) return tonumber(tb[b]) < tonumber(tb[a]) end
         return table.sort_by_value(participants, sorter, offset, playerAmount)
      end
      say("")
   end
end

Tutorial instalare quest:

  • Salvaţi conţinutul quest-ului într-un fişier text numit de exemplu nume_quest.quest

  • Vă conectaţi la filezilla / winscp şi întrati în /usr/home/game/share/locale/germany/quest (depinde ce server aveţi).

  • Îl puneţi acolo (să fie .quest sau .lua) şi da-ţi permisiuni 777.

  • Te loghezi în FreeBSD / putty şi scrii în felul următor: cd /usr/home/game/share/locale/germany/questapoi ./qc nume_quest.quest

  • Intraţi pe server şi scrieţi /reload q