init.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. -- MAGIC MIRROR
  2. -- by FreeGamers.org
  3. -- Based off of "Mirror of Returning" by Wuzzy and "Recall Mirror" by davidthecreator. Thank you!
  4. local magicmirror = {}
  5. -- Sets the fallback position for users with no bed spawn.
  6. -- Pull static spawn point from minetest.conf or settings.
  7. magicmirror.placeholder_pos = minetest.setting_get_pos("static_spawnpoint") or {x=0,y=0,z=0}
  8. -- Set the mana cost for teleporting
  9. magicmirror.cost_teleport = 200
  10. -- Check settings for mana cost overrides.
  11. if tonumber(minetest.settings:get("magicmirror_cost_teleport")) ~= nil then
  12. magicmirror.cost_teleport = tonumber(minetest.settings:get("magicmirror_cost_teleport"))
  13. end
  14. -- Set the magic mirror crafting recipes (Disabled here since its a drop-only item in Sara's Survival Server).
  15. --minetest.register_craft({
  16. -- output = "magic_mirror:magic_mirror",
  17. -- recipe = {
  18. -- {"default:gold_ingot", "default:diamond", "default:gold_ingot"},
  19. -- {"default:mese", "default:glass", "default:mese"},
  20. -- {"default:gold_ingot", "default:diamond", "default:gold_ingot"},
  21. -- }
  22. --})
  23. -- Check to see if the user has mana or not
  24. magicmirror.mana_check = function(player, cost)
  25. local allowed
  26. -- Mana subtract function.
  27. if mana.subtract(player:get_player_name(), cost) then
  28. allowed = true
  29. else
  30. allowed = false
  31. end
  32. return allowed
  33. end -- end function
  34. -- REGISTER THE MIRROR TOOL
  35. minetest.register_tool("magic_mirror:magic_mirror", {
  36. description = "" ..core.colorize("#35cdff","Magic Mirror\n") ..core.colorize("#FFFFFF", "Gaze deeply into the mirror to return home."),
  37. range = 0,
  38. stack_max = 1,
  39. inventory_image = "magic_mirror.png",
  40. on_use = function(itemstack,user)
  41. -- If user has the mana cost he/she can teleport.
  42. if magicmirror.mana_check(user, magicmirror.cost_teleport) then --allowed == true then
  43. -- Get the player name, current position, and bed position.
  44. local name = user:get_player_name()
  45. local firstpos = user:getpos()
  46. local rec_pos = beds.spawn[name]
  47. -- Teleporting departure effect.
  48. minetest.sound_play("magic_mirror_teleport", {pos = firstpos, gain = 0.8})
  49. for i=1,50 do
  50. minetest.add_particle({
  51. pos = firstpos,
  52. acceleration = 0,
  53. velocity = {x=math.random(-20, 20)/10, y=math.random(-20, 20)/10, z=math.random(-20, 20)/10},
  54. size = math.random(2,6),
  55. expirationtime = 3.0,
  56. collisiondetection = false,
  57. vertical = false,
  58. texture = "magic_mirror_particle.png",
  59. animation = {type="vertical_frames", aspect_w=8, aspect_h=8, length = 0.50,},
  60. glow = 30,
  61. })
  62. end
  63. -- Move the player to their bed position, else fallback to the spawn point.
  64. if rec_pos then
  65. user:set_pos(rec_pos)
  66. else
  67. user:set_pos(magicmirror.placeholder_pos)
  68. end
  69. -- Teleportation effects on arrival location.
  70. local nextpos = user:getpos()
  71. minetest.sound_play("magic_mirror_teleport", {pos = nextpos, gain = 1.0})
  72. for i=1,50 do
  73. minetest.add_particle({
  74. pos = nextpos,
  75. acceleration = 0,
  76. velocity = {x=math.random(-20, 20)/10, y=math.random(-20, 20)/10, z=math.random(-20, 20)/10},
  77. size = math.random(2,6),
  78. expirationtime = 3.0,
  79. collisiondetection = false,
  80. vertical = false,
  81. texture = "magic_mirror_particle.png",
  82. animation = {type="vertical_frames", aspect_w=8, aspect_h=8, length = 0.2,},
  83. glow = 30,
  84. })
  85. end
  86. -- User does not have enough mana, play sound effect
  87. else
  88. local firstpos = user:getpos()
  89. minetest.sound_play("bweapons_magic_pack_reload", {pos = firstpos, gain = 0.25})
  90. end -- end of "mana_check false" section.
  91. end}) -- end register tool function