Guest User

Pvp Manager - musicinstructor

a guest
May 11th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 32.42 KB | None | 0 0
  1. quest pvp_manager begin
  2.     state start begin
  3.         when login with game.get_event_flag("budokan_open") > 0 and pc.get_map_index() != 115 begin
  4.             q.set_icon("scroll_open_blue.tga")
  5.             send_letter("*Intră în arena Dojang")
  6.         end
  7.  
  8.         when button or info begin
  9.             say_title("Turneul PvP:")
  10.             if game.get_event_flag("budokan_open") == 2 then
  11.                 say("Arena Dojang este acum deschisă !")
  12.                 say("")
  13.                 say("Alătură-te pentru pariuri sau participă în duelele")
  14.                 say("competitive cu alţi jucători pentru a obţine")
  15.                 say("glorie şi bani.")
  16.                 say("")
  17.                 local s = select("Du-mă acolo acum.","Nu, mulţumesc.")
  18.                 if s == 1 then
  19.                     pc.warp(844800,0)
  20.                 end
  21.             else
  22.                 say("Arena Dojang se va deschide în scurt timp.")
  23.                 say("")
  24.                 say("Alătură-te pentru pariuri sau participă în duelele")
  25.                 say("competitive cu alţi jucători pentru a obţine")
  26.                 say("glorie şi bani.")
  27.                 say("")
  28.                 say("Când intrarea este permisă te poţi duce acolo")
  29.                 say("prin acest quest. Pregăteşte-ţi armele !")
  30.                 say("")
  31.             end
  32.         end
  33.         when login with pc.get_map_index() == 115 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
  34.             if pvp_attenders == nil then
  35.                 pvp_manager.guard_check_position()
  36.                 timer("pvp_guard_1", 20)
  37.                 return
  38.             end
  39.             if pvp_attenders[pvp_manager.get_my_attender_id()] == nil then
  40.                 pvp_manager.guard_check_position()
  41.                 timer("pvp_guard_1", 20)
  42.                 return
  43.             end
  44.             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
  45.                 pvp_manager.guard_check_position()
  46.                 timer("pvp_guard_1", 20)
  47.             end
  48.         end
  49.         when pvp_guard_1.timer begin
  50.             if pc.get_map_index() != 115 then
  51.                 return
  52.             end
  53.             pvp_manager.guard_check_position()
  54.             timer("pvp_guard_2", 20)
  55.         end
  56.         when pvp_guard_2.timer begin
  57.             if pc.get_map_index() != 115 then
  58.                 return
  59.             end
  60.             pvp_manager.guard_check_position()
  61.             timer("pvp_guard_1", 20)
  62.         end
  63.         function guard_check_position()
  64.             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
  65.                 pvp_manager.guard_reset()
  66.             end
  67.             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
  68.                 pvp_manager.guard_reset()
  69.             end
  70.             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
  71.                 pvp_manager.guard_reset()
  72.             end
  73.             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
  74.                 pvp_manager.guard_reset()
  75.             end
  76.         end
  77.        
  78.         function guard_reset()
  79.             notice_in_map("AUTOPVP-GUARD: "..pc.getname().." a fost dat afară din arenă.")
  80.             pc.warp_local(pc.get_map_index(), 126*100, 24*100)
  81.         end
  82.        
  83.         when 20378.chat."Închide Arena Dojang." with pc.is_gm() and pc.get_map_index() == 115 begin
  84.             say_title("Dojang:")
  85.             say("Intrarea în arena Dojand este închisă acum")
  86.             say("Cu toţii vor fi teleportaţi în oraş...")
  87.             say("")
  88.             warp_all_to_village( pc.get_map_index() , 1 )
  89.             game.set_event_flag("budokan_open", 0)
  90.         end
  91.        
  92.         when 20378.chat."Înapoi în oraş." with pc.get_map_index() == 115 begin
  93.             say_title("Vesemir:")
  94.             say("")
  95.             say("Doreşti să te întorci înapoi în oraş?")
  96.             say("")
  97.             local s = select("Da", "Nu")
  98.             if s == 1 then
  99.                 warp_to_village()
  100.             end
  101.         end
  102.  
  103.         when 20378.chat."GM: Anulează Turneul PvP" with pc.get_map_index() == 115 and pc.is_gm() and game.get_event_flag("pvp") != 0 begin
  104.             say_title("Anulează Turneul PvP")
  105.             say("Chiar doreşti să opreşti turneul PvP?")
  106.             say("")
  107.             local s = select("Da", "Nu")
  108.             if s == 1 then
  109.                 game.set_event_flag("pvp", 0)
  110.                 pvp_attenders = nil
  111.                 notice_all("Turneul PvP a fost anulat.")
  112.                 say_title("Turneu PvP anulat.")
  113.                 say("Turneul PvP a fost anulat.")
  114.                 say("")
  115.             end
  116.         end
  117.  
  118.         when 20378.chat."GM: Porneşte Turneul PvP" with pc.get_map_index() == 115 and pc.is_gm() and game.get_event_flag("pvp") == 0 begin
  119.             say_title("Porneşte Turneul PvP")
  120.             say("Te rugăm să setezi nivelele limită pentru")
  121.             say("Turneul PvP.")
  122.             say("")
  123.             say_reward("Nivel minim (minim 15):")
  124.             local str_min_level = input()
  125.             say_title("Începe Turneul PvP")
  126.             local min_level = tonumber(str_min_level)
  127.             if min_level == nil then
  128.                 say("Nu a fost introdus nici un număr.")
  129.                 say("")
  130.                 return
  131.             end
  132.             if tonumber(str_min_level) < 15 then
  133.                 min_level = 15
  134.             end
  135.             say("Nivelul minim a fost setat la: "..tostring(min_level)..".")
  136.             say("Te rugăm să introduci nivelul maxim:")
  137.             local str_max_level = input()
  138.             say_title("Începe Turneul PvP")
  139.             local max_level = tonumber(str_max_level)
  140.             if max_level == nil then
  141.                 say("Nici un număr nu a fost introdus.")
  142.                 say("")
  143.                 return
  144.             end
  145.             if tonumber(str_max_level) < min_level then
  146.                 say("Nivelul maxim trebuie să fie mai mare decât")
  147.                 say("nivelul minim.")
  148.                 say("")
  149.                 return
  150.             end
  151.            
  152.             game.set_event_flag("pvp_minlevel", min_level)
  153.             game.set_event_flag("pvp_maxlevel", max_level)
  154.            
  155.             say("Nivelul minim a fost setat la "..tostring(min_level)..".")
  156.             say("Nivelul maxim a fost setat la "..tostring(max_level)..".")
  157.             say("")
  158.             local s = select("Începe acum.", "Închide.")
  159.             if s == 2 then
  160.                 return
  161.             end
  162.            
  163.             say_title("Începe Turneul PvP")
  164.             say("Turneul PvP a început. Cei ce vor să participe")
  165.             say("se pot înscrie aici. Înscrierile pot fi")
  166.             say("închise de aici..")
  167.             say("")
  168.             say_reward("Nivelele limită curente: "..game.get_event_flag("pvp_minlevel").." - "..game.get_event_flag("pvp_maxlevel"))
  169.             game.set_event_flag("pvp", 1)
  170.             attender_count = 0
  171.             game.set_event_flag("pvp_tournament", get_global_time())
  172.             pvp_attenders = nil
  173.             pvp_attenders = { }
  174.            
  175.             arena = {
  176.                         -- arena 1
  177.                         {
  178.                             { 113, 100 },
  179.                             { 88, 100 },
  180.                             0,
  181.                             "SLEEPING",
  182.                             0,
  183.                         },
  184.                         -- arena 2
  185.                         {
  186.                             { 113, 152 },
  187.                             { 88, 152 },
  188.                             0,
  189.                             "SLEEPING",
  190.                             0,
  191.                         },
  192.                         -- arena 3
  193.                         {
  194.                             { 140, 152 },
  195.                             { 164, 152 },
  196.                             0,
  197.                             "SLEEPING",
  198.                             0,
  199.                         },
  200.                         -- arena 4
  201.                         {
  202.                             { 164, 100 },
  203.                             { 140, 100 },
  204.                             0,
  205.                             "SLEEPING",
  206.                             0,
  207.                         },
  208.                     }
  209.            
  210.             notice_all("Înscrierile pentru turneul PvP au fost deschise. Echipează-te şi vino în Arena Dojang.")
  211.             notice_all("Nivelele limită curente: "..game.get_event_flag("pvp_minlevel").." - "..game.get_event_flag("pvp_maxlevel"))
  212.         end
  213.         when 20378.chat."Înscrie-te în Turneul PvP" with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 1 begin
  214.             say_title(mob_name(20378)..":")
  215.             say("")
  216.             if game.get_event_flag("pvp_tournament") == pc.getqf("pvp_tournament") then
  217.                 say("Eşti deja înscris în Turneul PvP.")
  218.                 say("")
  219.                 return
  220.             end
  221.             if pc.get_level() < 15 then
  222.                 say("Nivelul tău este prea mic.")
  223.                 say("")
  224.                 return
  225.             end
  226.             if pc.get_level() < game.get_event_flag("pvp_minlevel") or pc.get_level() > game.get_event_flag("pvp_maxlevel") then
  227.                 say("Nivelul tău trebuie să fie între "..game.get_event_flag("pvp_minlevel").." şi "..game.get_event_flag("pvp_maxlevel"))
  228.                 say("")
  229.                 return
  230.             end
  231.             ----"123456789012345678901234567890123456789012345678901234567890"|
  232.  
  233.             say("Bun venit la Dojan. În acest turneu vei lupta")
  234.             say("împotriva jucătorilor de nivele similare cu al tău")
  235.             say("")
  236.             say("Înfrânge fiecare inamic şi intră în istoria")
  237.             say("Ţinutului Mistic.")
  238.             say("")
  239.             say("Doreşti să te înscrii în Turneul PvP?")
  240.             say("")
  241.             local s = select("Doresc să particip", "N-am nici o şansă ")
  242.             say_title(mob_name(20378)..":")
  243.             say("")
  244.             if s == 1 then
  245.                 say("Vei fi chemat atunci când va veni rândul tău, dar")
  246.                 say("trebuie să stai aici, altfel vei fi descalificat.")
  247.                 say("")
  248.                 say("Mult succes !")
  249.                 say("")
  250.                
  251.                 pvp_attenders[attender_count+1] = {name = pc.getname(), level = pc.get_level(), partner = nil, winner = true, fight_mode = 0, arena = 0}
  252.                 pc.setqf("attender_id", attender_count+1)
  253.                 pc.setqf("pvp_tournament", game.get_event_flag("pvp_tournament"))
  254.                 attender_count = attender_count + 1
  255.             elseif s == 2 then
  256.                 say("Întradevăr, pari foarte slab..")
  257.                 say("Unii şi-au pierdut viaţa în acest turneu.")
  258.                 say("")
  259.             end
  260.         end
  261.         when 20378.chat."Înscrierile pentru Turneul PvP" with pc.get_map_index() == 115 and pc.is_gm() and game.get_event_flag("pvp") == 1 begin
  262.             say_title("Turneul PvP")
  263.             say("Momentan sunt înscrişi "..tostring(attender_count).." de jucători.")
  264.             say("Ar trebui închise înscrierile şi pornite")
  265.             say("pariurile?")
  266.             say("")
  267.             local s = select("Închide înscrierile", "Continuă cu înscrierile")
  268.             if s == 1 then
  269.                 say_title("Închide înscrierile:")
  270.                 say("Înscrierile au fost închise.")
  271.                 say("Jucătorii pot paria acum.")
  272.                 say("")
  273.                 game.set_event_flag("pvp", 2)
  274.                 betting_list = {}
  275.                 betting_state = {}
  276.             end
  277.         end
  278.        
  279.         when 20378.chat."Pariază pentru Turneul PvP" with pc.get_map_index() == 115 and pc.is_gm() and game.get_event_flag("pvp") == 2 begin
  280.             say_title("Turneul PvP")
  281.             say("Ar trebui oprite pariurile şi pornit Turneul PvP?")
  282.             say("")
  283.             local s = select("Porneşte Turneul PvP acum", "Continuă cu pariurile")
  284.             if s == 1 then
  285.                 say_title("Opreşte Pariurile:")
  286.                 say("Timpul pentru pariuri s-a terminat.")
  287.                 say("Duelele vor începe acum.")
  288.                 say("")
  289.                 game.set_event_flag("pvp", 3)
  290.                 pvp_manager.make_duel_list()
  291.                 duel_list_index = 0
  292.                 playerless_mode = false
  293.                 notice_all("Înscrierile pentru Turneul PvP au fost închise. Duelele vor începe acum !")
  294.                 pvp_round_num = 1
  295.                 pvp_manager.refresh_arenas()
  296.             end
  297.         end
  298.        
  299.         when 20378.chat."Plasează un Pariu" with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 2 and betting_state != nil and betting_state[pc.get_player_id()] == nil begin
  300.             say_title("Plasează un Pariu:")
  301.             say("Pe ce jucător doreşti să pariezi?")
  302.             say("")
  303.             local player = input()
  304.             say_title("Plasează un Pariu:")
  305.             say("")
  306.             if pvp_manager.get_attender_id_by_name(player) == 0 then
  307.                 say("Acest jucător nu este înscris.")
  308.                 say("")
  309.                 return
  310.             end
  311.             say("Câţi bani doreşti să pariezi?")
  312.             say("")
  313.             local bet_amount = tonumber(input())
  314.             if bet_amount < 1 then
  315.                 say_title("Eroare:")
  316.                 say("Aceasta nu este o valoare validă.")
  317.                 say("")
  318.                 return
  319.             end
  320.             say_title("Confirmă:")
  321.             say("Doreşti să pariezi "..bet_amount.." Yang pe")
  322.             say(player.."?")
  323.             say("")
  324.             if select("Da", "Nu") == 2 then
  325.                 return
  326.             end
  327.            
  328.             if pc.gold < bet_amount then
  329.                 say_title("Eroare:")
  330.                 say("Nu ai destui bani.")
  331.                 say("")
  332.                 return
  333.             end
  334.            
  335.             betting_state[pc.get_player_id()] = 1
  336.             table.insert(betting_list, {pc.get_name(), bet_amount, player})
  337.             pc.change_gold(-bet_amount)
  338.            
  339.             say_title("Plasează un Pariu:")
  340.             say("Pariul a fost plasat.")
  341.             say("Mulţumim şi mult succes !")
  342.             say("")
  343.         end
  344.        
  345.         when 20378.chat."Cine participă?" with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 2 begin
  346.             setskin(NOWINDOW)
  347.             chat("Următoarele persoane participă în Turneul PvP:")
  348.             for i = 1, attender_count, 4 do
  349.                 local chatline = ""
  350.                 for j = i, i + 4, 1 do
  351.                     if pvp_attenders[j] != nil then
  352.                         chatline = chatline..pvp_attenders[j].name.."   "
  353.                     end
  354.                 end
  355.                 syschat(chatline)
  356.             end
  357.             syschat("Total "..attender_count.." participanţi")
  358.         end
  359.        
  360.         when 20378.chat."Cu cine voi lupta în continuare?" with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 3 and game.get_event_flag("pvp_tournament") == pc.getqf("pvp_tournament") begin
  361.             say_title(mob_name(20378)..":")
  362.             say("")
  363.             if pvp_manager.get_duel_partner() == nil then
  364.                 say("Nu există nici un oponent disponibil momentan.")
  365.                 say("")
  366.                 say("Dacă nu găsim pe nimeni disponibil vei merge în")
  367.                 say("următoarea rundă în mod automat.")
  368.                 say("")
  369.                 return
  370.             end
  371.             say("Conform planului curent te vei duela cu:")
  372.             say("")
  373.             say_reward(""..pvp_manager.get_duel_partner().."")
  374.             say("")
  375.         end
  376.        
  377.  
  378.         function make_duel_list()
  379.             duel_list = { }
  380.             local i = 0
  381.             for ai = 1, attender_count, 1 do
  382.                 if pvp_attenders[ai] != nil and pvp_attenders[ai].partner == nil and pvp_attenders[ai].winner == true then
  383.                     local partner_id = pvp_manager.findpartner(tostring(pvp_attenders[ai].name), pvp_attenders[ai].level)
  384.                     if partner_id != nil then
  385.                         pvp_attenders[ai].partner = tostring(pvp_attenders[partner_id].name)
  386.                         pvp_attenders[partner_id].partner = tostring(pvp_attenders[ai].name)
  387.                         duel_list[i] = {fighter_id1 = ai, fighter_id2 = partner_id}
  388.                         i = i + 1
  389.                     end
  390.                 end
  391.             end
  392.            
  393.             for ai = 1, attender_count, 1 do
  394.                 if pvp_attenders[ai] != nil and pvp_attenders[ai].partner == nil and pvp_attenders[ai].winner == true then
  395.                     local partner_id = pvp_manager.findpartner_for_partnerless(tostring(pvp_attenders[ai].name), pvp_attenders[ai].level)
  396.                     if partner_id != nil then
  397.                         pvp_attenders[ai].partner = tostring(pvp_attenders[partner_id].name)
  398.                         pvp_attenders[partner_id].partner = tostring(pvp_attenders[ai].name)
  399.                         duel_list[i] = {fighter_id1 = ai, fighter_id2 = partner_id}
  400.                         i = i + 1
  401.                     end
  402.                 end
  403.             end
  404.         end
  405.        
  406.        
  407.         function findpartner(name, level)
  408.             local closest_level = nil
  409.             local partner_id = nil
  410.             for ai = 1, attender_count, 1 do
  411.                 if pvp_attenders[ai] != nil and pvp_attenders[ai].winner == true and tonumber(pvp_attenders[ai].level) <= level + 30 and tonumber(pvp_attenders[ai].level) >= level - 30 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
  412.                     if closest_level == nil then
  413.                         closest_level = pvp_attenders[ai].level
  414.                         partner_id = ai
  415.                     elseif tonumber(pvp_attenders[ai].level) == tonumber(level) then
  416.                         closest_level = pvp_attenders[ai].level
  417.                         partner_id = ai
  418.                     elseif tonumber(level) < tonumber(closest_level) and tonumber(pvp_attenders[ai].level) < tonumber(closest_level) then
  419.                         closest_level = pvp_attenders[ai].level
  420.                         partner_id = ai
  421.                     elseif tonumber(level) > tonumber(closest_level) and tonumber(pvp_attenders[ai].level) > tonumber(closest_level) then
  422.                         closest_level = pvp_attenders[ai].level
  423.                         partner_id = ai
  424.                     end
  425.                 end
  426.             end
  427.             return tonumber(partner_id)
  428.         end
  429.        
  430.         function findpartner_for_partnerless(name, level)
  431.             local closest_level = nil
  432.             local partner_id = nil
  433.             for ai = 1, attender_count, 1 do
  434.                 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
  435.                     if closest_level == nil then
  436.                         closest_level = pvp_attenders[ai].level
  437.                         partner_id = ai
  438.                     elseif pvp_attenders[ai].level == level then
  439.                         closest_level = pvp_attenders[ai].level
  440.                         partner_id = ai
  441.                     elseif tonumber(level) < tonumber(closest_level) and pvp_attenders[ai].level < closest_level then
  442.                         closest_level = pvp_attenders[ai].level
  443.                         partner_id = ai
  444.                     elseif tonumber(level) > tonumber(closest_level) and pvp_attenders[ai].level > closest_level then
  445.                         closest_level = pvp_attenders[ai].level
  446.                         partner_id = ai
  447.                     end
  448.                 end
  449.             end
  450.             return partner_id
  451.         end
  452.        
  453.         function is_player_in_map(name)
  454.             if pc.getname() == name then
  455.                 return true
  456.             end
  457.             local myname = pc.getname()
  458.             local target = find_pc_by_name(name)
  459.             local t = pc.select(target)
  460.             if pc.getname() == myname then
  461.                 pc.select(t)
  462.                 return false
  463.             end
  464.             pc.select(t)
  465.             return true
  466.         end
  467.        
  468.        
  469.         when 20378.chat."GM: Actualizează şi Curăţă Arena" with pc.is_gm() and game.get_event_flag("pvp") == 3 begin
  470.             for aArena = 1, 4, 1 do
  471.                 arena[aArena][3] = 0
  472.                 arena[aArena][4] = "SLEEPING"
  473.             end
  474.             pvp_manager.refresh_arenas()
  475.         end
  476.        
  477.         -- not working
  478.         --[[
  479.         when 20378.chat."GM: Opreşte Lupta" with pc.is_gm() and game.get_event_flag("pvp") == 2 begin
  480.             say_title("Opreşte Lupta:")
  481.             say("În care arenă ar trebui sfârşită lupta?")
  482.             local s = select("Arena 1", "Arena 2", "Arena 3", "Arena 4", "Închide")
  483.            
  484.             if s == 5 then
  485.                 return
  486.             end
  487.            
  488.             local fighter1 = nil
  489.             local fighter2 = nil
  490.             for ai = 1, attender_count, 1 do
  491.                 if pvp_attenders[ai].arena == s and pvp_attenders[ai].fight_mode != 0 then
  492.                     if fighter1 == nil then
  493.                         fighter1 = ai
  494.                     else
  495.                         fighter2 = ai
  496.                     end
  497.                 end
  498.             end
  499.            
  500.             if fighter1 == nil then
  501.                 say_title("Sfârşeşte lupta:")
  502.                 say("Nu există nici un duel în arena respectivă în")
  503.                 say("acest moment.")
  504.                 say("")
  505.                 return
  506.             end
  507.            
  508.             say_title("Sfârşeşte Lupta:")
  509.             say("Cine ar trebui considerat câştigător când lupta în arena "..s.." ")
  510.             say("va fi încheiată?")
  511.             local w = select(tostring(pvp_attenders[fighter1].name), tostring(pvp_attenders[fighter1].name), "Închide")
  512.             if w == 3 then
  513.                 return
  514.             end
  515.            
  516.             if w == 1 then
  517.                 pvp_attenders[fighter2].winner = false
  518.                 notice_in_map(tostring(pvp_attenders[fighter1].name).." has won the battle against "..tostring(pvp_attenders[fighter2].name).."!", pc.get_map_index())
  519.                 pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter1].name, 126, 234))
  520.                 pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter2].name, 126, 24))
  521.             else
  522.                 pvp_attenders[fighter1].winner = false
  523.                 notice_in_map(tostring(pvp_attenders[fighter2].name).." has won the battle against "..tostring(pvp_attenders[fighter1].name).."!", pc.get_map_index())
  524.                 pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter1].name, 126, 24))
  525.                 pvp_manager.local_pc_warp(tostring(pvp_attenders[fighter2].name, 126, 234))
  526.             end
  527.            
  528.             pvp_attenders[fighter1].fight_mode = 0
  529.             pvp_attenders[fighter2].fight_mode = 0
  530.            
  531.            
  532.             arena[s][3] = 0
  533.             pvp_manager.refresh_arenas()
  534.            
  535.             say_title("Sfârşeşte duelul:")
  536.             say("Duelul a luat sfârţit.")
  537.         end
  538.         --]]
  539.        
  540.         when 20378.chat."GM: Recompensă Turneu PvP" with pc.is_gm() begin
  541.             say_title("Recompensă:")
  542.             say("Recompensă curentă: "..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")..")")
  543.             say("")
  544.             local s = select("Schimbă recompensa", "Închide")
  545.             if s == 2 then
  546.                 return
  547.             end
  548.             say_title("Schimbă Recompensa:")
  549.             say("Te rog introdu codul noii recompense:")
  550.             say("")
  551.             local vnum = input()
  552.             say_title("Schimbă recompensa:")
  553.             say("Te rog introdu cantitatea noii recompense:")
  554.             say("")
  555.             local count = input()
  556.             game.set_event_flag("pvp_price_count", count)
  557.             game.set_event_flag("pvp_price_vnum", vnum)
  558.             say_title("Schimbă Recompensa:")
  559.             say("Recompensa a fost schimbată.")
  560.             say("Noua recompensă: "..count.."x "..item_name(vnum).." (vnum: "..vnum..")")
  561.             say("")
  562.         end
  563.  
  564.         when 20378.chat."GM: Yang/Rundă Turneu PvP" with pc.is_gm() begin
  565.             say_title("Recompensă-Yang-Rundă:")
  566.             say("Suma curentă: "..game.get_event_flag("pvp_round_gold"))
  567.             say("")
  568.             local s = select("Schimbă ", "Închide")
  569.             if s == 2 then
  570.                 return
  571.             end
  572.             say_title("Schimbă Suma:")
  573.             say("Te rugăm să introduci suma de yang primită pentru")
  574.             say("câştigătorul unei runde:")
  575.             say("")
  576.             local gold = input()
  577.             game.set_event_flag("pvp_round_gold", gold)
  578.             say_title("Schimbă Suma:")
  579.             say("Yang-ul primit a fost schimbat.")
  580.             say("Yang actual pe rundă: "..gold)
  581.             say("")
  582.         end
  583.        
  584.         function refresh_arenas()
  585.             for aArena = 1, 4, 1 do
  586.                 if duel_list[duel_list_index] == nil then
  587.                     if playerless_mode == true then
  588.                         pvp_manager.init_next_round()
  589.                     else
  590.                         pvp_manager.fight_playerless()
  591.                     end
  592.                     return
  593.                 end
  594.                 if arena[aArena][3] == 0 then
  595.                     arena[aArena][3] = 1
  596.                     pvp_manager.fight_init(duel_list[duel_list_index].fighter_id1, duel_list[duel_list_index].fighter_id2, aArena)
  597.                 end
  598.             end
  599.         end
  600.        
  601.  
  602.         function fight_init(pid1, pid2, arena_id)
  603.             duel_list_index = duel_list_index + 1
  604.             if pvp_manager.is_player_in_map(tostring(pvp_attenders[pid1].name)) == false then
  605.                 notice_in_map(tostring(pvp_attenders[pid1].name).." nu este online, prin urmare va fi descalificat/ă.", pc.get_map_index())
  606.                 pvp_attenders[pid1].winner = false
  607.                 pvp_attenders[pid2].partner = nil
  608.                 arena[arena_id][3] = 0
  609.                 pvp_manager.refresh_arenas()
  610.                 return
  611.             end
  612.             if pvp_manager.is_player_in_map(tostring(pvp_attenders[pid2].name)) == false then
  613.                 notice_in_map(tostring(pvp_attenders[pid2].name).." nu este online, prin urmare va fi descalificat/ă.", pc.get_map_index())
  614.                 pvp_attenders[pid2].winner = false
  615.                 pvp_attenders[pid1].partner = nil
  616.                 arena[arena_id][3] = 0
  617.                 pvp_manager.refresh_arenas()
  618.                 return
  619.             end
  620.            
  621.             notice_in_map(tostring(pvp_attenders[pid1].name).." şi "..tostring(pvp_attenders[pid2].name).." vă rugăm să intraţi în ring!", pc.get_map_index())
  622.            
  623.             --[[
  624.             local f1_accept = ask_fight(tostring(pvp_attenders[pid1].name), tostring(pvp_attenders[pid2].name))
  625.             if f1_accept != CONFIRM_OK then
  626.                 notice_in_map(tostring(pvp_attenders[pid1].name).." nu a acceptat duelul împotriva lui "..tostring(pvp_attenders[pid2].name)..".", pc.get_map_index())
  627.                 pvp_attenders[pid1] = nil
  628.                 pvp_attenders[pid2].partner = nil
  629.                 pvp_manager.refresh_arenas()
  630.                 return
  631.             end
  632.            
  633.             local f2_accept = confirm(find_pc_by_name(tostring(pvp_attenders[pid2].name)), "Vei lupta împotriva lui "..tostring(pvp_attenders[pid1].name).. " ?", 15)
  634.             if f2_accept != CONFIRM_OK then
  635.                 notice_in_map(tostring(pvp_attenders[pid2].name).." nu a acceptat duelul împotriva lui "..tostring(pvp_attenders[pid1].name)..".", pc.get_map_index())
  636.                 pvp_attenders[pid2] = nil
  637.                 pvp_attenders[pid1].partner = nil
  638.                 pvp_manager.refresh_arenas()
  639.                 return
  640.             end
  641.             ]]
  642.            
  643.             pvp_attenders[pid1].fight_mode = 1
  644.             pvp_attenders[pid2].fight_mode = 1
  645.             pvp_attenders[pid1].arena = arena_id
  646.             pvp_attenders[pid2].arena = arena_id
  647.            
  648.             pvp_manager.local_pc_warp(tostring(pvp_attenders[pid1].name), arena[arena_id][1][1], arena[arena_id][1][2])
  649.             pvp_manager.local_pc_warp(tostring(pvp_attenders[pid2].name), arena[arena_id][2][1], arena[arena_id][2][2])
  650.  
  651.         end
  652.        
  653.         when login with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 3 and pvp_manager.get_fight_mode() == 1 begin
  654.             affect.add(apply.MOV_SPEED, -10000, 2)
  655.             affect.add_collect(apply.HP_REGEN, 5000, 30)
  656.             affect.add_collect(apply.SP_REGEN, 5000, 30)
  657.             pvp_manager.set_fight_mode(2)
  658.             if arena[pvp_manager.get_arena()][3] == 2 then
  659.                 arena[pvp_manager.get_arena()][5] = 30
  660.                 loop_timer("fight_start_countdown", 1)
  661.             else
  662.                 timer("partner_timeout", 60)
  663.             end
  664.             arena[pvp_manager.get_arena()][3] = 2
  665.         end    
  666.        
  667.         when partner_timeout.timer begin
  668.             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
  669.                 return
  670.             end
  671.             pvp_manager.set_fight_mode(3)
  672.             if arena[pvp_manager.get_arena()][3] == 3 then
  673.                 return
  674.             end
  675.             arena[pvp_manager.get_arena()][3] = 3
  676.             notice_in_map(pc.getname().." a câştigat împotriva lui "..pvp_manager.get_duel_partner().." prin abandon !", pc.get_map_index())
  677.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
  678.             pvp_attenders[pvp_manager.get_my_attender_id()].winner = true
  679.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = false
  680.             pc.warp_local(pc.get_map_index(), 12600, 23400)
  681.         end
  682.  
  683.         when fight_start_countdown.timer begin
  684.             if arena[pvp_manager.get_arena()][5] == -1 then
  685.                 return
  686.             end
  687.             local partner_vid = find_pc_by_name(pvp_manager.get_duel_partner())
  688.             local my_vid = pc.get_vid()
  689.             if arena[pvp_manager.get_arena()][5] == 0 then
  690.                 arena[pvp_manager.get_arena()][5] = -1
  691.                 pc.select(partner_vid)
  692.                 command("pvp "..my_vid)
  693.                 pc.select(my_vid)
  694.                 command("pvp "..partner_vid)
  695.                 notice_in_map("Duelul dintre "..pvp_manager.get_duel_partner().." şi "..pc.get_name().." începe !", pc.get_map_index())
  696.                 timer("fight_start_countdown_shutdown", 1)
  697.             else
  698.                 pc.select(partner_vid)
  699.                 if math.mod(arena[pvp_manager.get_arena()][5], 5) == 0 then
  700.                     syschat("Duelul începe în "..tostring(arena[pvp_manager.get_arena()][5]).." secunde.")
  701.                 end
  702.                 affect.add(apply.MOV_SPEED, -10000, 2)
  703.                 pc.select(my_vid)
  704.                 if math.mod(arena[pvp_manager.get_arena()][5], 5) == 0 then
  705.                     syschat("Duelul începe în "..tostring(arena[pvp_manager.get_arena()][5]).." secunde.")
  706.                 end
  707.                 affect.add(apply.MOV_SPEED, -10000, 2)
  708.                 arena[pvp_manager.get_arena()][5] = arena[pvp_manager.get_arena()][5] - 1
  709.             end
  710.         end
  711.        
  712.         when fight_start_countdown_shutdown.timer begin
  713.             cleartimer("fight_start_countdown")
  714.         end
  715.        
  716.         when logout with game.get_event_flag("pvp") == 3 and pc.get_map_index() == 115 and pvp_manager.get_fight_mode() == 2 begin
  717.             pvp_manager.set_fight_mode(3)
  718.             arena[pvp_manager.get_arena()][3] = 3
  719.             notice_in_map(pvp_manager.get_duel_partner().." a câştigat împotriva lui "..pc.getname().."!", pc.get_map_index())
  720.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
  721.             pvp_attenders[pvp_manager.get_my_attender_id()].winner = false
  722.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = true
  723.            
  724.             local target = find_pc_by_name(pvp_manager.get_duel_partner())
  725.             local t = pc.select(target)
  726.             pc.change_gold(game.get_event_flag("pvp_round_gold")*pvp_round_num)
  727.             pc.select(t)
  728.            
  729.             pvp_manager.local_pc_warp(pvp_manager.get_duel_partner(), 126, 24)
  730.         end
  731.        
  732.         when kill with game.get_event_flag("pvp") == 3 and pc.get_map_index() == 115 and npc.is_pc() and pvp_manager.get_fight_mode() == 2 begin
  733.             pvp_manager.set_fight_mode(3)
  734.             if arena[pvp_manager.get_arena()][3] == 3 then
  735.                 return
  736.             end
  737.             arena[pvp_manager.get_arena()][3] = 3
  738.             notice_in_map(pc.getname().." a câştigat împotriva lui "..pvp_manager.get_duel_partner().."!", pc.get_map_index())
  739.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].fight_mode = 3
  740.             pvp_attenders[pvp_manager.get_my_attender_id()].winner = true
  741.             pvp_attenders[pvp_manager.get_attender_id_by_name(pvp_manager.get_duel_partner())].winner = false
  742.            
  743.             pc.change_gold(game.get_event_flag("pvp_round_gold")*pvp_round_num)
  744.            
  745.             timer("fight_end", 5)
  746.         end
  747.        
  748.         when fight_end.timer begin
  749.             pc.warp_local(pc.get_map_index(), 12600, 23400)
  750.             pvp_manager.local_pc_warp(pvp_manager.get_duel_partner(), 126, 24)
  751.         end
  752.        
  753.         when letter with pc.get_map_index() == 115 and game.get_event_flag("pvp") == 3 and pvp_manager.get_fight_mode() == 3 begin
  754.             pvp_manager.set_fight_mode(0)
  755.            
  756.             if pvp_attenders[pvp_manager.get_my_attender_id()].winner == true then
  757.                 arena[pvp_manager.get_arena()][3] = 0
  758.                 pvp_manager.refresh_arenas()
  759.             end
  760.         end
  761.        
  762.         when login with pc.get_map_index() == 115 or pc.get_map_index() == 114 or pc.get_map_index() == 121 or pc.get_map_index() == 125 or pc.get_map_index() == 110 or pc.get_map_index() == 111 begin
  763.             loop_timer("horse_block",1)
  764.         end
  765.        
  766.         when horse_block.timer begin
  767.        
  768.             if horse.is_riding() then
  769.            
  770.                 pc.unmount()
  771.                 horse.unsummon()
  772.                 syschat("Nu poţi folosi calul aici !")
  773.                
  774.             end
  775.         end
  776.        
  777.         function fight_playerless()
  778.             for aArena = 1, 4, 1 do
  779.                 if arena[aArena][3] != 0 then
  780.                     return
  781.                 end
  782.             end
  783.             playerless_mode = true
  784.  
  785.            
  786.             pvp_manager.make_duel_list()
  787.             pvp_manager.refresh_arenas()
  788.         end
  789.        
  790.         function init_next_round()
  791.             for aArena = 1, 4, 1 do
  792.                 if arena[aArena][3] != 0 then
  793.                     return
  794.                 end
  795.             end
  796.             playerless_mode = false
  797.            
  798.             local winner_count = 0
  799.             local winner_id = 0
  800.             for ai = 1, attender_count, 1 do
  801.                 pvp_attenders[ai].partner = nil
  802.                 pvp_attenders[ai].fight_mode = 0
  803.                 if pvp_attenders[ai] != nil and pvp_attenders[ai].winner == true then
  804.                     winner_count = winner_count + 1
  805.                     winner_id = ai
  806.                 end
  807.             end
  808.            
  809.             if winner_count == 1 then
  810.                 notice_all(pvp_attenders[winner_id].name.." a câştigat Turneul PvP ! Avem o nouă legendă în Ţinutul Mistic !")
  811.                 notice_all(pvp_attenders[winner_id].name.." primeşte "..game.get_event_flag("pvp_price_count").."x "..item_name(game.get_event_flag("pvp_price_vnum")).." ca şi recompensă !")
  812.                
  813.                 pvp_manager.distribute_bets(pvp_attenders[winner_id].name)
  814.                
  815.                 local target = find_pc_by_name(pvp_attenders[winner_id].name)
  816.                 local t = pc.select(target)
  817.                 pc.give_item2(game.get_event_flag("pvp_price_vnum"), game.get_event_flag("pvp_price_count"))
  818.                 pc.select(t)
  819.                 notice_all("Turneul PvP a luat sfârşit. Vă aşteptăm la următorul Turneu !")
  820.                 game.set_event_flag("pvp", 0)
  821.                 pvp_attenders = nil
  822.                 return
  823.             end
  824.            
  825.            
  826.             pvp_manager.make_duel_list()
  827.             duel_list_index = 0
  828.             if winner_count == 2 then
  829.                 notice_all("Runda finală a Turnelului PvP începe acum !")
  830.             elseif winner_count <= 4 then
  831.                 notice_all("Runda semi-finală a Turnelului PvP începe acum !")
  832.             else
  833.                 notice_all("Următoarea rundă a Turneului PvP începe acum !")
  834.             end
  835.             pvp_round_num = pvp_round_num + 1
  836.             pvp_manager.refresh_arenas()
  837.         end
  838.        
  839.         function distribute_bets(winner_name)
  840.             --table.insert(betting_list, {pc.get_name(), bet_amount, player})
  841.             local jackpot = 0
  842.             local jackpot_winner_only = 0
  843.             local winners = 0
  844.             for i = 1, table.getn(betting_list), 1 do
  845.                 if betting_list[i][3] == winner_name then
  846.                     jackpot_winner_only = jackpot_winner_only + betting_list[i][2]
  847.                 end
  848.                 jackpot = jackpot + betting_list[i][2]
  849.                 winners = winners + 1
  850.             end
  851.            
  852.             for i = 1, table.getn(betting_list), 1 do
  853.                 if betting_list[i][3] == winner_name then
  854.                     pvp_manager.give_jackpot_gold(betting_list[i][1], math.ceil( (betting_list[i][2] / jackpot_winner_only)*jackpot ))
  855.                 end
  856.             end
  857.            
  858.         end
  859.        
  860.         function give_jackpot_gold(name, amount)
  861.             local target = find_pc_by_name(name)
  862.             if target == 0 then
  863.                 return
  864.             end
  865.             local t = pc.select(target)
  866.             pc.change_money(amount)
  867.             pc.select(t)
  868.         end
  869.        
  870.         function local_pc_warp(name, x, y)
  871.             local target = find_pc_by_name(name)
  872.             local t = pc.select(target)
  873.             pc.warp_local(pc.get_map_index(), x*100, y*100)
  874.             pc.select(t)
  875.         end
  876.        
  877.         function setqf_by_name(name, flag, value)
  878.             local target = find_pc_by_name(name)
  879.             local t = pc.select(target)
  880.             pc.setqf(flag, value)
  881.             pc.select(t)
  882.         end
  883.        
  884.         function getqf_by_name(name, flag)
  885.             local target = find_pc_by_name(name)
  886.             local t = pc.select(target)
  887.             local rflag = pc.getqf(flag)
  888.             pc.select(t)
  889.             return rflag
  890.         end
  891.        
  892.         function get_attender_id_by_name(name)
  893.             for ai = 1, attender_count, 1 do
  894.                 if tostring(pvp_attenders[ai].name) == name then
  895.                     return ai
  896.                 end
  897.             end
  898.             return 0
  899.         end
  900.        
  901.         function get_my_attender_id()
  902.             return pvp_manager.get_attender_id_by_name(pc.get_name())
  903.         end
  904.        
  905.         function get_duel_partner()
  906.             if pvp_attenders[pvp_manager.get_my_attender_id()] != nil and pvp_attenders[pvp_manager.get_my_attender_id()].partner != nil then
  907.                 return pvp_attenders[pvp_manager.get_my_attender_id()].partner
  908.             else
  909.                 return nil
  910.             end
  911.         end
  912.        
  913.         function get_fight_mode()
  914.             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
  915.                 return pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode
  916.             else
  917.                 return 0
  918.             end
  919.         end
  920.        
  921.         function set_fight_mode(fmode)
  922.             pvp_attenders[pvp_manager.get_my_attender_id()].fight_mode = fmode
  923.         end
  924.        
  925.         function get_arena()
  926.             return pvp_attenders[pvp_manager.get_my_attender_id()].arena
  927.         end
  928.        
  929.         function set_arena(id)
  930.             pvp_attenders[pvp_manager.get_my_attender_id()].arena = id
  931.         end
  932.        
  933.         function ask_fight(asker, target)
  934.             return confirm(find_pc_by_name(target), "Vei lupta împotriva lui "..asker.. "?", 15)
  935.         end
  936.     end
  937. end
Add Comment
Please, Sign In to add comment