Jump to content

Full Monarch System


Shogun

Recommended Posts

  • Premium

If I wrote this quest again I would surely do it differently but when this was written this was very advanced stuff believe me. What matters is that it works (been in use for years in our server)

The quest i posted isn't actually equal 100% to yours, it's more intuitive and looking-good to users, thanks to some functions i've used, like item_name and say_item_vnum.

 

I suggest you to use it,

 

p.s: i'm sorry for italian language, but i needed that and i've got the idea not to only improve it but to even translate it.

 

:asd:

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...
  • 4 weeks later...
  • Premium

What comend is for check kingdome/empire gold ?

 

/mi

 

This work with the 2012 files ?

 

It should.

 

As i can see in the source, the monarch system is linked to the Castle Gates and the Golden Frogs. Can you explain me what is this about?

 

Castle Gates... The Siege War event...

 

 

The frogs give you 10kk when killed and you can spawn them with the /frog command and they will appear in the castle in the area with the tiled floor.

  • Metin2 Dev 1
  • Love 1
Link to comment
Share on other sites

  • 4 months later...
  • 6 months later...
  • 2 months later...
  • 6 years later...

I'm quite new to this stuff, im getting an error , its something to do with implementing the angels blessing quest, i understand that one of the functions is broken, i don't know how to fix it tho (you mentioned something about changing db cores but idk what that means) i've tried editing this in Monarch.cpp "UPDATE monarch set money=%lld where empire=%d", m_MonarchInfo.money[Empire], Empire);|
Still doesnt work.
Any ideas?

Link to comment
Share on other sites

  • 1 year later...

hello everyone, today I bring a version that uses a mysql table as a base

 

Spoiler
quest monarch_election_NOVA begin
	state start begin

		function candidacy()
			local name = pc.get_name()
			local id = pc.get_player_id()
			local reino = pc.get_empire()
			
			local query = string.format("INSERT INTO player.imperador_candidatos (id, reino, nick, votos) VALUES (%d, %d, '%s', 0)", id, reino, name)
			local result = mysql_query(query)
		end

		function clearcandidacy()
			local query = "DELETE FROM player.imperador_candidatos"
			local result = mysql_query(query)
		end

		function candidacycount(empire)
			local reino = pc.get_empire()
			local query = string.format("SELECT COUNT(*) FROM player.imperador_candidatos WHERE reino = %d", reino)
			local result = mysql_query(query)
			
			if result ~= nil and result[1] ~= nil then
				return tonumber(result[1][1])
			else
				return 0
			end
		end

		function candidacy_list(empire)
			local reino = pc.get_empire()
			local query = string.format("SELECT nick FROM player.imperador_candidatos WHERE reino = %d", reino)
			local result = mysql_query(query)
			
			local res = {}
			if result ~= nil then
				for i, row in ipairs(result) do
					table.insert(res, row[1])
				end
			end
			
			return res
		end

		function election(id)
			local reino = pc.get_empire()
			local query = string.format("SELECT * FROM player.imperador_candidatos WHERE reino = %d ORDER BY votos DESC", reino)
			local result = mysql_query(query)
			
			if result ~= nil and result[id] ~= nil then
				local candidateId = tonumber(result[id][1])
				local candidateName = result[id][3]
				
				query = string.format("UPDATE player.imperador_candidatos SET votos = votos + 1 WHERE id = %d", candidateId)
				mysql_query(query)
				
				return candidateName
			else
				return "Nenhum"
			end
		end

		function getcurrentwinner(empire)
			local query = string.format("SELECT * FROM player.imperador_candidatos WHERE reino = %d ORDER BY votos DESC LIMIT 1", empire)
			local result = mysql_query(query)
			
			if result ~= nil and result[1] ~= nil then
				local candidateName = result[1][3]
				local candidateVotes = tonumber(result[1][4])
				
				return {candidateName, candidateVotes}
			else
				return {"Nenhum", 0}
			end
		end

		function getcurrentwinner_empire_id(empire)
			local query = string.format("SELECT id, reino FROM player.imperador_candidatos WHERE reino = %d ORDER BY votos DESC LIMIT 1", empire)
			local result = mysql_query(query)
			
			if result ~= nil and result[1] ~= nil then
				local playerId = tonumber(result[1][1])
				local playerEmpire = tonumber(result[1][2])
				
				return {playerEmpire, playerId}
			else
				return {empire, 0}
			end
		end


		function getcurrentwinner_empire_nick_id(empire)
			local query = string.format("SELECT nick, id FROM player.imperador_candidatos WHERE reino = %d ORDER BY votos DESC LIMIT 1", empire)
			local result = mysql_query(query)
			
			if result ~= nil and result[1] ~= nil then
				local playerNick = result[1][1]
				local playerId = tonumber(result[1][2])
				
				return {playerNick, playerId}
			else
				return {"Nenhum", 0}
			end
		end


		function getcurrentwinner_FUN(empire)
			local res = {"Nobody", 0}
			local f = io.open("data/monarch_election", "r")
			local maxvotes = -1
			for line in f:lines() do
				local exploded = string.split(line, "t")
				if tonumber(exploded[2]) == empire and tonumber(exploded[3]) > maxvotes then
					maxvotes = tonumber(exploded[3])
					res = {exploded[4], tonumber(exploded[1])}
				end
			end
			f:close()
			return res
		end
		

        -- when login or enter begin
            -- if oh.ismonarch() > 0 and pc.count_item(70021) == 0 then
                -- set_state(newking)
            -- elseif oh.ismonarch() == 0 then
				-- if oh.ismonarch() == 0 then
					-- if pc.count_item(70021) > 0 then
						-- pc.remove_item(70021)
						-- syschat("A bencao do Imperador foi removida.")
					-- end
					-- if pc.count_item(11971) > 0 or pc.count_item(11972) > 0 or pc.count_item(11973) > 0 or pc.count_item(11974) > 0 then
						-- if pc.get_part(PART_MAIN) > 11970 and pc.get_part(PART_MAIN) < 11975 then
							-- syschat("Por favor, desequipe sua Armadura Imperial e relogue.")
							-- syschat("Voce nao tem mais permissao para usa-lo.")
						-- else
							-- local armor = 11971 + pc.get_job()
							-- pc.removeitem(armor)
							-- syschat("Sua armadura imperial foi removida.")
						-- end
					-- end
				-- end
			-- end
            -- if game.get_event_flag("monarch_elect") > 0 and pc.get_level() >= 40 then
                -- send_letter("Eleicao para Imperador")
            -- end
        -- end

        when kill with game.get_event_flag("monarch_elect") > 0 and pc.level >= 70 begin
            if game.get_event_flag("monarch_electionid") != pc.getqf("electionid") then
                if not npc.is_pc() then
                    local limit = get_mob_level[npc.get_race()]
                    if limit == nil then
                        return
                    else
                        if pc.get_level() > limit+10 then
                            return
                        end
                    end
                end
                if number(1, 500) == 1 then
                    if pc.count_item(25040) == 0 and pc.enough_inventory(25040) then
                        pc.give_item2(25040, 1)
                        syschat("Agora voce esta qualificado para votar no seu Candidato.") 
                    end
                end
            end
        end

		-- when guild_war_observer1.chat."GM: ADD PERSONAGEM ARQUIV" or guild_war_observer2.chat."GM: ADD PERSONAGEM ARQUIV" or guild_war_observer3.chat."GM: ADD PERSONAGEM ARQUIV" begin
		-- when 11001.chat."Eleicao para Imperador" or 11003.chat."Eleicao para Imperador" or 11005.chat."Eleicao para Imperador" with game.get_event_flag("monarch_vot") == 1 begin
		when 11001.chat."Eleicao para Imperador" or 11003.chat."Eleicao para Imperador" or 11005.chat."Eleicao para Imperador" begin
			say_title("Bem vindo ao PAINEL IMPERADOR")
			say("")
			say("Utilize com cuidado!")
			local ss = select("Votar IMPERADOR", "+ Votados" , "Candidatar" , "Sair" )
			if ss == 1 then
				if pc.get_level() < 92 then
					say("Voce precisa ter pelo menos nivel 92 para votar. Volte quando")
					say("se tornar um verdadeiro cidadao.")
					say("")
					return
				end
				if pc.getqf("VOTO_COMPUTADO") == 1 then
					say("Voce ja votou. Nao e possivel votar duas vezes!")
					say("")
					return
				end
				if pc.count_item(25040) < 1 then
					say("Voce precisa deste documento para provar que e verdadeiramente")
					say("um cidadao de "..locale.empire_names[pc.get_empire()]..".")
					say("")
					say_item_vnum(25040)
					say("Voce pode obte-lo derrotando monstros inimigos ou jogadores. Volte")
					say("quando tiver obtido o item.")
					say("")
					return
				end
				if game.get_event_flag("monarch_elect") == 2 then
					local gname_table = monarch_election_NOVA.candidacy_list(pc.get_empire())
					if table.getn(gname_table) == 0 then
						say("Nao ha candidatos!")
						say("")
					else
						table.insert(gname_table, "Cancelar")
						say("Voce esta qualificado para participar.")
						say(".")
						say("Por favor, vote com cuidado")
						say("voce so pode faze-lo uma vez.")
						say("")
						wait()
						local s5 = select_table(gname_table)
						if s5 == table.getn(gname_table) then
							return;
						else
							pc.setqf("VOTO_COMPUTADO", 1)
							pc.remove_item(25040, 1)
							say_title("Eleicao para Imperador:")
							say("")
							say("Obrigado por participar!")
							say("")
							-- say_reward("Voce votou em: "..gname_table[s5])
							say("")
							monarch_election_NOVA.election(s5)
							say_reward("Voce votou em: "..gname_table[s5])
						end
					end
				elseif game.get_event_flag("monarch_elect") == 0 then
					say("No momento nao esta acontecendo votacoes")
				elseif game.get_event_flag("monarch_elect") == 1 then
					say("No momento esta aberto apenas para se candidatar!")
				end
			elseif ss == 2 then
				say_title("Eleicao do Imperador:")
				say("")
				say("Atualmente, a eleicao dos novos imperadores esta em andamento.")
				say("")

				local winners = {}
				for empire = 1, 3 do
					local winnerData = monarch_election_NOVA.getcurrentwinner(empire)
					winners[empire] = winnerData
				end

				say_reward("Vencedores da Eleição Imperial:")

				say_reward("Shinsoo: " .. winners[1][1] .. " - Votos: " .. winners[1][2])
				say_reward("Chunjo: " .. winners[2][1] .. " - Votos: " .. winners[2][2])
				say_reward("Jinno: " .. winners[3][1] .. " - Votos: " .. winners[3][2])
				say("")
				say("")
				say("")
			elseif ss == 3 then
				local NEED_MONEY = 1000000
				local NEED_LEVEL = 65
				if game.get_event_flag("monarch_elect") == 1 then
					if pc.getqf("monarch_CANDIDATO") == 1 then
						say("Voce ja se candidatou, aguarde o fim das eleicoes")
						return
					elseif pc.getqf("monarch_CANDIDATO") == 0 then
						say("Voce deseja de concorrer pelo seu reino")
						say("como imperador?")
						say("")
						local a = select("Sim", "Sair" )
						if a == 1 then
							if monarch_election_NOVA.candidacycount(pc.get_empire()) >= 8 then
								say("Desculpe, ja temos candaditos suficientes.")
								say("")
								say("tente novamente na proxima eleicao.")
							elseif pc.get_gold() >= NEED_MONEY and pc.get_level() >= NEED_LEVEL then
								say("Parabens voce se registrou na disputa IMPERIAL!")
								monarch_election_NOVA.candidacy();
								-- game.set_event_flag("monarch_CANDIDATO", 1)
								pc.setqf("monarch_CANDIDATO", 1)
							else
								say("Desculpe, voce nao cumpre os requisitos.")
								say(".")
								say("Necessario Lv 65 E 1.000.000 DE GOLD")
								-- say("Desculpe, voce nao cumpre os requisitos.")
							end

						end
					end
				elseif game.get_event_flag("monarch_elect") == 0 then
					say("No momento nao esta aberto para se candidatar!")
				end
			end
		end

		-- when letter with game.get_event_flag("monarch_elect") == 1 or pc.is_gm() begin
		when letter with pc.is_gm() begin
		-- when letter begin
			send_letter("Painel IMPERADOR")
		end

		-- when button or info with game.get_event_flag("monarch_elect") == 1 or pc.is_gm() begin
		when button or info with pc.is_gm() begin
            -- if game.get_event_flag("monarch_elect") == 1 then
			-- if pc.is_gm() == true then
				-- local b = select("1", "2")
				-- if b == 1 then
					-- say("TE")
				-- end
			-- end
			local s = select("Abrir/Fechar inscricao IMP", "+ Votados", "Votar" , "Concorrer", "Sair" )
			if s == 1 then
				if game.get_event_flag("monarch_elect") == 1 then
					say_title("Eleicao do Imperador:")
					say("")
					say("Atualmente, as candidaturas para a Eleicao do Imperador estao abertas.")
					say("")
					say("Deseja encerra-las agora?")
					say("")
					local s = select("Encerrar", "Continuar")

					if s == 1 then
						notice_all("A eleicao para Imperador esta comecando agora!")
						notice_all("Apresente seus certificados ao Guardiao Arqueiro para votar.")
						game.set_event_flag("monarch_elect", 2)
						pc.setqf("VOTO_COMPUTADO", 0)
						-- game.set_event_flag("monarch_electionid", get_global_time())
						say_title("Eleicao do Imperador:")
						say("")
						say("As candidaturas foram encerradas e os jogadores agora podem")
						say("votar em um imperador.")
						say("")
					end
				elseif game.get_event_flag("monarch_elect") == 2 then
					say_title("Eleicao do Imperador:")
					say("")
					say("Atualmente, a eleicao dos novos imperadores esta em andamento.")
					say("Deseja encerra-la agora?")
					say("")
					local winners = {}
					for empire = 1, 3 do
						local winnerData = monarch_election_NOVA.getcurrentwinner(empire)
						winners[empire] = winnerData
					end

					say("Vencedores da Eleição Imperial:")

					say("Shinsoo: " .. winners[1][1] .. " - Votos: " .. winners[1][2])
					say("Chunjo: " .. winners[2][1] .. " - Votos: " .. winners[2][2])
					say("Jinno: " .. winners[3][1] .. " - Votos: " .. winners[3][2])

					local s = select("Encerrar", "Continuar")
					if s == 1 then
						notice_all("A Eleicao do Imperador terminou agora.")
						notice_all("Vencedores da Eleição Imperial:")
						notice_all("")
						-- game.set_event_flag("monarch_elect", 0)
						-- mgmt.monarch_change_lord(2, monarch_election.getcurrentwinner_empire_id(2)[2])
						-- for empire = 1, 3 do
							-- local winnerData = monarch_election_NOVA.getcurrentwinner_empire_id(empire)
							-- local winnerName = winnerData[1]
							
							-- if winnerName ~= "Ninguem" then
								-- mgmt.monarch_change_lord(empire, winnerName)
							-- end
						-- end
						-- mgmt_monarch_change_lord(2, 1)
						-- mgmt_monarch_change_lord(3, 1751)
						-- for empire = 1, 3 do
							-- local winnerData = monarch_election_NOVA.getcurrentwinner_empire_id(empire)
							-- local playerId = winnerData[2]
							
							-- if playerId ~= 0 then
								-- mgmt.monarch_change_lord(empire, playerId)
							-- end
						-- end


						-- if monarch_election.getcurrentwinner(1)[1] != 0 then
							-- mgmt.monarch_change_lord(1, monarch_election_NOVA.getcurrentwinner_empire_nick_id(1)[2])
						-- end
						-- if monarch_election.getcurrentwinner(2)[1] != 0 then
							-- mgmt.monarch_change_lord(2, monarch_election_NOVA.getcurrentwinner_empire_nick_id(2)[2])
						-- end
						-- if monarch_election.getcurrentwinner(3)[1] != 0 then
							-- mgmt.monarch_change_lord(3, monarch_election_NOVA.getcurrentwinner_empire_nick_id(3)[2])
							-- mgmt.monarch_change_lord(3, "Select")
							-- mgmt.monarch_change_lord(3, 1)
							-- mgmt.monarch_change_lord(2, 1)
							-- mgmt.monarch_change_lord(1, 1)
							-- monarch_election_NOVA.clearcandidacy()
						-- end
					end
				elseif game.get_event_flag("monarch_elect") == 0 then
					say_title("Eleicao do Imperador:")
					say("")
					say("Aqui voce pode iniciar as candidaturas para o Imperador.")
					say("")
					say("Deseja inicia-las agora?")
					say("")
					local s = select("Iniciar", "Nao iniciar")

					if s == 1 then
						notice_all("O periodo de Candidaturas para Imperador comeca agora!")
						notice_all("Aproxime-se do Guardiao Arqueiro na cidade para se inscrever na eleicao.")
						game.set_event_flag("monarch_elect", 1)
						-- pc.setqf("monarch_CANDIDATO", 0)
						-- game.set_event_flag("monarch_electionid", get_global_time())
						monarch_election_NOVA.clearcandidacy()
					end
				end
			elseif s == 2 then
				say_title("Eleicao do Imperador:")
				say("")
				say("Atualmente, a eleicao dos novos imperadores esta em andamento.")
				-- say("Deseja encerra-la agora?")
				say("")
				-- say_reward("Posicoes atuais:")

				local winners = {}
				for empire = 1, 3 do
					local winnerData = monarch_election_NOVA.getcurrentwinner(empire)
					winners[empire] = winnerData
				end

				say_reward("Vencedores da Eleição Imperial:")

				say_reward("Shinsoo: " .. winners[1][1] .. " - Votos: " .. winners[1][2])
				say_reward("Chunjo: " .. winners[2][1] .. " - Votos: " .. winners[2][2])
				say_reward("Jinno: " .. winners[3][1] .. " - Votos: " .. winners[3][2])
				say("")
				say("")
				say("")
			elseif s == 3 then
				-- if game.get_event_flag("monarch_elect") == 2 then
					local gname_table = monarch_election_NOVA.candidacy_list(pc.get_empire())
					if table.getn(gname_table) == 0 then
						say("Nao ha candidatos!")
						say("")
					else
						table.insert(gname_table, "Cancelar")
						say("Voce esta qualificado para participar.")
						say(".")
						say("Por favor, vote com cuidado")
						say("voce so pode faze-lo uma vez.")
						say("")
						wait()
						local s5 = select_table(gname_table)
						if s5 == table.getn(gname_table) then
							return;
						else
							monarch_election_NOVA.election(s5)
							say_reward("Voce votou em: "..gname_table[s5])
						end
					end
				-- elseif game.get_event_flag("monarch_elect") == 0 then
					-- say("No momento nao esta acontecendo votacoes")
				-- end
			elseif s == 4 then
				if game.get_event_flag("monarch_elect") == 1 then
					if pc.getqf("monarch_CANDIDATO") == 1 then
						say("Voce ja se candidatou, aguarde o fim das eleicoes")
						return
					elseif pc.getqf("monarch_CANDIDATO") == 0 then
						say("Voce deseja de concorrer pelo seu reino")
						say("como imperador?")
						say("")
						local a = select("Sim", "Sair" )
						if a == 1 then
							-- if game.get_event_flag("monarch_CANDIDATO") == 1 then
								-- say("Voce ja se candidatou, aguarde o fim das eleicoes")
							
								say("Voce se candidatou!")
								say("")
								say("Boa sorte")
								monarch_election_NOVA.candidacy();
								pc.setqf("monarch_CANDIDATO", 1)
							-- end
						end
					end
				elseif game.get_event_flag("monarch_elect") == 0 then
					say("No momento nao esta aberto para se candidatar!")
				end
			elseif s == 5 then
				return
			end

		end--endwhen
	end--endstate

	    -- state newking begin
			-- when login or enter begin
				-- send_letter("Parabens!")
			-- end
			-- when button or info begin
				-- local treatment = {
					-- [0] = "Rei",
					-- [1] = "Rainha",
				-- }
				-- local armor = 11971 + pc.get_job()
				-- say_title("Parabens!")
				-- say("")
				-- say("Voce foi eleito como o(a) "..treatment[pc.get_sex()].." de "..locale.empire_names[pc.get_empire()].."!")
				-- say("")
				-- say("Como "..treatment[pc.get_sex()]..", voce recebe a Armadura Hwang e os")
				-- say("itens Bencao do Anjo durante o seu reinado.")
				-- say("")
				-- say("Este amuleto permite que voce use seus poderes de Imperador, mas")
				-- say("observe que voce tera sua utilizacao limitada pelo Yang disponivel")
				-- say("no cofre do Reino, portanto, escolha sabiamente!")
				-- say("")
				-- say("Que o seu reinado seja prospero!")
				-- say("")
				-- clear_letter()
				-- set_state(start)
				-- if pc.count_item(armor) == 0 then
					-- pc.give_item2(armor)
				-- end
				-- if pc.count_item(70021) == 0 then
					-- pc.give_item2(70021)
				-- end
				-- notice_all("O(a) "..treatment[pc.get_sex()].." "..pc.getname().." de "..locale.empire_names[pc.get_empire()].." foi coroado! Todos saudem o(a) "..treatment[pc.get_sex()].."!")
			-- end
		-- end

end

 

Spoiler
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for imperador_candidatos
-- ----------------------------
DROP TABLE IF EXISTS `imperador_candidatos`;
CREATE TABLE `imperador_candidatos`  (
  `id` int(255) NOT NULL,
  `reino` int(3) NOT NULL DEFAULT 1,
  `nick` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '',
  `votos` int(11) NOT NULL
) ENGINE = MyISAM CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;

 

I'm going to leave a detail here that the vote confirmation method still doesn't need to be 100% updated and the "mgmt.monarch_change_lord" function doesn't work for some reason.

 

for empire = 1, 3 do
  local winnerData = monarch_election_NOVA.getcurrentwinner_empire_id(empire)
  local playerId = winnerData[2]

  if playerId ~= 0 then
  mgmt.monarch_change_lord(empire, playerId)
  end
end

 

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.