]> git.lizzy.rs Git - crafter_client.git/blob - environment_effects.lua
Make weather use timers
[crafter_client.git] / environment_effects.lua
1 local old_node
2 local in_water = false
3 local old_in_water = false
4 --this is to check if the player is exploring a cave
5 --if exploring cave not near an open shaft then play a scary noise
6 --every 5-7 minutes
7 local scary_sound_player_timer = math.random(-120,0)
8
9
10 --this is used for the water trickling effect
11 local water_trickling_timer = 0
12 local water_sound_handle = nil
13
14 minetest.register_globalstep(function(dtime)
15         if not minetest.localplayer then
16                 return
17         end
18         local vel = minetest.localplayer:get_velocity().y
19         local pos = minetest.localplayer:get_pos()
20         
21         local node = minetest.get_node_or_nil(pos)
22         if node then
23                 local name = node.name
24                 if name == "main:water" or name == "main:waterflow" then
25                         in_water = true
26                         if in_water == true and old_in_water == false and vel < 0 then
27                                 minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
28                         end
29                 else
30                         in_water = false
31                 end
32         end
33         
34         old_node = node
35         old_in_water = in_water
36         
37         
38         ---------------------------------------------
39         --print(scary_sound_player_timer)
40         --try to play every 5-7 minutes
41         scary_sound_player_timer = scary_sound_player_timer + dtime
42         if scary_sound_player_timer > 300 then
43                 scary_sound_player_timer = math.random(-120,0)
44                 pos.y = pos.y + 1.625
45                 local light = minetest.get_node_light(pos)
46                 if pos.y < 0 and light <= 13 then
47                         minetest.sound_play("scary_noise",{gain=0.4,pitch=math.random(70,100)/100})
48                 end     
49         end
50         
51         
52         ------------------------------------------------------
53         
54         --the water trickling timer
55         water_trickling_timer = water_trickling_timer + dtime
56         if water_trickling_timer > 0.4 then
57                 water_trickling_timer = 0
58                 local is_water_near = minetest.find_node_near(pos, 3, {"main:waterflow"})
59                 if is_water_near and not water_sound_handle then
60                         water_sound_handle = minetest.sound_play("stream", {loop=true,gain=0})
61                         minetest.sound_fade(water_sound_handle, 0.25, 0.1)
62                 elseif not is_water_near and water_sound_handle then
63                         minetest.sound_fade(water_sound_handle, -0.25, 0)
64                         water_sound_handle = nil
65                 end
66         end
67 end)