]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add music which plays during certain times of the day and night
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 00:12:16 +0000 (20:12 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 24 May 2020 00:12:16 +0000 (20:12 -0400)
init.lua
music_handling.lua [new file with mode: 0644]

index 5f833269c54adb4e8c61aac18a1357071f6fdb3f..0fb0d1558de1d7d36177717464fddadee2dbdcff 100644 (file)
--- 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 (file)
index 0000000..fbde9ce
--- /dev/null
@@ -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