[DEVELOPMENT RELEASE]full Automatic tournament

09/19/2012 11:11 d3m0n3#1
hi,
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
### torneo_pvp.quest ###

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
09/19/2012 11:14 ƮΦвi#2
Cool, danke für das Release, werde es gleich mal einbauen.
09/19/2012 11:14 Jоe#3
Quote:
Originally Posted by d3m0n3 View Post
hi,
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.


d3m0n3
Thank you.
You could comment your functions, the next time.
That saves more time, for other ppl. to work with.
09/19/2012 11:19 d3m0n3#4
Quote:
Originally Posted by Jоe View Post
Thank you.
You could comment your functions, the next time.
That saves more time, for other ppl. to work with.
good idea certainly will be applied in future releases :)
09/19/2012 13:29 ηice#5
very Nice
09/19/2012 13:33 *~.ιηνιηĒιвℓє.~*#6
Thank you it is a really :awesome: relase
09/19/2012 14:34 .CHJonas#7
Thank you, its very usefull :D
09/19/2012 14:39 d3m0n3#8
Quote:
Originally Posted by UNoob!.>. View Post
Ne creo ventimila di sistemi come quello... Era solo per vedere in cosa consisteva il tuo lavoro da "DIO", e comunque con il tuo "BEL" sistema ci ho fatto almeno 200 euro fottendo i coglioni che tu hai fottuto in precedenza con qualche TUA invenzione della minchia. Ti ripeto, tutte le tue "MODIFICHE DA DIO" sono stupende solo da parte di chi non capisce niente, per gente come me non sono altro che CAZZATELLE! Ora puoi insinuare quel che vuoi e dire pure "Ah di tuo non sai fare niente eccetera" ma sai benissimo che č solo un metodo per non mostrare il tuo cosiddetto "ROSIC". Ciao ciao, e la prossima volta vai ad insegnare come si fa l'acqua calda su inforge, community di coglioni e sfigati. Bon voyage!
if you took the time to come up on elitepvpers for comment my post and say that i think you're Rosic and not me :D
09/19/2012 15:33 [The]Domco#9
Very nice release man :)
09/19/2012 16:32 .Rebel#10
why you have made pub was our project and now is release iven before finish all testīs and implement on the server -.-

you are great scripter but made this release ..............
09/19/2012 16:56 d3m0n3#11
Quote:
Originally Posted by .Rebel View Post
why you have made pub was our project and now is release iven before finish all testīs and implement on the server -.-

you are great scripter but made this release ..............

just because you helped me in some tests give you praise, but you can't ask for something that I developed that is not released if I want do it

you want something private? then I could ask to be paid, but this did not happen...
I develop quest only for pleasure. ;)
09/19/2012 21:06 wzy26022#12
Reward how to set up
09/19/2012 22:56 [SA]Natsuki#13
Kann mir jemand sagen was das bringt?

Danke jeder der Antwortet
09/19/2012 23:14 Pаylasici#14
Quote:
Originally Posted by Jоe View Post
Thank you.
You could comment your functions, the next time.
That saves more time, for other ppl. to work with.
He already explained it with his source code. ;)
09/19/2012 23:50 d3m0n3#15
Quote:
Originally Posted by UNoob!.>. View Post
OhOhOh, ma quindi postiamo anche il lavoro degli altri senza permesso, sei davvero cosė coglione? Boh, mai vista una testa di cazzo del genere, pazzesco! :mofo:
if Rebel can say only one function written by him can delete the entire post :)

you stop rosic ;)

[Only registered and activated users can see links. Click Here To Register...]