]> git.lizzy.rs Git - crafter_client.git/commitdiff
Fix globalsteps to node timers
authoroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 20 Apr 2020 07:22:06 +0000 (03:22 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Mon, 20 Apr 2020 07:22:06 +0000 (03:22 -0400)
environment_effects.lua

index 16b074b6205319bb84061145c57d95d58a5d384c..8b2b6e23c9b3464b02d9e3edb46528a20dbb8398 100644 (file)
@@ -11,50 +11,64 @@ local scary_sound_player_timer = math.random(-120,0)
 local water_trickling_timer = 0
 local water_sound_handle = nil
 
-minetest.register_globalstep(function(dtime)
-       if not minetest.localplayer then
-               return
-       end
-       local vel = minetest.localplayer:get_velocity().y
-       local pos = minetest.localplayer:get_pos()
-       
-       local node = minetest.get_node_or_nil(pos)
-       if node then
-               local name = node.name
-               if name == "main:water" or name == "main:waterflow" then
-                       in_water = true
-                       if in_water == true and old_in_water == false and vel < 0 then
-                               minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
+local function splash_effect()
+       if minetest.localplayer then            
+               local vel = minetest.localplayer:get_velocity().y
+               local pos = minetest.localplayer:get_pos()
+               local node = minetest.get_node_or_nil(pos)
+               
+               if node then
+                       local name = node.name
+                       if name == "main:water" or name == "main:waterflow" then
+                               in_water = true
+                               if in_water == true and old_in_water == false and vel < 0 then
+                                       minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
+                               end
+                       else
+                               in_water = false
                        end
-               else
-                       in_water = false
                end
+               
+               old_node = node
+               old_in_water = in_water
        end
+       minetest.after(0.01, function()
+               splash_effect()
+       end)
+end
+splash_effect()
+
+
        
-       old_node = node
-       old_in_water = in_water
-       
-       
-       ---------------------------------------------
+---------------------------------------------
+
+
+local function scary_sound_timer()
        --print(scary_sound_player_timer)
        --try to play every 5-7 minutes
-       scary_sound_player_timer = scary_sound_player_timer + dtime
-       if scary_sound_player_timer > 300 then
-               scary_sound_player_timer = math.random(-120,0)
+       if minetest.localplayer then
+               local pos = minetest.localplayer:get_pos()
                pos.y = pos.y + 1.625
                local light = minetest.get_node_light(pos)
                if pos.y < 0 and light <= 13 then
                        minetest.sound_play("scary_noise",{gain=0.4,pitch=math.random(70,100)/100})
-               end     
+               end
        end
-       
-       
-       ------------------------------------------------------
-       
-       --the water trickling timer
-       water_trickling_timer = water_trickling_timer + dtime
-       if water_trickling_timer > 0.4 then
-               water_trickling_timer = 0
+       minetest.after(300+math.random(0,120), function()
+               scary_sound_timer()
+       end)
+end
+
+minetest.after(300+math.random(0,120), function()
+       scary_sound_timer()
+end)
+
+
+------------------------------------------------------
+
+local function water_trickle()
+       if minetest.localplayer then
+               local pos = minetest.localplayer:get_pos()
                local is_water_near = minetest.find_node_near(pos, 3, {"main:waterflow"})
                if is_water_near and not water_sound_handle then
                        water_sound_handle = minetest.sound_play("stream", {loop=true,gain=0})
@@ -64,4 +78,9 @@ minetest.register_globalstep(function(dtime)
                        water_sound_handle = nil
                end
        end
-end)
+       minetest.after(0.1, function()
+               water_trickle()
+       end)
+end
+
+water_trickle()