mirror of
https://gitlab.com/lunovox/e-urn.git
synced 2025-03-15 07:21:22 +00:00
[feat] Novos comandos!
This commit is contained in:
parent
6dcd29240b
commit
91c853d2bf
2 changed files with 313 additions and 44 deletions
113
api.lua
113
api.lua
|
@ -63,6 +63,119 @@ modEUrn.on_leaveplayer = function(player)
|
|||
end
|
||||
end
|
||||
|
||||
modEUrn.getPresidentName = function()
|
||||
if type(modEUrn.handler.elected.president.name)~="nil"
|
||||
and modEUrn.handler.elected.president.name ~= ""
|
||||
then
|
||||
return modEUrn.handler.elected.president.name
|
||||
end
|
||||
end
|
||||
|
||||
modEUrn.doPresident = function(playername, candidatename)
|
||||
if minetest.player_exists(candidatename) then
|
||||
local now = os.time() --Em milisegundos
|
||||
|
||||
--modEUrn.handler.elected
|
||||
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 = candidatename
|
||||
modEUrn.handler.elected.president.when = now
|
||||
|
||||
|
||||
--modEUrn.handler.candidates
|
||||
if modEUrn.handler.candidates==nil then
|
||||
modEUrn.handler.candidates = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president==nil then
|
||||
modEUrn.handler.candidates.president = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president[candidatename]==nil then
|
||||
modEUrn.handler.candidates.president[candidatename] = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president[candidatename].political_campaign==nil then
|
||||
modEUrn.handler.candidates.president[candidatename].political_campaign = "There are no campaign data about this political candidate."
|
||||
end
|
||||
if modEUrn.handler.candidates.president[candidatename].voters==nil then
|
||||
modEUrn.handler.candidates.president[candidatename].voters = { }
|
||||
end
|
||||
for _, iCandPresident in ipairs(modEUrn.handler.candidates.president) do
|
||||
if type(modEUrn.handler.candidates.president[iCandPresident].voters[playername])~="nil" then
|
||||
modEUrn.handler.candidates.president[iCandPresident].voters[playername] = nil
|
||||
end
|
||||
end
|
||||
modEUrn.handler.candidates.president[candidatename].voters[playername] = now
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(
|
||||
playername,
|
||||
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
|
||||
core.colorize("#FF0000", "[E-URN]").." "
|
||||
..modEUrn.translate("The name '%s' is not the player name registered on the server!"):format(candidatename)
|
||||
)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
modEUrn.doPresidentCandidate = function(playername, candidatename, political_campaign)
|
||||
if minetest.player_exists(candidatename) then
|
||||
local now = os.time() --Em milisegundos
|
||||
if type(political_campaign)~="string"
|
||||
or political_campaign == ""
|
||||
then
|
||||
political_campaign = "There are no campaign data about this political candidate."
|
||||
end
|
||||
|
||||
--modEUrn.handler.candidates
|
||||
if modEUrn.handler.candidates==nil then
|
||||
modEUrn.handler.candidates = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president==nil then
|
||||
modEUrn.handler.candidates.president = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president[candidatename]==nil then
|
||||
modEUrn.handler.candidates.president[candidatename] = { }
|
||||
end
|
||||
modEUrn.handler.candidates.president[candidatename].political_campaign = political_campaign
|
||||
|
||||
if modEUrn.handler.candidates.president[candidatename].voters==nil then
|
||||
modEUrn.handler.candidates.president[candidatename].voters = { }
|
||||
end
|
||||
|
||||
return true
|
||||
else
|
||||
minetest.chat_send_player(
|
||||
playername,
|
||||
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
|
||||
core.colorize("#FF0000", "[E-URN]").." "
|
||||
..modEUrn.translate("The name '%s' is not the player name registered on the server!"):format(candidatename)
|
||||
)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
modEUrn.getPresCandCampaign = function(candidatename)
|
||||
local political_campaign = "There are no campaign data about this political candidate."
|
||||
if type(modEUrn.handler.candidates.president[candidatename].political_campaign)=="string"
|
||||
and modEUrn.handler.candidates.president[candidatename].political_campaign ~= ""
|
||||
then
|
||||
political_campaign =modEUrn.handler.candidates.president[candidatename].political_campaign
|
||||
end
|
||||
return political_campaign
|
||||
end
|
||||
|
||||
modEUrn.getPresidentCandidates = function()
|
||||
local cands = { }
|
||||
for iCandPresName, iCandPresValue in pairs(modEUrn.handler.candidates.president) do
|
||||
table.insert(cands, iCandPresName)
|
||||
--cands:insert(iCandPresName)
|
||||
end
|
||||
return cands
|
||||
end
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
modEUrn.on_leaveplayer(player)
|
||||
modEUrn.doSave()
|
||||
|
|
244
commands.lua
244
commands.lua
|
@ -3,60 +3,39 @@ elected = {
|
|||
president = {
|
||||
name = "", --name of the elected candidate.
|
||||
when = 0, --when the candidate was elected.
|
||||
voters = { }, --names of voters who voted for this elected candidate.
|
||||
},
|
||||
},
|
||||
candidates = {
|
||||
president = { },
|
||||
president = {
|
||||
["cadidatename"] = {
|
||||
political_campaign = "",
|
||||
voters = { --names of voters who voted for this candidate.
|
||||
["votername"] = "when",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
--]]
|
||||
|
||||
--############################################################################
|
||||
|
||||
modEUrn.getPropCommPresident = function()
|
||||
local now = os.time() --Em milisegundos
|
||||
return {
|
||||
--privs = {electoraljudge=true},
|
||||
params = "[<".. modEUrn.translate("candidate_name")..">]",
|
||||
description = modEUrn.translate("Show or Select the presidente of the server."),
|
||||
func = function(playername, param)
|
||||
if type(param)=="string" and param~="" then
|
||||
func = function(playername, candidatename)
|
||||
if type(candidatename)=="string" and candidatename~="" then
|
||||
if minetest.get_player_privs(playername).electoraljudge then
|
||||
if minetest.player_exists(param) then
|
||||
local who = param
|
||||
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 = who
|
||||
modEUrn.handler.elected.president.when = now
|
||||
if modEUrn.handler.elected.president.voters==nil then
|
||||
modEUrn.handler.elected.president.voters = { }
|
||||
end
|
||||
modEUrn.handler.elected.president.voters[playername] = now
|
||||
|
||||
if modEUrn.handler.candidates==nil then
|
||||
modEUrn.handler.candidates = { }
|
||||
end
|
||||
if modEUrn.handler.candidates.president==nil then
|
||||
modEUrn.handler.candidates.president = { }
|
||||
end
|
||||
modEUrn.handler.candidates.president[who] = now
|
||||
|
||||
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(who)
|
||||
)
|
||||
else
|
||||
minetest.chat_send_player(
|
||||
playername,
|
||||
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
|
||||
core.colorize("#FF0000", "[E-URN]").." "
|
||||
..modEUrn.translate("The name '%s' is not the player name registered on the server!"):format(param)
|
||||
)
|
||||
end
|
||||
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,
|
||||
|
@ -70,7 +49,7 @@ modEUrn.getPropCommPresident = function()
|
|||
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.handler.elected.president.name))
|
||||
..modEUrn.translate("The president of this server is %s!"):format(dump(modEUrn.getPresidentName()))
|
||||
)
|
||||
end
|
||||
end,
|
||||
|
@ -81,8 +60,185 @@ 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 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
|
||||
|
||||
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)
|
||||
if type(candidatename)=="string" and candidatename ~= "" then
|
||||
|
||||
if minetest.player_exists(candidatename) then
|
||||
if type(modEUrn.handler.candidates.president[candidatename])=="table" then
|
||||
minetest.chat_send_player(
|
||||
playername,
|
||||
core.colorize("#00FF00", "[E-URN]").." "
|
||||
..core.colorize("#888888",
|
||||
modEUrn.translate("Candidate Name: ")
|
||||
)
|
||||
..core.colorize("#00FF00", candidatename)
|
||||
)
|
||||
local Campaign = modEUrn.getPresCandCampaign(candidatename)
|
||||
if type(Campaign)=="string" and Campaign~="" then
|
||||
minetest.chat_send_player(
|
||||
playername,
|
||||
core.colorize("#00FF00", "[E-URN]").." "
|
||||
..core.colorize("#888888",
|
||||
modEUrn.translate("Candidate Campaign: ")
|
||||
)
|
||||
..Campaign
|
||||
)
|
||||
end
|
||||
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,
|
||||
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
|
||||
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,
|
||||
--os.date("%Y-%m-%d %Hh:%Mm:%Ss", now) ..
|
||||
core.colorize("#FF0000", "[E-URN]").." "
|
||||
..modEUrn.translate("Please enter the name of the candidate you wish to display the campaign!").."\n"
|
||||
..core.colorize("#888888", "Syntaxe: ")
|
||||
..core.colorize("#00FFFF",
|
||||
"/campaign <"..modEUrn.translate("candidate_name")..">"
|
||||
)
|
||||
)
|
||||
end
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
minetest.register_chatcommand(
|
||||
"campaign",
|
||||
modEUrn.getPropCommCandCampaign()
|
||||
)
|
||||
|
||||
--############################################################################
|
||||
|
||||
--[[
|
||||
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,
|
||||
}
|
||||
)
|
||||
--]]
|
Loading…
Add table
Reference in a new issue