1 --nether teleporters are animation based
2 --the animation must finish before the teleport is initialized
3 local hud_bg_id = nil --aether portal bg
4 local aether_cool_off_timer = 0 --use this to stop players teleporting back and forth
6 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 aether_cool_off_timer > 0 then
15 aether_cool_off_timer = aether_cool_off_timer - dtime
16 if aether_cool_off_timer <= 0 then
17 aether_cool_off_timer = 0
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 aether_cool_off_timer == 0 then
27 if init_sound == nil then
28 init_sound = minetest.sound_play("portal_initialize",{gain=0})
29 minetest.sound_fade(init_sound, 0.34, 1)
31 if hud_bg_id == nil then
32 hud_bg_id = minetest.localplayer:hud_add({
33 hud_elem_type = "image", -- see HUD element types, default "text"
34 position = {x=0.5, y=0.5},
35 name = "", -- default ""
36 scale = {x=-100, y=-100}, -- default {x=0,y=0}
37 text = "nether_portal_gui.png^[opacity:"..opacity, -- default ""
40 elseif opacity < 255 then
41 --make the hud fade in
42 opacity = opacity + (dtime*100)
44 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
47 --play heavenly sounds
49 if init_sound and node and node.name == "nether:portal" then
50 minetest.sound_fade(init_sound, -0.4, 0)
52 teleport_sound = minetest.sound_play("portal_teleported",{gain=1})
53 minetest.sound_fade(teleport_sound, -0.1, 0)
57 --player left portal before teleporting
58 if aether_cool_off_timer == 0 then
59 opacity = opacity - (dtime*100)
60 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
63 minetest.sound_fade(init_sound, -0.4, 0)
68 minetest.localplayer:hud_remove(hud_bg_id)
72 --teleport complete animation
73 elseif aether_cool_off_timer > 0 then
75 opacity = opacity - (dtime*100)
76 minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity)
79 minetest.localplayer:hud_remove(hud_bg_id)
87 minetest.localplayer:hud_remove(hud_bg_id)
92 --initialize teleport command to server
93 if hud_bg_id and aether_cool_off_timer == 0 then
94 if opacity >= 255 then
95 nether:send_all("teleport me")
96 --can't use any portal for 7 seconds
97 aether_cool_off_timer = 6 --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;)