init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. gdac_invis = gdac_invis or {}
  2. gdac_invis.modpath = minetest.get_modpath("gdac_invis")
  3. gdac_invis.players = gdac_invis.players or {}
  4. gdac_invis.is_invisible = function(name)
  5. if gdac_invis.players[name] then
  6. return true
  7. else
  8. return false
  9. end
  10. end
  11. -- Must be called with the server-internal name of a player.
  12. function gdac_invis.gpn(pname)
  13. if gdac_invis.is_invisible(pname) then
  14. return ""
  15. end
  16. return rename.gpn(pname)
  17. end
  18. gdac_invis.toggle_invisibility = function(name, param)
  19. local player = minetest.get_player_by_name(name)
  20. if player and player:is_player() then
  21. if not gdac_invis.players[name] then
  22. gdac_invis.players[name] = {}
  23. -- Store player's current properties.
  24. local playerproperties = player:get_properties()
  25. --gdac_invis.players[name].collisionbox = playerproperties.collisionbox
  26. --player_labels.disable_nametag_broadcast(name)
  27. player:set_nametag_attributes({color={a=0, r=0, g=0, b=0}, text=gdac_invis.gpn(name)})
  28. player:set_properties({
  29. visual_size = {x=0, y=0},
  30. makes_footstep_sound = false,
  31. -- Cannot be zero-size because otherwise player would fall through cracks.
  32. --collisionbox = {0},
  33. --selectionbox = {0},
  34. collide_with_objects = false,
  35. is_visible = false,
  36. pointable = false,
  37. })
  38. minetest.chat_send_player(name, "# Server: You become invisible!")
  39. else
  40. player_labels.enable_nametag_broadcast(name)
  41. -- Restore player properties.
  42. --local collisionbox = gdac_invis.players[name].collisionbox
  43. player:set_properties({
  44. visual_size = {x=1, y=1},
  45. makes_footstep_sound = true,
  46. --collisionbox = collisionbox,
  47. collide_with_objects = true,
  48. is_visible = true,
  49. pointable = true,
  50. })
  51. gdac_invis.players[name] = nil
  52. minetest.chat_send_player(name, "# Server: You are now visible.")
  53. end
  54. end
  55. return true
  56. end
  57. if not gdac_invis.run_once then
  58. minetest.register_privilege("gdac_invis", {
  59. description = "Permits an admin to be invisible to other players.",
  60. give_to_singleplayer = false,
  61. })
  62. minetest.register_chatcommand("invisible", {
  63. params = "",
  64. description = "",
  65. privs = {gdac_invis=true},
  66. func = function(...)
  67. return gdac_invis.toggle_invisibility(...)
  68. end,
  69. })
  70. minetest.register_on_joinplayer(function(player)
  71. local name = player:get_player_name()
  72. gdac_invis.players[name] = nil
  73. end)
  74. -- Reloadable.
  75. local file = gdac_invis.modpath .. "/init.lua"
  76. local name = "gdac_invis:core"
  77. reload.register_file(name, file, false)
  78. gdac_invis.run_once = true
  79. end