mirror of
https://gitlab.com/lunovox/e-urn.git
synced 2025-03-15 07:21:22 +00:00
[feat] código não testado.
This commit is contained in:
parent
4ca3113c2b
commit
f4e224811e
3 changed files with 145 additions and 1 deletions
41
api.lua
41
api.lua
|
@ -17,8 +17,11 @@ modEUrn.handler = {
|
|||
},
|
||||
--]]
|
||||
voters = { }, --modEUrn.handler.voters[playername]
|
||||
--month_counted = 0
|
||||
}
|
||||
|
||||
modEUrn.MinPlayedHours = tonumber(minetest.settings:get("eurn.voter.min_played_hours") or 90) -- value in hours
|
||||
|
||||
modEUrn.doSave = function()
|
||||
local file = io.open(modEUrn.urlTabela, "w")
|
||||
if file then
|
||||
|
@ -176,6 +179,31 @@ modEUrn.getPresidentCandidates = function()
|
|||
return cands
|
||||
end
|
||||
|
||||
modEUrn.doCheckPresident = function()
|
||||
--Verifica registra quem será o presidente pela maioria de voto do candidato.
|
||||
if #modEUrn.handler.candidates.president >= 1 then
|
||||
local maxVotes = 0
|
||||
local PresMaxVoted = ""
|
||||
for iCandPresName, _ in pairs(modEUrn.handler.candidates.president) do
|
||||
local numVotes = #modEUrn.handler.candidates.president[iCandPresName].voters
|
||||
if numVotes >= 1 and maxVotes < numVotes then
|
||||
maxVotes = numVotes
|
||||
PresMaxVoted = iCandPresName
|
||||
end
|
||||
end
|
||||
if PresMaxVoted~="" then
|
||||
if modEUrn.handler.elected==nil then
|
||||
modEUrn.handler.elected = { }
|
||||
end
|
||||
if modEUrn.handler.elected.president==nil then
|
||||
modEUrn.handler.elected.president = { }
|
||||
end
|
||||
modEUrn.handler.elected.president.name = PresMaxVoted
|
||||
modEUrn.handler.elected.president.when = os.time() --Agora em milisegundos
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
modEUrn.on_leaveplayer(player)
|
||||
modEUrn.doSave()
|
||||
|
@ -228,4 +256,15 @@ minetest.register_on_shutdown(function()
|
|||
--minetest.log('action',"[E-URN] "..modEUrn.translate("Saving the database from all players in the file '%s'!"):format(modEUrn.urlTabela))
|
||||
end)
|
||||
|
||||
|
||||
minetest.after(3.5, function()
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local presname = modEUrn.handler.elected.president.name
|
||||
if type(presname)=="string" and presname~="" then
|
||||
local mesAtual = os.date("%m", os.time())
|
||||
local mesChecked = os.date("%m", tonumber(modEUrn.handler.elected.president.when) or os.time())
|
||||
if mesChecked ~= mesAtual then
|
||||
modEUrn.doCheckPresident()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
|
81
commands.lua
81
commands.lua
|
@ -215,6 +215,87 @@ minetest.register_chatcommand(
|
|||
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"
|
||||
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
|
||||
if type(modEUrn.handler.candidates.president[iCandPresName].voters[playername])~="nil" then
|
||||
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:ERRO]").." "
|
||||
..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()
|
||||
)
|
||||
|
||||
|
||||
--############################################################################
|
||||
|
||||
--[[
|
||||
|
|
24
settingtypes.txt
Normal file
24
settingtypes.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
# E-URN:
|
||||
# Allows you to print the debug information of this mod on the screen.
|
||||
# Default: false
|
||||
eurn.debug (Show E-Urn Debug) bool false
|
||||
|
||||
# E-URN:
|
||||
# Whether the database will be BASE64 compressed.
|
||||
# If enabled will save database bank in file '.db64',
|
||||
# else in file '.tbl' without compression.
|
||||
# Default: true
|
||||
eurn.save_compressed (Database Compressed) bool true
|
||||
|
||||
# E-URN:
|
||||
# Minimum game time in hours to become a voter.
|
||||
# Default: 90 | Min: 0 | Max: 8760
|
||||
eurn.voter.min_played_hours (Minimum Game Hours) int 90 0 8760
|
||||
|
||||
# E-URN:
|
||||
# Time interval in seconds to check the presidential candidate with the highest number of votes.
|
||||
# WARNING: Decreasing this value too much can cause server lag.
|
||||
# Default: 1800 | Min: 300 | Max: 86400
|
||||
eurn.president.intervalcheck (Interval Check President) int 1800 300 86400
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue