init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. if not minetest.global_exists("gdac_invis") then gdac_invis = {} end
  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. pova.set_modifier(player, "nametag",
  29. {color={a=0, r=0, g=0, b=0}, text=""}, "gdac_invis",
  30. {priority=1000})
  31. pova.set_modifier(player, "properties", {
  32. visual_size = {x=0, y=0},
  33. makes_footstep_sound = false,
  34. -- Cannot be zero-size because otherwise player would fall through cracks.
  35. --collisionbox = {0},
  36. --selectionbox = {0},
  37. collide_with_objects = false,
  38. is_visible = false,
  39. pointable = false,
  40. show_on_minimap = false,
  41. }, "gdac_invis", {priority=1000})
  42. minetest.chat_send_player(name, "# Server: Administrative cloak enabled.")
  43. else
  44. pova.remove_modifier(player, "nametag", "gdac_invis")
  45. pova.remove_modifier(player, "properties", "gdac_invis")
  46. gdac_invis.players[name] = nil
  47. minetest.chat_send_player(name, "# Server: Invisibility cloak disabled.")
  48. end
  49. end
  50. return true
  51. end
  52. if not gdac_invis.run_once then
  53. minetest.register_privilege("gdac_invis", {
  54. description = "Administrative invisibility mode.",
  55. give_to_singleplayer = false,
  56. })
  57. minetest.register_chatcommand("invisible", {
  58. params = "",
  59. description = "",
  60. privs = {gdac_invis=true},
  61. func = function(...)
  62. return gdac_invis.toggle_invisibility(...)
  63. end,
  64. })
  65. minetest.register_on_joinplayer(function(player)
  66. local name = player:get_player_name()
  67. gdac_invis.players[name] = nil
  68. end)
  69. -- Reloadable.
  70. local file = gdac_invis.modpath .. "/init.lua"
  71. local name = "gdac_invis:core"
  72. reload.register_file(name, file, false)
  73. gdac_invis.run_once = true
  74. end