chat_commands.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. -- AWARDS
  2. --
  3. -- Copyright (C) 2013-2015 rubenwardy
  4. -- This program is free software; you can redistribute it and/or modify
  5. -- it under the terms of the GNU Lesser General Public License as published by
  6. -- the Free Software Foundation; either version 2.1 of the License, or
  7. -- (at your option) any later version.
  8. -- This program is distributed in the hope that it will be useful,
  9. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. -- GNU Lesser General Public License for more details.
  12. -- You should have received a copy of the GNU Lesser General Public License along
  13. -- with this program; if not, write to the Free Software Foundation, Inc.,
  14. -- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. --
  16. local S = lottachievements.gettext
  17. minetest.register_chatcommand("achievements", {
  18. params = S("[c|clear|disable|enable]"),
  19. description = S("Show, clear, disable or enable your achievements"),
  20. func = function(name, param)
  21. if param == "clear" then
  22. lottachievements.clear_player(name)
  23. minetest.chat_send_player(name,
  24. S("All your achievements and statistics have been cleared. You can now start again."))
  25. elseif param == "disable" then
  26. lottachievements.disable(name)
  27. minetest.chat_send_player(name, S("You have disabled your achievements."))
  28. elseif param == "enable" then
  29. lottachievements.enable(name)
  30. minetest.chat_send_player(name, S("You have enabled your achievements."))
  31. elseif param == "c" then
  32. lottachievements.show_to(name, name, nil, true)
  33. else
  34. lottachievements.show_to(name, name, nil, false)
  35. end
  36. end
  37. })
  38. minetest.register_chatcommand("achievement-info", {
  39. params = S("<achievement ID>"),
  40. description = S("Show details of an achievement"),
  41. func = function(name, param)
  42. local def = lottachievements.def[param]
  43. if def then
  44. minetest.chat_send_player(name, string.format(S("%s: %s"), def.title, def.description))
  45. else
  46. minetest.chat_send_player(name, S("Achievement not found."))
  47. end
  48. end
  49. })
  50. minetest.register_chatcommand("achievement-stats", {
  51. privs = {
  52. server = true
  53. },
  54. params = S("<name>"),
  55. description = S("Get the achievements statistics for the given player or yourself"),
  56. func = function(name, param)
  57. if not param or param == "" then
  58. param = name
  59. end
  60. minetest.chat_send_player(name, param)
  61. local player = lottachievements.player(param)
  62. minetest.chat_send_player(name, dump(player))
  63. end
  64. })