From 272de6a5dc89587c4df37463b7fb09df70313c27 Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Sat, 23 May 2020 20:12:16 -0400 Subject: [PATCH] Add music which plays during certain times of the day and night --- init.lua | 1 + music_handling.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 music_handling.lua diff --git a/init.lua b/init.lua index 5f83326..0fb0d15 100644 --- a/init.lua +++ b/init.lua @@ -27,6 +27,7 @@ function initialize_all() dofile(path.."/nether.lua") dofile(path.."/aether.lua") dofile(path.."/waila.lua") + dofile(path.."/music_handling.lua") end --we must delay initialization until the player exists in the world diff --git a/music_handling.lua b/music_handling.lua new file mode 100644 index 0000000..fbde9ce --- /dev/null +++ b/music_handling.lua @@ -0,0 +1,42 @@ +local song_playing = nil +local song_tick = 0 +local song_index = nil + +local song_table ={ + [-1] = {name="uh_oh",length=10}, + + [18900]={name="bedtime",length=22}, + [5000]={name="morning",length=15}, + [12000]={name="simple",length=36}, + [23999]={name="day",length=96} +} + +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}) + song_index = time_of_day + elseif song_playing then + song_tick = song_tick + dtime + print(song_tick) + if song_tick > song_table[song_index].length then + print("resetting the song variable") + song_playing = nil + song_index = nil + song_tick = 0 + end + end +end) +--[[ +minetest.register_on_death(function() + if not song_playing then + song_playing = song_table[-1].name + print("playing "..song_table[-1].name) + minetest.sound_play(song_table[-1].name,{gain=0.6}) + song_index = -1 + end +end) +]]-- \ No newline at end of file -- 2.44.0