1 --nether teleporters are animation based
2 --the animation must finish before the teleport is initialized
4 local hud_id = nil --foreground (portal)
5 local hud_bg_id = nil --black background
6 local cool_off_timer = 0 --use this to stop players teleporting back and forth
8 local teleport_sound = nil
9 minetest.register_globalstep(function(dtime)
10 if not minetest.localplayer or not minetest.camera then
13 --use this for player cooloff timer also to not overload server
14 if cool_off_timer > 0 then
15 cool_off_timer = cool_off_timer - dtime
16 if cool_off_timer <= 0 then
21 local pos = minetest.localplayer:get_pos()
24 local node = minetest.get_node_or_nil(pos)
26 if node and node.name == "nether:portal" and cool_off_timer == 0 then
27 if hud_bg_id == nil then
28 hud_bg_id = minetest.localplayer:hud_add({
29 hud_elem_type = "image", -- see HUD element types, default "text"
30 position = {x=0.5, y=0.5},
31 name = "", -- default ""
32 scale = {x=-100, y=-100}, -- default {x=0,y=0}
33 text = "darkness.png", -- default ""
35 hud_id = minetest.localplayer:hud_add({
36 hud_elem_type = "image", -- see HUD element types, default "text"
37 position = {x=0.5, y=0.5},
38 name = "", -- default ""
39 scale = {x=-1, y=-1}, -- default {x=0,y=0}
40 text = "nether_portal_gui.png", -- default ""
42 init_sound = minetest.sound_play("portal_initialize",{gain=0,pitch=math.random(70,90)/100})
43 minetest.sound_fade(init_sound, 0.34, 1)
46 --make the hud zoom in
48 local scale = minetest.localplayer:hud_get(hud_id).scale.x
50 scale = scale - ((scale/-(1/dtime))*2)
51 elseif scale < -100 then
54 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
56 elseif hud_bg_id and hud_id then
59 minetest.sound_fade(init_sound, -0.25, 0)
61 teleport_sound = minetest.sound_play("portal_teleported",{gain=1,pitch=math.random(70,90)/100})
62 minetest.sound_fade(teleport_sound, -0.1, 0)
65 --make the hud zoom out
66 local scale = minetest.localplayer:hud_get(hud_id).scale.x
68 scale = scale + ((scale/-(1/dtime))*2)
69 elseif scale > -1 then
72 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
75 minetest.localplayer:hud_remove(hud_bg_id)
76 minetest.localplayer:hud_remove(hud_id)
80 elseif hud_bg_id and hud_id then
81 minetest.localplayer:hud_remove(hud_bg_id)
82 minetest.localplayer:hud_remove(hud_id)
87 --initialize teleport command to server
88 if hud_bg_id and hud_id and cool_off_timer == 0 then
89 local scale = minetest.localplayer:hud_get(hud_id).scale.x
91 nether:send_all("teleport me")
92 --can't use any portal for 6 seconds