]> git.lizzy.rs Git - crafter_client.git/blob - environment_effects.lua
Update README.md
[crafter_client.git] / environment_effects.lua
1 local minetest,math = minetest,math
2
3 local old_node
4 local in_water = false
5 local old_in_water = false
6 --this is to check if the player is exploring a cave
7 --if exploring cave not near an open shaft then play a scary noise
8 --every 5-7 minutes
9 local scary_sound_player_timer = math.random(-120,0)
10
11
12 --this is used for the water trickling effect
13 local water_trickling_timer = 0
14 local water_sound_handle = nil
15
16 local function splash_effect()
17         if minetest.localplayer then            
18                 local vel = minetest.localplayer:get_velocity().y
19                 local pos = minetest.localplayer:get_pos()
20                 local node = minetest.get_node_or_nil(pos)
21                 
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         end
37         minetest.after(0.01, function()
38                 splash_effect()
39         end)
40 end
41 splash_effect()
42
43
44         
45 ---------------------------------------------
46
47
48 local function scary_sound_timer()
49         --print(scary_sound_player_timer)
50         --try to play every 5-7 minutes
51         if minetest.localplayer then
52                 local pos = minetest.localplayer:get_pos()
53                 pos.y = pos.y + 1.625
54                 local light = minetest.get_node_light(pos)
55                 if pos.y < 0 and light <= 13 then
56                         minetest.sound_play("scary_noise",{gain=0.4,pitch=math.random(70,100)/100})
57                 end
58         end
59         minetest.after(300+math.random(0,120), function()
60                 scary_sound_timer()
61         end)
62 end
63
64 minetest.after(300+math.random(0,120), function()
65         scary_sound_timer()
66 end)
67
68
69 ------------------------------------------------------
70
71 local function water_trickle()
72         if minetest.localplayer then
73                 local pos = minetest.localplayer:get_pos()
74                 local is_water_near = minetest.find_node_near(pos, 3, {"main:waterflow"})
75                 if is_water_near and not water_sound_handle then
76                         water_sound_handle = minetest.sound_play("stream", {loop=true,gain=0})
77                         minetest.sound_fade(water_sound_handle, 0.25, 0.1)
78                 elseif not is_water_near and water_sound_handle then
79                         minetest.sound_fade(water_sound_handle, -0.25, 0)
80                         water_sound_handle = nil
81                 end
82         end
83         minetest.after(0.1, function()
84                 water_trickle()
85         end)
86 end
87
88 water_trickle()