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 nether_id = nil --the nether incoming
7 local cool_off_timer = 0 --use this to stop players teleporting back and forth
9 local teleport_sound = nil
10 minetest.register_globalstep(function(dtime)
11 if not minetest.localplayer or not minetest.camera then
14 --use this for player cooloff timer also to not overload server
15 if cool_off_timer > 0 then
16 cool_off_timer = cool_off_timer - dtime
17 if cool_off_timer <= 0 then
22 local pos = minetest.localplayer:get_pos()
25 local node = minetest.get_node_or_nil(pos)
27 if node and node.name == "nether:portal" and cool_off_timer == 0 then
28 if hud_bg_id == nil then
29 hud_bg_id = minetest.localplayer:hud_add({
30 hud_elem_type = "image", -- see HUD element types, default "text"
31 position = {x=0.5, y=0.5},
32 name = "", -- default ""
33 scale = {x=-100, y=-100}, -- default {x=0,y=0}
34 text = "darkness.png", -- default ""
36 hud_id = minetest.localplayer:hud_add({
37 hud_elem_type = "image", -- see HUD element types, default "text"
38 position = {x=0.5, y=0.5},
39 name = "", -- default ""
40 scale = {x=-1, y=-1}, -- default {x=0,y=0}
41 text = "nether_portal_gui.png", -- default ""
43 nether_id = minetest.localplayer:hud_add({
44 hud_elem_type = "image", -- see HUD element types, default "text"
45 position = {x=0.5, y=0.5},
46 name = "", -- default ""
47 scale = {x=0, y=0}, -- default {x=0,y=0}
48 text = "darkness.png", -- default ""
50 init_sound = minetest.sound_play("portal_initialize",{gain=0,pitch=math.random(70,90)/100})
51 minetest.sound_fade(init_sound, 0.34, 1)
54 --make the hud zoom in
55 local scale = minetest.localplayer:hud_get(hud_id).scale.x
57 scale = scale - ((scale/-(1/dtime))*2)
58 elseif scale < -100 then
61 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
63 elseif hud_bg_id and hud_id then
66 minetest.sound_fade(init_sound, -0.25, 0)
68 teleport_sound = minetest.sound_play("portal_teleported",{gain=1,pitch=math.random(70,90)/100})
69 minetest.sound_fade(teleport_sound, -0.1, 0)
72 --player left portal before teleporting
73 if cool_off_timer == 0 then
74 --make the hud zoom out
75 local scale = minetest.localplayer:hud_get(hud_id).scale.x
77 scale = scale + ((scale/-(1/dtime))*2)
78 elseif scale > -1 then
81 minetest.localplayer:hud_change(hud_id, "scale", {x=scale,y=scale})
84 minetest.localplayer:hud_remove(hud_bg_id)
85 minetest.localplayer:hud_remove(hud_id)
86 minetest.localplayer:hud_remove(nether_id)
91 --teleport complete animation
93 local scale = minetest.localplayer:hud_get(nether_id).scale.x
94 if scale == 0 then scale = -1 end
96 scale = scale - ((scale/-(1/dtime))*2)
97 elseif scale < -100 then
100 minetest.localplayer:hud_change(nether_id, "scale", {x=scale,y=scale})
101 if scale == -100 then
102 minetest.localplayer:hud_remove(hud_bg_id)
103 minetest.localplayer:hud_remove(hud_id)
104 minetest.localplayer:hud_remove(nether_id)
110 elseif hud_bg_id and hud_id then
111 minetest.localplayer:hud_remove(hud_bg_id)
112 minetest.localplayer:hud_remove(hud_id)
113 minetest.localplayer:hud_remove(nether_id)
119 --initialize teleport command to server
120 if hud_bg_id and hud_id and cool_off_timer == 0 then
121 local scale = minetest.localplayer:hud_get(hud_id).scale.x
122 if scale == -100 then
123 nether:send_all("teleport me")
124 --can't use any portal for 6 seconds