2023-07-20 22:44:51 -03:00
--[[
elected = {
president = {
name = " " , --name of the elected candidate.
when = 0 , --when the candidate was elected.
} ,
} ,
candidates = {
2024-02-18 18:06:19 -03:00
president = {
[ " cadidatename " ] = {
political_campaign = " " ,
voters = { --names of voters who voted for this candidate.
[ " votername " ] = " when " ,
} ,
} ,
} ,
2023-07-20 22:44:51 -03:00
} ,
--]]
2024-02-18 18:06:19 -03:00
--############################################################################
2023-07-20 22:44:51 -03:00
modEUrn.getPropCommPresident = function ( )
return {
2024-02-16 21:28:25 -03:00
--privs = {electoraljudge=true},
params = " [< " .. modEUrn.translate ( " candidate_name " ) .. " >] " ,
description = modEUrn.translate ( " Show or Select the presidente of the server. " ) ,
2024-02-18 18:06:19 -03:00
func = function ( playername , candidatename )
if type ( candidatename ) == " string " and candidatename ~= " " then
2024-02-16 21:28:25 -03:00
if minetest.get_player_privs ( playername ) . electoraljudge then
2024-02-18 18:06:19 -03:00
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
2024-02-16 21:28:25 -03:00
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] " ) .. " "
2024-02-18 18:06:19 -03:00
.. modEUrn.translate ( " The president of this server is %s! " ) : format ( dump ( modEUrn.getPresidentName ( ) ) )
2024-02-16 21:28:25 -03:00
)
end
2023-07-20 22:44:51 -03:00
end ,
}
end
minetest.register_chatcommand (
" president " ,
modEUrn.getPropCommPresident ( )
)
2024-02-18 18:06:19 -03:00
--[[
2023-07-20 22:44:51 -03:00
minetest.register_chatcommand (
modEUrn.translate ( " president " ) ,
modEUrn.getPropCommPresident ( )
)
2024-02-18 18:06:19 -03:00
--]]
--############################################################################
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 )
2024-02-20 23:03:09 -03:00
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
2024-02-18 18:06:19 -03:00
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 )
2024-02-20 23:03:09 -03:00
modEUrn.showPresCandCampaign ( playername , candidatename )
2024-02-18 18:06:19 -03:00
end ,
}
end
minetest.register_chatcommand (
" campaign " ,
modEUrn.getPropCommCandCampaign ( )
)
2024-02-19 14:31:33 -03:00
minetest.register_chatcommand (
" candidate " ,
modEUrn.getPropCommCandCampaign ( )
)
2024-02-18 18:06:19 -03:00
2024-02-19 11:05:38 -03:00
--############################################################################
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 )
2024-02-19 11:37:52 -03:00
if type ( modEUrn.handler . voters [ playername ] ) == " table " then
2024-02-19 11:05:38 -03:00
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
2024-02-20 23:03:09 -03:00
--modEUrn.debug("iCandPresName = "..iCandPresName)
2024-02-19 11:05:38 -03:00
if type ( modEUrn.handler . candidates.president [ iCandPresName ] . voters [ playername ] ) ~= " nil " then
2024-02-20 23:03:09 -03:00
--modEUrn.debug("modEUrn.handler.candidates.president["..iCandPresName.."].voters = "..dump(modEUrn.handler.candidates.president[iCandPresName].voters))
modEUrn.handler . candidates.president [ iCandPresName ] . voters [ playername ] = nil
2024-02-19 11:05:38 -03:00
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] " ) .. " "
2024-02-20 23:03:09 -03:00
.. modEUrn.translate ( " Player '%s' is not registered as a candidate for president! " ) : format ( candidatename )
2024-02-19 11:05:38 -03:00
)
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 ,
2024-02-19 11:47:01 -03:00
core.colorize ( " #FF0000 " , " [E-URN] " ) .. " "
2024-02-19 11:05:38 -03:00
.. 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 ( )
)
2024-02-20 23:03:09 -03:00
--############################################################################
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 ( )
)
2024-02-19 11:05:38 -03:00
2024-02-18 18:06:19 -03:00
--############################################################################
--[[
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 ,
}
)
2024-02-20 23:03:09 -03:00
--]]