Jump to content

Sistema/Evento DeathMatch


Mário.
 Share

Recommended Posts

Bem, fiz isto já há algum tempo para o servidor pvp e penso que não darei muito uso dela.

O evento (ou sistema, como preferirem dizer) é meter todos os jogadores free-for-all, ou seja, têm como objetivo matar outros jogadores para ganhar pontos e serem os vencedores.

Isto é ideal para um servidor pvp.

Ele está estruturado da seguinte forma:

  • O GM ativa o evento e os jogadores terão 5 minutos para entrarem no mapa;
  • O evento tem como duração 20 minutos;
  • O jogador tem 10 vidas, sendo que se as perder, é removido do mapa (anunciado como eliminação);
  • Quando o jogador morre 5x, aparece um aviso de como só lhe resta mais 5 vidas;
  • A cada morte, o jogador perde 1 ponto;
  • A cada 1 minuto, aparece o top 5 das pessoas com mais pontos do evento somente no mapa;
  • Existem duas hipóteses: Jogadores de nível 1-75 poderem participar ou 75-105;

Tudo o que disse é totalmente editável pela quest:

				settings.map_index = 64 -- map index where the event will be set to
				settings.name = "Mapa PvP" -- name of the map 
				settings.low_level = 75 -- min level to participate
				settings.max_level = 105 -- max level to participate
				settings.time = 60*20 -- You can set time for the event
				settings.warning_die = 5 -- Warning if the player die 5 times
				settings.limit_die = 10 -- Limit lives that you have in order to get kicked out
				settings.warp_out = 5 -- Time to warp out if the event is off
				settings.timer = 60*5 -- Time in order to participate in the event
				settings.ranking = 60*1 -- Time to set a loop for ranking
				settings.test = false -- return false for debug mode just for testing
	--			settings.true = true -- enable the event = true | disable the event = false

 

Source

 

1) Adicionar no service.h:

#define LSM2_EVENT_DEATHMATCH

 

2) No char_battle.cpp, procura por:

	if (bPKMode == PK_MODE_GUILD && !GetGuild())
		bPKMode = PK_MODE_FREE;

 

Adiciona por baixo:

#ifdef LSM2_EVENT_DEATHMATCH
	if (GetMapIndex() == 29){
		if (IsGM())
			bPKMode = PK_MODE_PROTECT; // se for GM, ele ficará protegido e não o conseguirão matar
		else
			bPKMode = PK_MODE_FREE; // se for jogador normal, ele ficará livre 
	}
#endif

 

PS: Altera o 29 pelo INDEX do mapa a ser utilizado.

 

Server

1) Abrir o questlib.lua e adicionar:

dofile(get_locale_base_path().."/quest/sistema.lua")

 

2) Na pasta /quest criar um ficheiro chamado sistema.lua e adicionar:

sistema = {}
sistema.evento_deathmatch = {}
sistema.evento_deathmatch.palavra = "deathmatch"
sistema.evento_deathmatch.desligado = 0
sistema.evento_deathmatch.ligado = 1
sistema.evento_deathmatch.palavra75 = "apenas75"
sistema.evento_deathmatch.palavra75p = "acima75"
sistema.evento_deathmatch.palavraranking = "ranking"
sistema.evento_deathmatch.titulo = "Evento Último Sobrevivente:"
sistema.evento_deathmatch.apenas75 = "Somente os jogadores que estiverem a nível 75 poderão participar no evento."
sistema.evento_deathmatch.apenas105 = "Somente os jogadores que estiverem a nível 75+ poderão participar no evento."
sistema.evento_deathmatch.grupo = "Infelizmente estás em grupo."
sistema.evento_deathmatch.teleportado = "O evento não está ativo, serás teleportado para fora do mapa."
sistema.evento_deathmatch.vidas = "Já morreste 5 vezes.[ENTER]Lembrando que se morreres 10 vezes serás desqualificado independente das mortes que tenhas."
sistema.evento_deathmatch.adeus = "O jogador %s foi desqualificado do evento por ter morrido"
sistema.evento_deathmatch.npc = "Último Sobrevivente"
sistema.evento_deathmatch.npcgm = "Evento: Último Sobrevivente"
sistema.evento_deathmatch.calendario = "O Calendário está proposto para ser o seguinte:"
sistema.evento_deathmatch.calendario1 = "SEGUNDA-FEIRA: Desligado[ENTER]TERÇA-FEIRA: Desligado[ENTER]QUARTA-FEIRA: Desligado[ENTER]QUINTA-FEIRA: Desligado[ENTER]SEXTA-FEIRA: 21H[ENTER]SÁBADO: 16H[ENTER]DOMINGO: Desligado"
sistema.evento_deathmatch.ativar = "Queres ativar o evento?"
sistema.evento_deathmatchyes = "Sim"
sistema.evento_deathmatchno = "Não"
sistema.evento_deathmatch.escolhenivel = "Escolhe qual é a opção que desejas ativar:"
sistema.evento_deathmatch.so75 = "Nível 75 - 75"
sistema.evento_deathmatch.mais75 = "Nível 75+"
sistema.evento_deathmatch.eventofoiligado75 = "O Evento Último Sobrevivente encontra-se ativado.[ENTER]Participa através do Beleguim da Batalha.[ENTER]Somente personagens de nível 75 serão aceites."
sistema.evento_deathmatch.eventofoiligado75p = "O Evento Último Sobrevivente encontra-se ativado.[ENTER]Participa através do Beleguim da Batalha.[ENTER]Somente personagens de nível 75+ serão aceites."
sistema.evento_deathmatch.desativar = "Queres desativar o evento?"
sistema.evento_deathmatch.eventofoidesligado = "O Evento Último Sobrevivente foi encerrado."
sistema.evento_deathmatch.portasfechadas = "As participações para o Evento foram encerradas.[ENTER]Boa sorte a todos os participantes, que vença o melhor."
sistema.evento_deathmatch.ranking = "O jogador %s encontra-se no topo da tabela com %s mortes."
sistema.evento_deathmatch.acabou = "O evento acaba de terminar, sendo o vencedor o jogador %s com %s mortes.[ENTER]A administração parabeniza o jogador com 250 moedas de dragão."
sistema.evento_deathmatch.mensagemdesligado = "O evento encontra-se desligado, aguarda por mais informações."
sistema.evento_deathmatch.mensagemligado = "Isto é para os jogadores que sabem duelar e mostrar a sua persistência dentro do campo da batalha. Achas que estás preparado para entrares num mapa onde só o mais forte sairá vitorioso?"
sistema.evento_deathmatch.error = "ERRO: Contacta a administração e explica-lhes como é que chegaste até aqui."
sistema.evento_deathmatch.npcfechado = "Infelizmente já não podes participar, as inscrições fecharam.[ENTER]Podes acompanhar o evento estando atento as notícias."
sistema.evento_deathmatch.kills = "Possuís %s mortes."
sistema.evento_deathmatch.ranking = "Classificações:"
sistema.evento_deathmatch.ranking1 = "%s - %s mortes"
sistema.evento_deathmatch.importante = "É necessário que fiques mapa do Deserto para que os jogadores sejam teleportados."

 

3) Inserir a seguinte função na questlib.lua:

function say_lsm2(msg)
	msg_size = string.len(msg)
	if msg_size > 59 then
		local i = 59
		last_word = nil
		while last_word == nil and i > 0 do
			if string.sub(msg,i,i) == " " or string.sub(msg,i,i) == "." or string.sub(msg,i,i) == "," then
				last_word = i
			end
			i = i-1
		end
		if i == 0 then
			last_word = 59
		end
		say(string.sub(msg,0,last_word))
		say2(string.sub(msg,last_word+1))
	else
		say(msg)
	end
end

 

4) Instalar o deathmatch.sql que está disponível abaixo e inserir na tabela log da base de dados.

Deixo-vos aqui a quest:

quest lsm2_event begin
	state start begin
		function get_settings()
			local settings = {}
				settings.map_index = 64 -- map index where the event will be set to
				settings.name = "Mapa PvP" -- name of the map 
				settings.low_level = 75 -- min level to participate
				settings.max_level = 105 -- max level to participate
				settings.time = 60*20 -- You can set time for the event
				settings.warning_die = 5 -- Warning if the player die 5 times
				settings.limit_die = 10 -- Limit lives that you have in order to get kicked out
				settings.warp_out = 5 -- Time to warp out if the event is off
				settings.timer = 60*5 -- Time in order to participate in the event
				settings.ranking = 60*1 -- Time to set a loop for ranking
				settings.test = false -- return false for debug mode just for testing
	--			settings.true = true -- enable the event = true | disable the event = false
				return settings
		end
		
		function only_low_level()		
			local settings = lsm2_event.get_settings()
			
			if settings.low_level != pc.get_level() then
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say(sistema.evento_deathmatch.apenas75) -- only 75
				return
			else
				-- [1] - reds | [2] - yellows | [3] - blues
				local empire = pc.get_empire()
				local warp_xy = {[1] = {794100, 958200}, [2] = {799900, 940000}, [3] = {782600, 943100}}
				pc.warp(warp_xy[empire][1], warp_xy[empire][2])
			end
		end
		
		function only_max_level()
			local settings = lsm2_event.get_settings()
			
			if settings.low_level > pc.get_level() then
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say(sistema.evento_deathmatch.apenas105) -- only 75 plus
				return
			else
				-- [1] - reds | [2] - yellows | [3] - blues
				local empire = pc.get_empire()
				local warp_xy = {[1] = {794100, 958200}, [2] = {799900, 940000}, [3] = {782600, 943100}}
				pc.warp(warp_xy[empire][1], warp_xy[empire][2])
			end
		end
		
		-- only for test
		function only_for_test()
			local settings = lsm2_event.get_settings()
			
			if settings.test == true then return true else
				return false
			end
				
			return false
		end
		
		function clear_all()
			game.set_event_flag(sistema.evento_deathmatch.palavra,sistema.evento_deathmatch.desligado)
			game.set_event_flag(sistema.evento_deathmatch.palavra75,sistema.evento_deathmatch.desligado)
			game.set_event_flag(sistema.evento_deathmatch.palavra75p,sistema.evento_deathmatch.desligado)
			clear_server_timer("ranking")
			clear_server_timer("lsm2_event")
			clear_server_timer("adecorrer")
		end
		
		when login begin
			local settings = lsm2_event.get_settings()
			
			if pc.get_map_index() == settings.map_index and game.get_event_flag(sistema.evento_deathmatch.palavra) == sistema.evento_deathmatch.desligado then
				if pc.is_gm() then
					return
				end
			
				notice_multiline(sistema.evento_deathmatch.teleportado, notice)
				warp_to_village(settings.warp_out)
				
			-- tlthings01
		-- elseif pc.get_map_index() == settings.map_index and game.get_event_flag(sistema.evento_deathmatch.palavra) != sistema.evento_deathmatch.desligado then	
			-- if pc.is_dead() == true then
				-- local count = pc.getf("die","deathmatch")+1
				-- local contagem = pc.getf("kill","deathmatch")-1	
				-- pc.setf("die","deatmatch",pc.getf("die","deathmatch")+1)

				-- pc.setf("kill","deathmatch",pc.getf("kill","deathmatch")-1)
				-- chat("Como morreste, perdeste uma morte. Neste momento possuis "..contagem.. " morte(s).")
				
				-- if count == settings.warning_die then 
					-- notice_multiline(sistema.evento_deathmatch.vidas,notice)
				-- elseif count == settings.die then
					-- notice_all(string.format(sistema.evento_deathmatch.adeus,pc.get_name()))
					-- warp_to_village()
					-- pc.setf("die","deathmatch",0)
				-- end
			else
				return
			end
		end
			
		-- tlthings02	
		when die begin
			local settings = lsm2_event.get_settings()

			if pc.get_map_index() == settings.map_index and game.get_event_flag(sistema.evento_deathmatch.palavra) != sistema.evento_deathmatch.desligado then
				local count = pc.getf("die","deathmatch")+1
				local settings = lsm2_event.get_settings()
				local contagem = pc.getf("kill","deathmatch")-1

				pc.setf("die","deathmatch",pc.getf("die","deathmatch")+1)
				pc.setf("kill","deathmatch",pc.getf("kill","deathmatch")-1)

				chat("Como morreste, perdeste uma morte. Neste momento possuis "..contagem.. " morte(s).")

				if count == settings.warning_die then 
					notice_multiline(sistema.evento_deathmatch.vidas,notice)
				elseif count >= settings.limit_die then
					notice_all(string.format(sistema.evento_deathmatch.adeus,pc.get_name()))
					warp_to_village()
					pc.setf("die","deathmatch",0)
				end
			end
		end
			
		when 9004.chat.sistema.evento_deathmatch.npcgm with pc.is_gm() begin
			local settings = lsm2_event.get_settings()
			
			if game.get_event_flag(sistema.evento_deathmatch.palavra) == sistema.evento_deathmatch.desligado then
				say_title(sistema.evento_deathmatch.titulo)
				say(sistema.evento_deathmatch.calendario)
				say(sistema.evento_deathmatch.calendario1)
				wait()
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say(sistema.evento_deathmatch.ativar)
				
				if select(sistema.evento_deathmatchyes, sistema.evento_deathmatchno) == 1 then
					
					say_title(sistema.evento_deathmatch.titulo)
					say()
					say(sistema.evento_deathmatch.escolhenivel)
					
					local choose = select(sistema.evento_deathmatch.so75,sistema.evento_deathmatch.mais75,locale.cancel)
					
					if choose == 1 then
						game.set_event_flag(sistema.evento_deathmatch.palavra75,sistema.evento_deathmatch.ligado)
						game.set_event_flag(sistema.evento_deathmatch.palavra,sistema.evento_deathmatch.ligado)
						notice_multiline(sistema.evento_deathmatch.eventofoiligado75,notice_all)
						server_timer("lsm2_event",settings.timer)
					else
						game.set_event_flag(sistema.evento_deathmatch.palavra75p,sistema.evento_deathmatch.ligado)
						game.set_event_flag(sistema.evento_deathmatch.palavra,sistema.evento_deathmatch.ligado)
						notice_multiline(sistema.evento_deathmatch.eventofoiligado75p,notice_all)
						server_timer("lsm2_event",settings.timer)
					end
				else
					return
				end
			else
				say_title(sistema.evento_deathmatch.titulo)
				say(sistema.evento_deathmatch.desativar)
				say()
				say_lsm2(sistema.evento_deathmatch.importante,settings.name)
				
				if select(sistema.evento_deathmatchyes, sistema.evento_deathmatchno) == 1 then
					lsm2_event.clear_all()
					notice_multiline(sistema.evento_deathmatch.eventofoidesligado,notice_all)
					warp_all_to_village(pc.get_map_index(),settings.warp_out)
				else
					return
				end
			end
		end
		
		when lsm2_event.server_timer begin
			local settings = lsm2_event.get_settings()
			
			notice_multiline(sistema.evento_deathmatch.portasfechadas,notice_all)
			game.set_event_flag(sistema.evento_deathmatch.palavra,sistema.evento_deathmatch.fechado)
			server_loop_timer("ranking",settings.ranking)
			server_timer("adecorrer",settings.time)
		end
		
		when ranking.server_timer begin
			local ranking = mysql_query("SELECT nome, mortes FROM log.deathmatch ORDER by mortes DESC LIMIT 5;")
			
			notice_all(sistema.evento_deathmatch.ranking)
			for position in ipairs(ranking) do
				notice_all(string.format(position..".º lugar: "..ranking.nome[position].." - "..ranking.mortes[position].." mortes."))
			end
		end
		
		when adecorrer.server_timer begin
			local ranking = mysql_query("SELECT nome, mortes FROM log.deathmatch ORDER by mortes DESC LIMIT 1;")
			
			for position in ipairs(ranking) do
				notice_multiline(string.format(sistema.evento_deathmatch.acabou,ranking.nome[position],ranking.mortes[position]),notice_all)
				lsm2_event.clear_all()
			end
		end
		
		when guild_war_observer1.chat.sistema.evento_deathmatch.npc or
			guild_war_observer2.chat.sistema.evento_deathmatch.npc or 
			guild_war_observer3.chat.sistema.evento_deathmatch.npc begin
			local settings = lsm2_event.get_settings()
			
			if game.get_event_flag(sistema.evento_deathmatch.palavra) == sistema.evento_deathmatch.desligado then
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say(sistema.evento_deathmatch.mensagemdesligado)
				return
			elseif game.get_event_flag(sistema.evento_deathmatch.palavra) == sistema.evento_deathmatch.ligado then
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say_lsm2(sistema.evento_deathmatch.mensagemligado)
				
				if select(sistema.evento_deathmatchyes, sistema.evento_deathmatchno) == 1 then
					if game.get_event_flag(sistema.evento_deathmatch.palavra75) == sistema.evento_deathmatch.ligado then
						lsm2_event.only_low_level()
					elseif game.get_event_flag(sistema.evento_deathmatch.palavra75p) == sistema.evento_deathmatch.ligado then
						lsm2_event.only_max_level()
					elseif party.is_party() then
						say(sistema.evento_deathmatch.grupo) return
					else
						say_title(sistema.evento_deathmatch.titulo)
						say()
						say(sistema.evento_deathmatch.error)
						return
					end
				else
					return
				end
			elseif game.get_event_flag(sistema.evento_deathmatch.palavra) == sistema.evento_deathmatch.fechado then
				say_title(sistema.evento_deathmatch.titulo)
				say()
				say(sistema.evento_deathmatch.npcfechado)
				return
			end
		end
		
		when kill with npc.is_pc() begin
			local settings = lsm2_event.get_settings()
			
			if pc.get_map_index() == settings.map_index then
				local contagem = pc.getf("kill","deathmatch")+1

				pc.setf("kill","deathmatch",pc.getf("kill","deathmatch")+1)
				mysql_query("UPDATE log.deathmatch SET mortes ='"..contagem.."' WHERE name ='"..pc.get_name().."' LIMIT 1")
				chat("Neste momento contas com "..contagem.. " morte(s).")
			end
		end
	end
end

ATENÇÃO: Utilizei a função when die begin mas em caso de não tiverem pesquisem por tlthings01 dentro da quest e descomentem tudo o que está por baixo e removem/comentem o que está no tlthings02

 

Infelizmente não tenho qualquer imagem nem tenho tempo para tal mas foi testado e usado em cenário real.

OBS: É recomendado usarem mysql_direct_query para melhor performance mas a diferença de uma para a outra neste cenário é de 0.0343s por isso é indiferente a escolha de uma para a outra.

 

Ah e ignorem o facto dos comentários estarem em inglês, apeteceu-me escrever dessa forma na altura.

 

PS: Isto é igual/semelhante ao Evento Coliseu.

deathmatch.sql 

questing.lua

Edited by Mário.
  • Like 3
Link to comment
Share on other sites

4 horas atrás, igoriap disse:

Instalei tudo direito, quando clico no npc 9004 que está setado, o npc me retorna somente a opção de Desligar o evento e nada mais, e os Arqueiros que são de entrada,  quando clicados não retornam nada.

No sysser do CH me retorna  lsm2_event error lua !

Verifica pelo comando /get se o evento não se encontra com o número 1.

Tenta desligar e ligar de novo o evento, és o único com esse erro.

Link to comment
Share on other sites

8 minutos atrás, igoriap disse:

Sim está com 1, quando clico no npc como player para entrar no evento etc opções, no core 1 retorna este erro

Screenshot_1.png

 

10 horas atrás, LuizFernando disse:

Comigo também só aparece a opção desligar.

 

Insiram a seguinte função no questlib.lua:

function say_lsm2(msg)
	msg_size = string.len(msg)
	if msg_size > 59 then
		local i = 59
		last_word = nil
		while last_word == nil and i > 0 do
			if string.sub(msg,i,i) == " " or string.sub(msg,i,i) == "." or string.sub(msg,i,i) == "," then
				last_word = i
			end
			i = i-1
		end
		if i == 0 then
			last_word = 59
		end
		say(string.sub(msg,0,last_word))
		say2(string.sub(msg,last_word+1))
	else
		say(msg)
	end
end

 

 

Tópico editado.

Link to comment
Share on other sites

1 hora atrás, igoriap disse:

Agora me retorna esse erro, e no npc exibe metade das falas, no observer (arqueiro) continua sem exibir nada e travando a tela quando clico.

Screenshot_2.png

 

Resolvido no Skype, era necessário o questing.lib do Mijago e o sistema.lua estava incompleto.

Adicionado a questlib em caso de não terem e sistema.lua editado.

 

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...