*Reorganized code so that further expansion is possible in a very organized manner.
*modpol.add_member() -- added a check if the member is already a member of that organized *storage -- fixed bug by moving storageref to top of file *added on_joinplayer to add players to instance *moved minetest specific code in init.lua to modpol_minetest, organized in folders. All overrides in one folder, all chatcommands in another, the on_joinplayer in modpol_minetest/orgs/instance.lua
This commit is contained in:
44
modpol_minetest/overrides/interactions/interactions.lua
Normal file
44
modpol_minetest/overrides/interactions/interactions.lua
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
|
||||
-- ===================================================================
|
||||
-- Function: modpol.binary_poll_user(user, question)
|
||||
-- Overwrites function at /interactions.lua
|
||||
-- presents a yes/no/abstain poll to a user, returns answer
|
||||
modpol.binary_poll_user = function(user, question)
|
||||
-- set up formspec
|
||||
local text = "Poll: " .. question
|
||||
local formspec = {
|
||||
"formspec_version[4]",
|
||||
"size[5,3]",
|
||||
"label[0.375,0.5;", minetest.formspec_escape(text), "]",
|
||||
"button[1,1.5;1,0.8;yes;Yes]",
|
||||
"button[2,1.5;1,0.8;no;No]",
|
||||
"button[3,1.5;1,0.8;abstain;Abstain]"
|
||||
--TKTK can we enable text wrapping?
|
||||
--TKTK we could use scroll boxes to contain the text
|
||||
}
|
||||
local formspec_string = table.concat(formspec, "")
|
||||
-- present to player
|
||||
minetest.show_formspec(user, "modpol:binary_poll", formspec_string)
|
||||
end
|
||||
|
||||
--what to do
|
||||
minetest.register_on_player_receive_fields(function (player, formname, fields)
|
||||
-- modpol:poll
|
||||
if formname == "modpol:binary_poll" then
|
||||
local pname = player:get_player_name()
|
||||
local vote = nil
|
||||
if fields.yes then vote = fields.yes
|
||||
elseif fields.no then vote = fields.no
|
||||
elseif fields.abstain then vote = fields.abstain
|
||||
end
|
||||
if vote then
|
||||
minetest.chat_send_all(pname .. " voted " .. vote)
|
||||
--TKTK : we should send the message to all in that org, definately not to all players
|
||||
end
|
||||
minetest.close_formspec(pname, formname)
|
||||
return vote
|
||||
else -- if the form is not a recognized name
|
||||
return
|
||||
end
|
||||
end)
|
Reference in New Issue
Block a user