--[[ elected = { president = { name = "", --name of the elected candidate. when = 0, --when the candidate was elected. }, }, candidates = { president = { ["cadidatename"] = { political_campaign = "", voters = { --names of voters who voted for this candidate. ["votername"] = "when", }, }, }, }, --]] --############################################################################ modEUrn.getPropCommPresident = function() return { --privs = {electoraljudge=true}, params = "[<".. modEUrn.translate("candidate_name")..">]", description = modEUrn.translate("Show or Select the presidente of the server."), func = function(playername, candidatename) if type(candidatename)=="string" and candidatename~="" then if minetest.get_player_privs(playername).electoraljudge then if modEUrn.doPresident(playername, candidatename) then modEUrn.doSave() minetest.chat_send_player( playername, --os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) .. core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Player %s has been named the president of this server!"):format(dump(candidatename)) ) end else minetest.chat_send_player( playername, --os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) .. core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("You do not have the 'electoraljudge' privilege to define who will be the president of the server!") ) end else minetest.chat_send_player( playername, --os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) .. core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("The president of this server is %s!"):format(dump(modEUrn.getPresidentName())) ) end end, } end minetest.register_chatcommand( "president", modEUrn.getPropCommPresident() ) --[[ minetest.register_chatcommand( modEUrn.translate("president"), modEUrn.getPropCommPresident() ) --]] --############################################################################ modEUrn.getPropCommCandidateMe = function() return { --privs = {electoraljudge=true}, params = "[<".. modEUrn.translate("political campaign")..">]", description = modEUrn.translate("Register your campaign to run for server president."), func = function(playername, political_campaign) local player = minetest.get_player_by_name(playername) if player and player:is_player() then --modEUrn.debug("playername='"..playername.."' | political_campaign='"..political_campaign.."'") modEUrn.FormSpecs.showFormRegCampaign(playername, political_campaign) else local candidatename = playername if modEUrn.doPresidentCandidate(playername, candidatename, political_campaign) then modEUrn.doSave() minetest.chat_send_player( playername, --os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) .. core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Player %s has been registered to run as a candidate for president of this server!"):format(dump(candidatename)) ) end end end, } end minetest.register_chatcommand( "candidateme", modEUrn.getPropCommCandidateMe() ) --############################################################################ modEUrn.getPropCommCandidates = function() return { --privs = {electoraljudge=true}, --params = "[<".. modEUrn.translate("political campaign")..">]", description = modEUrn.translate("Show the name of all candidates for president."), func = function(playername) local cands = modEUrn.getPresidentCandidates() local candList = "" local candCount = 0 --minetest.chat_send_all("Numero de Candidatos: "..#modEUrn.handler.candidates.president) for _, iCandPresName in ipairs(cands) do candCount = candCount + 1 if candList == "" then candList = iCandPresName else candList = candList..", "..iCandPresName end end minetest.chat_send_player( playername, core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Number of Candidates: %s"):format(candCount) ) minetest.chat_send_player( playername, core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Candidate List: %s"):format(candList) ) --minetest.chat_send_all("Numero de Candidatos: "..candCount) --minetest.chat_send_all("Lista de Candidatos: "..candList) --]] --[[ if then minetest.chat_send_player( playername, --os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) .. core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Player %s has been registered to run as a candidate for president of this server!"):format(dump(candidatename)) ) end --]] end, } end minetest.register_chatcommand( "candidates", modEUrn.getPropCommCandidates() ) --############################################################################ modEUrn.getPropCommCandCampaign = function() return { --privs = {electoraljudge=true}, params = "<".. modEUrn.translate("candidate_name")..">", description = modEUrn.translate("Show the Campaign of candidate for president."), func = function(playername, candidatename) modEUrn.showPresCandCampaign(playername, candidatename) end, } end minetest.register_chatcommand( "campaign", modEUrn.getPropCommCandCampaign() ) minetest.register_chatcommand( "candidate", modEUrn.getPropCommCandCampaign() ) --############################################################################ modEUrn.getPropCommCandVote = function() return { --privs = {electoraljudge=true}, params = "<".. modEUrn.translate("candidate_name")..">", description = modEUrn.translate("Vote for a specific candidate for president."), func = function(playername, candidatename) if type(modEUrn.handler.voters[playername])=="table" then local voterTimePlayed = modEUrn.handler.voters[playername].times.played --in secounds if voterTimePlayed >= modEUrn.MinPlayedHours * (60*60) then if type(candidatename)=="string" and candidatename ~= "" then if minetest.player_exists(candidatename) then if type(modEUrn.handler.candidates.president[candidatename])=="table" then --modEUrn.MinPlayedHours --modEUrn.handler.voters[playername].times.played for iCandPresName, _ in pairs(modEUrn.handler.candidates.president) do --modEUrn.debug("iCandPresName = "..iCandPresName) if type(modEUrn.handler.candidates.president[iCandPresName].voters[playername])~="nil" then --modEUrn.debug("modEUrn.handler.candidates.president["..iCandPresName.."].voters = "..dump(modEUrn.handler.candidates.president[iCandPresName].voters)) modEUrn.handler.candidates.president[iCandPresName].voters[playername] = nil break end end modEUrn.handler.candidates.president[candidatename].voters[playername] = os.time() --Agora em milisegundos minetest.chat_send_player( playername, core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("You voted for the candidate: ") ..core.colorize("#00FF00", candidatename) ) else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("Player '%s' is not registered as a candidate for president!"):format(candidatename) ) end else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("The name '%s' is not the player name registered on the server!"):format(candidatename) ) end else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("Please enter the name of the presidential candidate you wish to vote!").."\n" ..core.colorize("#888888", "Syntaxe: ") ..core.colorize("#00FFFF", "/vote <"..modEUrn.translate("candidate_name")..">" ) ) end else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("You have not yet played the minimum number of hours to become a presidential voter. (Minimum %02d hours)"):format(modEUrn.MinPlayedHours) ) end else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN:ERRO]").." " ..modEUrn.translate("Your name is not registered as a voter.") ) end end, } end minetest.register_chatcommand( "vote", modEUrn.getPropCommCandVote() ) --############################################################################ modEUrn.getPropCommVotes = function() return { privs = {electoraljudge=true}, --params = "<".. modEUrn.translate("candidate_name")..">", description = modEUrn.translate("Displays the number of votes for each candidate!"), func = function(playername, candidatename) --modEUrn.debug("modEUrn.handler.candidates.president = "..dump(modEUrn.handler.candidates.president)) --modEUrn.debug("modEUrn.sortTableLenght(modEUrn.handler.candidates.president) = "..modEUrn.sortTableLenght(modEUrn.handler.candidates.president)) if type(modEUrn.handler.candidates.president)=="table" then local votes = {} for iCandPresName, iCandPresTable in pairs(modEUrn.handler.candidates.president) do local num = modEUrn.sortTableLenght(iCandPresTable.voters) if type(iCandPresTable.voters)=="table" and num >= 1 then votes[iCandPresName] = num --modEUrn.debug("num = "..num) end end if modEUrn.sortTableLenght(votes) >= 1 then --modEUrn.debug(dump(votes)) votes = modEUrn.unsortTableByValue(votes) --modEUrn.debug(dump(votes)) local strVotes = "" for iCandPresName, iCandPresVotes in pairs(votes) do --modEUrn.debug("modEUrn.getPropCommVotes(): iCandPresName = "..dump(iCandPresName).." | iCandPresVotes = "..dump(iCandPresVotes)) if strVotes=="" then strVotes = modEUrn.translate(" * %s : %02d votes"):format(iCandPresName, iCandPresVotes) else strVotes = strVotes.."\n"..modEUrn.translate(" * %s : %02d votes"):format(iCandPresName, iCandPresVotes) end end minetest.chat_send_player( playername, core.colorize("#00FF00", "[E-URN]").." " ..modEUrn.translate("Voting list for presidential election: ").."\n"..strVotes ) --]] else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("No one has voted in the presidential election yet!") --..core.colorize("#00FF00", candidatename) ) end else minetest.chat_send_player( playername, core.colorize("#FF0000", "[E-URN]").." " ..modEUrn.translate("There is no registered candidate for the presidential election!") --..core.colorize("#00FF00", candidatename) ) end end, } end minetest.register_chatcommand( "votes", modEUrn.getPropCommVotes() ) --############################################################################ --[[ minetest.register_chatcommand( "t", { privs = {server=true}, --params = "[<".. modEUrn.translate("political campaign")..">]", description = modEUrn.translate("Register your campaign to run for server president."), func = function(playername, param) local t = { 1, 2, ["três"] = { a = 1, b = 2, c = 3, }, 4 } table.remove(t, 2) t["três"].b = nil minetest.chat_send_all(dump2(t)) end, } ) --]]