From 14bca085455616b20db2ce5f5aaed3dc55b6fc8b Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Tue, 26 May 2020 00:29:06 -0400 Subject: [PATCH] Make nether songs play when you enter the nether --- music_handling.lua | 20 +++++++++++-------- nether.lua | 49 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/music_handling.lua b/music_handling.lua index b16b9c1..a8291cc 100644 --- a/music_handling.lua +++ b/music_handling.lua @@ -1,23 +1,26 @@ -local song_playing = nil +song_playing = nil local song_tick = 0 -local song_index = nil - -local song_table ={ - [-1] = {name="uh_oh",length=10}, - +song_index = nil +current_song = nil +song_volume = 0.28 +song_table ={ [18900]={name="bedtime",length=22}, [5000]={name="morning",length=15}, [12000]={name="simple",length=36}, - [23999]={name="day",length=96} + [23999]={name="day",length=96}, + + [90000] = {name="nether_chime",length=16}, + [90001] = {name="the_nether",length=52}, } + minetest.register_globalstep(function(dtime) local time_of_day = math.floor((minetest.get_timeofday() * 24000)+0.5) --print(time_of_day) if song_table[time_of_day] and not song_playing then song_playing = song_table[time_of_day].name --print("playing "..song_table[time_of_day].name) - minetest.sound_play(song_table[time_of_day].name,{gain=0.3}) + current_song = minetest.sound_play(song_table[time_of_day].name,{gain=song_volume}) song_index = time_of_day elseif song_playing then song_tick = song_tick + dtime @@ -27,6 +30,7 @@ minetest.register_globalstep(function(dtime) song_playing = nil song_index = nil song_tick = 0 + current_song = nil end end end) diff --git a/nether.lua b/nether.lua index 1d58e96..9d06fdd 100644 --- a/nether.lua +++ b/nether.lua @@ -1,7 +1,7 @@ --nether teleporters are animation based --the animation must finish before the teleport is initialized local hud_bg_id = nil --aether portal bg -local aether_cool_off_timer = 0 --use this to stop players teleporting back and forth +local nether_cool_off_timer = 0 --use this to stop players teleporting back and forth local init_sound = nil local teleport_sound = nil local opacity = 0 @@ -11,10 +11,10 @@ minetest.register_globalstep(function(dtime) return end --use this for player cooloff timer also to not overload server - if aether_cool_off_timer > 0 then - aether_cool_off_timer = aether_cool_off_timer - dtime - if aether_cool_off_timer <= 0 then - aether_cool_off_timer = 0 + if nether_cool_off_timer > 0 then + nether_cool_off_timer = nether_cool_off_timer - dtime + if nether_cool_off_timer <= 0 then + nether_cool_off_timer = 0 end end @@ -23,7 +23,7 @@ minetest.register_globalstep(function(dtime) local node = minetest.get_node_or_nil(pos) - if node and node.name == "nether:portal" and aether_cool_off_timer == 0 then + if node and node.name == "nether:portal" and nether_cool_off_timer == 0 then if init_sound == nil then init_sound = minetest.sound_play("portal_initialize",{gain=0}) minetest.sound_fade(init_sound, 0.34, 1) @@ -55,7 +55,7 @@ minetest.register_globalstep(function(dtime) end --player left portal before teleporting - if aether_cool_off_timer == 0 then + if nether_cool_off_timer == 0 then opacity = opacity - (dtime*100) minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity) @@ -70,7 +70,7 @@ minetest.register_globalstep(function(dtime) opacity = 0 end --teleport complete animation - elseif aether_cool_off_timer > 0 then + elseif nether_cool_off_timer > 0 then opacity = opacity - (dtime*100) minetest.localplayer:hud_change(hud_bg_id, "text", "nether_portal_gui.png^[opacity:"..opacity) @@ -90,11 +90,40 @@ minetest.register_globalstep(function(dtime) end --initialize teleport command to server - if hud_bg_id and aether_cool_off_timer == 0 then + if hud_bg_id and nether_cool_off_timer == 0 then if opacity >= 255 then nether:send_all("teleport me") --can't use any portal for 7 seconds - aether_cool_off_timer = 6 --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;) + nether_cool_off_timer = 6 --if you read this, you'll notice the nether cool off timer is 6 and this is 7 ;) + minetest.after(1,function() + local after_newpos = minetest.localplayer:get_pos().y + if after_newpos < -10000 and after_newpos > -20000 then + --cancel old songs + if current_song then + minetest.sound_fade(current_song,-0.4,0) + end + + minetest.after(math.random(3,5)+math.random(),function() + if after_newpos < -10000 and after_newpos > -20000 then + --backup in case server lags out + if current_song then + minetest.sound_fade(current_song,-0.4,0) + end + local song = 90000+math.random(0,1) + --print(song) + song_playing = song_table[song].name + current_song = minetest.sound_play(song_table[song].name,{gain=song_volume}) + song_index = song + + end + end) + elseif song_playing and (song_index == 90000 or song_index == 90001) then + minetest.sound_fade(current_song,-0.4,0) + song_playing = nil + song_index = nil + song_tick = 0 + end + end) end end end) -- 2.44.0