interactions.lua 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -- ===================================================================
  2. -- Function: modpol.menu(user)
  3. -- Params: user (string)
  4. -- Q: Should this return a menu of commands relevant to the specific user?
  5. -- Output: Displays a menu of commands to the user
  6. -- TKTK currently a manually curated list---needs major improvement
  7. modpol.menu = function(user)
  8. local output = "Command list:"
  9. for key,value in pairs(chat_table) do
  10. output = output .. "/" .. key .. "\n"
  11. end
  12. return output
  13. end
  14. -- ===================================================================
  15. -- Function: modpol.binary_poll_user(user, question)
  16. -- Overwrites function at /interactions.lua
  17. -- presents a yes/no/abstain poll to a user, returns answer
  18. modpol.binary_poll_user = function(user, question)
  19. -- set up formspec
  20. local text = "Poll: " .. question
  21. local formspec = {
  22. "formspec_version[4]",
  23. "size[5,3]",
  24. "label[0.375,0.5;", minetest.formspec_escape(text), "]",
  25. "button[1,1.5;1,0.8;yes;Yes]",
  26. "button[2,1.5;1,0.8;no;No]",
  27. "button[3,1.5;1,0.8;abstain;Abstain]"
  28. --TKTK can we enable text wrapping?
  29. --TKTK we could use scroll boxes to contain the text
  30. }
  31. local formspec_string = table.concat(formspec, "")
  32. -- present to player
  33. minetest.show_formspec(user, "modpol:binary_poll", formspec_string)
  34. end
  35. --what to do
  36. minetest.register_on_player_receive_fields(function (player, formname, fields)
  37. -- modpol:poll
  38. if formname == "modpol:binary_poll" then
  39. local pname = player:get_player_name()
  40. local vote = nil
  41. if fields.yes then vote = fields.yes
  42. elseif fields.no then vote = fields.no
  43. elseif fields.abstain then vote = fields.abstain
  44. end
  45. if vote then
  46. minetest.chat_send_all(pname .. " voted " .. vote)
  47. --TKTK : we should send the message to all in that org, definately not to all players
  48. end
  49. minetest.close_formspec(pname, formname)
  50. return vote
  51. else -- if the form is not a recognized name
  52. return
  53. end
  54. end)