1
0
mirror of https://codeberg.org/tenplus1/ambience.git synced 2024-12-23 17:20:30 +01:00

music plays at midnight if found on server/client

This commit is contained in:
TenPlus1 2017-07-06 12:29:23 +01:00
parent dc1ad5b1c9
commit 095387c6dd
2 changed files with 48 additions and 5 deletions

View File

@ -9,6 +9,7 @@ Based on Immersive Sounds .36 mod by Neuromancer and optimized to run on servers
- 0.5 - Changed to kilbiths smaller sound files and removed canadianloon1, adjusted timings
- 0.6 - Using new find_nodes_in_area features to count nodes and speed up execution (thanks everamzah)
- 0.7 - Code tweaks and added Jungle sounds for day and night time
- 0.8 - override default water sounds for 0.4.14 dev and above, add separate gain for each sound
- 0.8 - Override default water sounds for 0.4.14 dev and above, add separate gain for each sound
- 0.9 - Plays music files on server or local client when found at midnight, files to be named "ambience_music.1.ogg" changing number each up to 9.
Code license: MIT

View File

@ -1,5 +1,5 @@
--= Ambience lite by TenPlus1 (24th December 2016)
--= Ambience lite by TenPlus1 (6th July 2017)
local max_frequency_all = 1000 -- larger number means more frequent sounds (100-2000)
local SOUNDVOLUME = 1.0
@ -11,6 +11,12 @@ minetest.override_item("default:water_flowing", { sounds = {} })
minetest.override_item("default:river_water_source", { sounds = {} })
minetest.override_item("default:river_water_flowing", { sounds = {} })
-- music settings
local music_frequency = 100
local music_handler = nil
local MUSICVOLUME = 1
local play_music = minetest.setting_getbool("ambience_music") ~= false
-- sound sets (gain defaults to 0.3 unless specifically set)
local night = {
@ -133,6 +139,27 @@ local get_ambience = function(player)
pos.y = pos.y - 0.2 -- reset pos
local tod = minetest.get_timeofday()
-- play server or local music if available
if play_music then
-- print ("-- tod", tod, music_handler)
if tod > 0.01 and tod < 0.02 then
music_handler = nil
end
-- play at midnight
if tod >= 0.0 and tod <= 0.01 and not music_handler then
music_handler = minetest.sound_play("ambience_song", {
to_player = player:get_player_name(),
gain = MUSICVOLUME
})
end
end
--= START Ambiance
if minetest.registered_nodes[nod_head]
@ -222,8 +249,6 @@ print (
return {cave = cave}
end
local tod = minetest.get_timeofday()
if tod > 0.2
and tod < 0.8 then
@ -289,6 +314,7 @@ end
-- check sounds that are not in still_playing
local still_playing = function(still_playing, player_name)
if not still_playing.cave then stop_sound(cave, player_name) end
if not still_playing.high_up then stop_sound(high_up, player_name) end
if not still_playing.beach then stop_sound(beach, player_name) end
@ -341,7 +367,7 @@ minetest.register_globalstep(function(dtime)
end
end)
-- set volume command
-- set volume commands
minetest.register_chatcommand("svol", {
params = "<svol>",
description = "set sound volume (0.1 to 1.0)",
@ -357,3 +383,19 @@ minetest.register_chatcommand("svol", {
return true, "Sound volume set to " .. SOUNDVOLUME
end,
})
minetest.register_chatcommand("mvol", {
params = "<mvol>",
description = "set music volume (0.1 to 1.0)",
privs = {server = true},
func = function(name, param)
MUSICVOLUME = tonumber(param) or MUSICVOLUME
if MUSICVOLUME < 0.1 then MUSICVOLUME = 0.1 end
if MUSICVOLUME > 1.0 then MUSICVOLUME = 1.0 end
return true, "Music volume set to " .. MUSICVOLUME
end,
})