]> git.lizzy.rs Git - crafter_client.git/blob - environment_effects.lua
Overhaul client version checking
[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 local function splash_effect()
15         if minetest.localplayer then            
16                 local vel = minetest.localplayer:get_velocity().y
17                 local pos = minetest.localplayer:get_pos()
18                 local node = minetest.get_node_or_nil(pos)
19                 
20                 if node then
21                         local name = node.name
22                         if name == "main:water" or name == "main:waterflow" then
23                                 in_water = true
24                                 if in_water == true and old_in_water == false and vel < 0 then
25                                         minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
26                                 end
27                         else
28                                 in_water = false
29                         end
30                 end
31                 
32                 old_node = node
33                 old_in_water = in_water
34         end
35         minetest.after(0.01, function()
36                 splash_effect()
37         end)
38 end
39 splash_effect()
40
41
42         
43 ---------------------------------------------
44
45
46 local function scary_sound_timer()
47         --print(scary_sound_player_timer)
48         --try to play every 5-7 minutes
49         if minetest.localplayer then
50                 local pos = minetest.localplayer:get_pos()
51                 pos.y = pos.y + 1.625
52                 local light = minetest.get_node_light(pos)
53                 if pos.y < 0 and light <= 13 then
54                         minetest.sound_play("scary_noise",{gain=0.4,pitch=math.random(70,100)/100})
55                 end
56         end
57         minetest.after(300+math.random(0,120), function()
58                 scary_sound_timer()
59         end)
60 end
61
62 minetest.after(300+math.random(0,120), function()
63         scary_sound_timer()
64 end)
65
66
67 ------------------------------------------------------
68
69 local function water_trickle()
70         if minetest.localplayer then
71                 local pos = minetest.localplayer:get_pos()
72                 local is_water_near = minetest.find_node_near(pos, 3, {"main:waterflow"})
73                 if is_water_near and not water_sound_handle then
74                         water_sound_handle = minetest.sound_play("stream", {loop=true,gain=0})
75                         minetest.sound_fade(water_sound_handle, 0.25, 0.1)
76                 elseif not is_water_near and water_sound_handle then
77                         minetest.sound_fade(water_sound_handle, -0.25, 0)
78                         water_sound_handle = nil
79                 end
80         end
81         minetest.after(0.1, function()
82                 water_trickle()
83         end)
84 end
85
86 water_trickle()