commands.lua 991 B

12345678910111213141516171819202122232425262728293031
  1. minetest.register_privilege("moonphase", {
  2. description = "Change the phase of the moon",
  3. give_to_singleplayer = false
  4. })
  5. minetest.register_chatcommand("moonphase", {
  6. description ="Display current moon phase",
  7. func = function(playername, param)
  8. local msg = "Current moon phase: " .. moon_phases.get_phase()
  9. .. "\nRun set_moonphase [1-8] to change this."
  10. minetest.chat_send_player(playername, msg)
  11. end
  12. })
  13. minetest.register_chatcommand("set_moonphase", {
  14. params = "<phase>",
  15. description = "Set moon phase to given value",
  16. privs = { moonphase = true },
  17. func = function(playername, param)
  18. if param == nil or param == "" then
  19. minetest.chat_send_player(playername, "Provide a number between 1 and 8")
  20. else
  21. local change = moon_phases.set_phase(param)
  22. if change then
  23. minetest.chat_send_player(playername, "Moon phase changed successfully")
  24. else
  25. minetest.chat_send_player(playername, "Invalid argument. Provide a number between 1 and 8.")
  26. end
  27. end
  28. end
  29. })