New sound play algorithm
parent
87c467ab8b
commit
60329de407
|
@ -1,40 +1,35 @@
|
|||
math.randomseed(3)
|
||||
sound_playing = 0
|
||||
local night = {"Crickets_At_NightCombo", "horned_owl", "Wolves_Howling"}
|
||||
local day = {"bird"}
|
||||
local cave = {}
|
||||
|
||||
minetest.register_globalstep(function(time)
|
||||
local time = minetest.env:get_timeofday()
|
||||
-- minetest.chat_send_all(time .. " " .. sound_playing)
|
||||
|
||||
if sound_playing == 0 then
|
||||
sound_playing = time
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 10 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
if math.random(1, 100) > 5 then
|
||||
return
|
||||
end
|
||||
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.8 then
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
if player:getpos().y < 0 then
|
||||
--TODO uncommend this if cave sounds are added
|
||||
--minetest.sound_play(cave[math.random(1, #cave)], {to_player = player:get_player_name()})
|
||||
else
|
||||
minetest.sound_play(night[math.random(1, #night)], {to_player = player:get_player_name()})
|
||||
end
|
||||
end
|
||||
|
||||
if sound_playing > 1 and time < 0.05 then
|
||||
sound_playing = 0.05
|
||||
end
|
||||
|
||||
--random wolves & owls at night
|
||||
if time > 0.8 or time < 0.2 then
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("Wolves_Howling")
|
||||
end
|
||||
if math.random(10000) >9997 then
|
||||
minetest.sound_play("horned_owl")
|
||||
end
|
||||
end
|
||||
if time > sound_playing then
|
||||
|
||||
if time > 0.8 or time < 0.2 then
|
||||
sound_playing = time + 0.07
|
||||
minetest.sound_play("Crickets_At_NightCombo")
|
||||
|
||||
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
sound_playing = time + 0.1
|
||||
minetest.sound_play("bird")
|
||||
return true
|
||||
else
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local light = minetest.env:get_node_light(player:getpos())
|
||||
if light < 5 then
|
||||
--TODO uncommend this if cave sounds are added
|
||||
--minetest.sound_play(cave[math.random(1, #cave)], {to_player = player:get_player_name()})
|
||||
else
|
||||
minetest.sound_play(day[math.random(1, #day)], {to_player = player:get_player_name()})
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue