I'm here to present my work currently under development, is an automated tournament up to 64 players using the arena as battle field
at moment I was able to test the operation for 4 player having good results, certainly the quest still has many shortcomings to be corrected but I do not have the possibility to test with 8+ players, I kindly ask if someone can look for bugs and report them . the final quest will be publicly released for all users
particularly now I'm interested the advancement of the tournament stages
for the proper functioning must be created manually the directory "torneo" and maps 1,3,21,23,41,43,112 there are started in same core
I am sorry if my English is not proper
### torneo_lib.lua ###
Code:
TORNEO_READ = 0 TORNEO_PLUS = 1 TORNEO_NEW = 3 TORNEO_NEXT = 4 TORNEO_MEMBER = 1 TORNEO_REGISTRED = 2 TORNEO_START = 3 TORNEO_FINISH = 4 TORNEO_STAGE = 5 TORNEO_ROUND = 6 function torneo_open_regi() local TORNEO_PATH = "locale/italy/quest/object/torneo/" local TORNEO_FILE = "torneo_stage_*" os.execute("cd "..TORNEO_PATH.." && rm -rf "..TORNEO_FILE) game.set_event_flag("torneo_close", 0) end function torneo_round(number) local stage = { 8,16,24,32,40,48,56,64 } local x = 1 while true do if stage[x] == nil then break end if number <= stage[x] then return x end x = x + 1 end end function torneo_tool(linea, stage, round, modo) local TORNEO_PATH = "locale/italy/quest/object/torneo/" local TORNEO_FILE = "torneo_stage_"..stage.."_round_"..round..".txt" local x = 1 local file local newRound local result if modo == 0 then file = io.open(TORNEO_PATH..TORNEO_FILE, "r") while true do local line = file:read("*l") if line == nil then break end local text = string.gsub(line, "\n", "") if x == linea then io.close(file) return text end x = x + 1 end io.close(file) elseif modo == 1 then file = io.open(TORNEO_PATH..TORNEO_FILE, "a+") file:write(linea.."\n") io.close(file) elseif modo == 2 then if round <= 2 then newRound = 1 elseif round <= 4 then newRound = 2 elseif round <= 6 then newRound = 3 elseif round <= 8 then newRound = 4 end local TORNEO_NEWFILE = "torneo_stage_"..stage.."_round_"..newRound..".txt" file = io.open(TORNEO_PATH..TORNEO_NEWFILE, "a+") file:write(linea.."\n") io.close(file) return newRound end end function torneo_data(linea, modo) local TORNEO_PATH = "locale/italy/quest/object/torneo/" local TORNEO_FILE = "torneo.txt" local x = 1 local file = "" if modo == TORNEO_READ then file = io.open(TORNEO_PATH..TORNEO_FILE, "r") while true do local line = file:read("*l") if line == nil then break end local text = string.gsub(line, "\n", "") if x == linea then io.close(file) return text end x = x + 1 end io.close(file) elseif modo == TORNEO_PLUS then local linee = {} local x = 1 local y = 1 file = io.open(TORNEO_PATH..TORNEO_FILE, "r") while true do linee[x] = file:read("*l") if linee[x] == nil then break end x = x + 1 end io.close(file) os.rename(TORNEO_PATH..TORNEO_FILE, TORNEO_PATH..TORNEO_FILE..".BAK") local update = io.open(TORNEO_PATH..TORNEO_FILE, "a+") while true do if linee[y] == nil then break end if y == linea then local newPoint = tonumber(linee[y]) + 1 update:write(newPoint.."\n") else update:write(linee[y].."\n") end io.flush() y = y + 1 end io.close(update) elseif modo == TORNEO_NEXT then local linee = {} local x = 1 local y = 1 file = io.open(TORNEO_PATH..TORNEO_FILE, "r") while true do linee[x] = file:read("*l") if linee[x] == nil then break end x = x + 1 end io.close(file) local newMember = tonumber(linee[1])/2 local newFinish = 0 local newStage = tonumber(linee[5])+1 local newRound = 1 local newStart = tonumber(linee[3])+1 local update = io.open(TORNEO_PATH..TORNEO_FILE, "w+") update:write(newMember.."\n"..linee[2].."\n"..newStart.."\n"..newFinish.."\n"..newStage.."\n"..newRound.."\n") io.close(update) elseif modo == TORNEO_NEW then file = io.open(TORNEO_PATH..TORNEO_FILE, "w+") file:write(linea.."\n0\n0\n0\n1\n1\n") io.close(file) end end function torneo_opp(posizione, stage, round) local member = {} local x = 1 local sfidanti = tonumber(torneo_member(stage, round))/2 while true do member[x] = torneo_tool(x, stage, round, 0) if member[x] == nil then break end x = x + 1 end local opps = sfidanti + posizione local chll = posizione - sfidanti if posizione <= sfidanti then return member[opps] else return member[chll] end end function torneo_member(stage, round) local TORNEO_PATH = "locale/italy/quest/object/torneo/" local TORNEO_FILE = "torneo_stage_"..stage.."_round_"..round..".txt" local x = 1 local file = io.open(TORNEO_PATH..TORNEO_FILE, "r") while true do local line = file:read("*l") if line == nil then break end x = x + 1 end io.close(file) local result = x - 1 return result end function torneo_number(name, stage, round) local player = {} local x = 1 while true do player[x] = torneo_tool(x, stage, round, 0) if player[x] == name then break end x = x + 1 end return x end
Code:
quest torneo_pvp begin state start begin when 20094.chat."Gestione torneo" with pc.is_gm() begin say_title("Gestore torneo:") say("") say("Benvenuto Game Master") say("cosa posso fare per te?") say("") local a = select("Attiva torneo","Disattiva torneo","Chiudi") if a == 3 then return elseif a == 1 then say_title("Gestore torneo:") say("") say("Inserire il livello minimo") local minLevel = tonumber(input()) game.set_event_flag("torneo_minLvl", minLevel) say_title("Gestore torneo:") say("") say("Inserire il livello massimo") local maxLevel = tonumber(input()) game.set_event_flag("torneo_maxLvl", maxLevel) say_title("Gestore torneo:") say("") say("Quanti membri ha il torneo?") local membri = { 4,8,16,32,64 } local x = select( "4","8","16","32","64" ) game.set_event_flag("torneo_membri", membri[x]) say_title("Gestore torneo:") say("") say("Torneo avviato con successo.") say("") notice_all("Torneo PvP avviato") notice_all("potete effettuare le registrazioni") torneo_open_regi() torneo_data(membri[x],3) elseif a == 2 then say_title("Gestore torneo:") say("") say("Torneo Disattivato.") say("") game.set_event_flag("torneo_close", 1) end end when 20094.chat."torneo pvp" begin local minLevel = game.get_event_flag("torneo_minLvl") local maxLevel = game.get_event_flag("torneo_maxLvl") if game.get_event_flag("torneo_close") != 0 then say_title("Torneo PvP") say("") say("Il torneo non e' attivo torna piu' tardi.") npc.unlock() return end if not npc.lock() then say_title("Torneo PvP") say("") say("Sto parlando con un altro combattente ora.") say("Riprova tra qualche istante.") return end if pc.get_level() < minLevel or pc.get_level() > maxLevel then say_title("Torneo PvP") say("") say("Il tuo livello non e' adatto a questo torneo") npc.unlock() return end if pc.getqf("torneo_registred") == 1 then say_title("Torneo PvP") say("") say("Sei già registrato a questo torneo") npc.unlock() return end local registrati = tonumber(torneo_data(2,0)) local membri = tonumber(torneo_data(1,0)) if registrati >= membri then say_title("Torneo PvP") say("") say("E' stato raggiunto il numero di partecipanti") say("massimo per il torneo torna la prossima volta") npc.unlock() return end say_title("Torneo PvP") say("") say("Benvenuto "..pc.get_name()..".") say("Seleziona la funzione:[ENTER]") local s = select("Partecipa al torneo","Assisti al torneo","Chiudi") if s == 3 then return elseif s == 1 then if registrati < membri then say_title("Torneo PvP") say("") say("Iscrizione confermata al raggiungimento") say("dei membri varranno avviati i duelli") if membri == registrati+1 then notice_all("Registrazioni chiuse a breve inizieranno gli scontri") timer("torneo_start", 10) end local player = pc.get_name() local newReg = registrati + 1 torneo_data(2,1) local number = torneo_data(2,0) local round = torneo_round(newReg) pc.setqf("torneo_stage", 1) pc.setqf("torneo_registred", 1) pc.setqf("torneo_round", round) pc.setqf("torneo_point", 0) torneo_tool(player, 1, round, 1) loop_timer("torneo_teleport", 5) npc.unlock() end elseif s == 2 then if game.get_event_flag("torneo_close") != 0 then say_title("Torneo PvP") say("") say("Il torneo non e' attivo torna piu' tardi.") npc.unlock() return end local g = arena.get_duel_list() local arena_name = {} local arena_observer = {} table.foreachi (g , function (n, p) arena_name[n] = p[1].." vs "..p[2] arena_observer[n] = {p[3], p[4], p[5]} end ) table.insert(arena_name, "Chiudi") table.insert(arena_observer, 0) local count = table.getn(g) say_title("Assisti a un duello") if count == 0 then say("Non ci sono duelli al momento.[ENTER]") return end say("Al momento ci sono: "..count.." duelli.[ENTER]") wait() say_title("Assisti a un duello") local s = select_table(arena_name) if s == table.getn(arena_name) then return end arena.add_observer(arena_observer[s][1], arena_observer[s][2], arena_observer[s][3]) end end when torneo_start.timer begin torneo_data(3,1) end when torneo_teleport.timer begin local torneo_start = tonumber(torneo_data(3,0)) local torneo_stage = tonumber(torneo_data(5,0)) local torneo_round = tonumber(torneo_data(6,0)) if torneo_start == pc.getqf("torneo_stage") and torneo_stage == pc.getqf("torneo_stage") and torneo_round == pc.getqf("torneo_round") then cleartimer("torneo_teleport") pc.setqf("torneo_registred", 0) local round = pc.getqf("torneo_round") local name = pc.get_name() local stage = pc.getqf("torneo_stage") local sfidanti = tonumber(torneo_member(stage, round))/2 if sfidanti < 1 then notice_all("Il player "..name.." ha vitno il torneo!!!") return elseif sfidanti == 1 then notice_all("Sta per iniziare lo scontro finale del torneo") end local posizione = tonumber(torneo_number(name, stage, round)) local opp = "" if posizione <= sfidanti then opp = torneo_opp(posizione, stage, round) local z = arena.start_duel(opp,3) if z != 1 then loop_timer("torneo_next", 5) else notice_all("Lo scontro "..name.." Vs. "..opp.." e' iniziato") end else opp = torneo_opp(posizione, stage, round) local opp_vid = find_pc_by_name(opp) if opp_vid == 0 then loop_timer("torneo_next", 5) else return end end else return end end when torneo_next.timer begin cleartimer("torneo_next") pc.setqf("torneo_point", 0) local name = pc.get_name() notice_all("IL Giocatore "..name.." ha superato questo turno") torneo_data(4,1) local round = pc.getqf("torneo_round") pc.setqf("torneo_stage", pc.getqf("torneo_stage")+1) local stage = pc.getqf("torneo_stage") local newRound = torneo_tool(name, stage, round, 2) pc.setqf("torneo_round", newRound) local finiti = tonumber(torneo_data(4,0)) local duelli = tonumber(torneo_data(1,0))/2 if duelli == finiti then torneo_data(0,4) elseif duelli > finiti and round > 1 then local check = round*4 if finiti == check then torneo_data(6,1) end end pc.setqf("torneo_next", 1) end when kill with pc.get_map_index() == 112 begin local torneo_stage = tonumber(torneo_data(5,0)) local torneo_round = tonumber(torneo_data(6,0)) if torneo_stage == pc.getqf("torneo_stage") and torneo_round == pc.getqf("torneo_round") then pc.setqf("torneo_point", pc.getqf("torneo_point")+1) local point = pc.getqf("torneo_point") if point == 3 then loop_timer("torneo_next", 5) end end end when login with pc.getqf("torneo_next") == 1 and pc.get_map_index() == 3 or pc.get_map_index() == 23 or pc.get_map_index() == 43 begin pc.setqf("torneo_registred", 0) pc.setqf("torneo_next", 0) loop_timer("torneo_teleport", 20) end end end
enjoy
d3m0n3