A minetest mod for mapmaking
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
2.0KB

  1. -- Arguments
  2. -- chunk: The chunk coordinate conversion API
  3. -- audio: The audio playback API
  4. -- map_formspec: The map display API
  5. -- settings: The mod settings
  6. local chunk, audio, map_formspec, settings = ...;
  7. local MAXINT = 2147483647;
  8. minetest.register_privilege("cartographer", {
  9. description = "Allows use of the /map command to view local area maps",
  10. give_to_singleplayer = false,
  11. give_to_admin = true,
  12. });
  13. -- /map <detail> <scale> -- Displays a regional map around the player
  14. -- (Optional)detail: Specifies the map's detail level. Defaults to the highest
  15. -- available detail.
  16. -- (Optional)scale: Specifies the map's scale. Defaults to 1.
  17. minetest.register_chatcommand("map", {
  18. params = "[<detail>] [<scale>]",
  19. description = "Display a mapo of the local area",
  20. privs = { cartographer = true },
  21. func = function(name, param)
  22. local detail, scale = param:match("(%d*) (%d*)");
  23. if detail then
  24. detail = tonumber(detail);
  25. else
  26. detail = MAXINT;
  27. end
  28. if scale then
  29. scale = tonumber(scale);
  30. else
  31. scale = 1;
  32. end
  33. local player = minetest.get_player_by_name(name);
  34. local pos = player:get_pos();
  35. local player_x = math.floor((chunk.to(pos.x) / scale) + 0.5);
  36. local player_z = math.floor((chunk.to(pos.z) / scale) + 0.5);
  37. audio.play_feedback("cartographer_open_map", player);
  38. minetest.show_formspec(name, "map", map_formspec.from_coords(player_x,
  39. player_z,
  40. settings.default_size,
  41. settings.default_size,
  42. detail,
  43. scale,
  44. true));
  45. end,
  46. })