init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. if cloaking.is_cloaked(name) then
  20. minetest.chat_send_player(name, "# Server: You are currently cloaked! The cloak will be disabled, first.")
  21. minetest.chat_send_player(name, "# Server: The delay involved in switching invisibility systems may allow you to be briefly seen.")
  22. cloaking.toggle_cloak(name)
  23. end
  24. local player = minetest.get_player_by_name(name)
  25. if player and player:is_player() then
  26. if not gdac_invis.players[name] then
  27. gdac_invis.players[name] = {}
  28. player_labels.disable_nametag(name)
  29. player:set_nametag_attributes({color={a=0, r=0, g=0, b=0}, text=gdac_invis.gpn(name)})
  30. player:set_properties({
  31. visual_size = {x=0, y=0},
  32. makes_footstep_sound = false,
  33. -- Cannot be zero-size because otherwise player would fall through cracks.
  34. --collisionbox = {0},
  35. --selectionbox = {0},
  36. collide_with_objects = false,
  37. is_visible = false,
  38. pointable = false,
  39. show_on_minimap = false,
  40. })
  41. minetest.chat_send_player(name, "# Server: You become invisible!")
  42. else
  43. player_labels.enable_nametag(name)
  44. player:set_properties({
  45. visual_size = {x=1, y=1},
  46. makes_footstep_sound = true,
  47. collide_with_objects = true,
  48. is_visible = true,
  49. pointable = true,
  50. show_on_minimap = true,
  51. })
  52. gdac_invis.players[name] = nil
  53. minetest.chat_send_player(name, "# Server: You are now visible.")
  54. end
  55. end
  56. return true
  57. end
  58. if not gdac_invis.run_once then
  59. minetest.register_privilege("gdac_invis", {
  60. description = "Permits an admin to be invisible to other players.",
  61. give_to_singleplayer = false,
  62. })
  63. minetest.register_chatcommand("invisible", {
  64. params = "",
  65. description = "",
  66. privs = {gdac_invis=true},
  67. func = function(...)
  68. return gdac_invis.toggle_invisibility(...)
  69. end,
  70. })
  71. minetest.register_on_joinplayer(function(player)
  72. local name = player:get_player_name()
  73. gdac_invis.players[name] = nil
  74. end)
  75. -- Reloadable.
  76. local file = gdac_invis.modpath .. "/init.lua"
  77. local name = "gdac_invis:core"
  78. reload.register_file(name, file, false)
  79. gdac_invis.run_once = true
  80. end