1 local minetest,name = minetest,minetest.localplayer:get_name()
2 local aether = minetest.mod_channel_join(name..":aether_teleporters")
4 --nether teleporters are animation based
5 --the animation must finish before the teleport is initialized
6 local hud_bg_id = nil --aether portal bg
7 local aether_cool_off_timer = 0 --use this to stop players teleporting back and forth
9 local teleport_sound = nil
12 minetest.register_globalstep(function(dtime)
13 if not minetest.localplayer or not minetest.camera then
16 --use this for player cooloff timer also to not overload server
17 if aether_cool_off_timer > 0 then
18 aether_cool_off_timer = aether_cool_off_timer - dtime
19 if aether_cool_off_timer <= 0 then
20 aether_cool_off_timer = 0
24 local pos = minetest.localplayer:get_pos()
27 local node = minetest.get_node_or_nil(pos)
29 if node and node.name == "aether:portal" and aether_cool_off_timer == 0 then
30 if init_sound == nil then
31 init_sound = minetest.sound_play("aether_teleport",{gain=0})
32 minetest.sound_fade(init_sound, 0.34, 1)
34 if hud_bg_id == nil then
35 hud_bg_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=-100, y=-100}, -- default {x=0,y=0}
40 text = "aether_portal_gui.png^[opacity:"..opacity, -- default ""
43 elseif opacity < 255 then
44 --make the hud fade in
45 opacity = opacity + (dtime*100)
47 minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
50 --play heavenly sounds
52 if init_sound and node and node.name == "aether:portal" then
53 minetest.sound_fade(init_sound, -0.4, 0)
55 teleport_sound = minetest.sound_play("aether_teleport_complete",{gain=1})
56 minetest.sound_fade(teleport_sound, -0.1, 0)
60 --player left portal before teleporting
61 if aether_cool_off_timer == 0 then
62 opacity = opacity - (dtime*100)
63 minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
66 minetest.sound_fade(init_sound, -0.4, 0)
71 minetest.localplayer:hud_remove(hud_bg_id)
75 --teleport complete animation
76 elseif aether_cool_off_timer > 0 then
78 opacity = opacity - (dtime*100)
79 minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
82 minetest.localplayer:hud_remove(hud_bg_id)
90 minetest.localplayer:hud_remove(hud_bg_id)
95 --initialize teleport command to server
96 if hud_bg_id and aether_cool_off_timer == 0 then
97 if opacity >= 255 then
98 aether:send_all("teleport me")
99 --can't use any portal for 7 seconds
100 aether_cool_off_timer = 7 --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;)