]> git.lizzy.rs Git - crafter_client.git/blob - aether.lua
Overhaul client version checking
[crafter_client.git] / aether.lua
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
5 local init_sound = nil
6 local teleport_sound = nil
7 local opacity = 0
8
9 minetest.register_globalstep(function(dtime)
10         if not minetest.localplayer or not minetest.camera then
11                 return
12         end
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
18                 end
19         end
20         
21         local pos = minetest.localplayer:get_pos()
22         pos.y = pos.y + 0.1
23         
24         local node = minetest.get_node_or_nil(pos)
25         
26         if node and node.name == "aether:portal" and aether_cool_off_timer == 0 then
27                 if init_sound == nil then
28                         init_sound = minetest.sound_play("aether_teleport",{gain=0})
29                         minetest.sound_fade(init_sound, 0.34, 1)
30                 end
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 = "aether_portal_gui.png^[opacity:"..opacity,    -- default ""
38                         })
39                         
40                 elseif opacity < 255 then
41                         --make the hud fade in
42                         opacity = opacity + (dtime*100)
43                         
44                         minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
45                 end
46         elseif hud_bg_id then
47                 --play heavenly sounds
48                 
49                 if init_sound and node and node.name == "aether:portal" then
50                         minetest.sound_fade(init_sound, -0.4, 0)
51                         init_sound = nil
52                         teleport_sound = minetest.sound_play("aether_teleport_complete",{gain=1})
53                         minetest.sound_fade(teleport_sound, -0.1, 0)
54                         teleport_sound = nil
55                 end
56                 
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", "aether_portal_gui.png^[opacity:"..opacity)
61                         
62                         if init_sound then
63                                 minetest.sound_fade(init_sound, -0.4, 0)
64                                 init_sound = nil
65                         end
66                         
67                         if opacity <= 0 then
68                                 minetest.localplayer:hud_remove(hud_bg_id)
69                                 hud_bg_id = nil
70                                 opacity = 0
71                         end
72                 --teleport complete animation
73                 elseif aether_cool_off_timer > 0 then
74                 
75                         opacity = opacity  - (dtime*100)                        
76                         minetest.localplayer:hud_change(hud_bg_id, "text", "aether_portal_gui.png^[opacity:"..opacity)
77                         
78                         if opacity <= 0 then
79                                 minetest.localplayer:hud_remove(hud_bg_id)
80                                 hud_bg_id = nil
81                                 opacity = 0
82                         end
83                 else
84                         init_sound = nil
85                 end
86         elseif hud_bg_id then
87                 minetest.localplayer:hud_remove(hud_bg_id)
88                 hud_bg_id = nil
89                 opacity = 0
90         end
91         
92         --initialize teleport command to server
93         if hud_bg_id and aether_cool_off_timer == 0 then
94                 if opacity >= 255 then
95                         aether:send_all("teleport me")
96                         --can't use any portal for 7 seconds
97                         aether_cool_off_timer = 7  --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;)
98                 end
99         end
100 end)