mirror of
https://codeberg.org/tenplus1/ambience.git
synced 2024-12-26 18:50:29 +01:00
tweat code
This commit is contained in:
parent
9ad6bac0cb
commit
f3f2cedd4b
5
api.txt
5
api.txt
@ -80,7 +80,7 @@ Additional Commands
|
||||
Two volume commands have been added to set sound and music volume:
|
||||
|
||||
/svol (0.1 to 1.0)
|
||||
/mvol (0.1 to 1.0) -- 0 can be used to stop music from playing when it begins
|
||||
/mvol (0.1 to 1.0) -- 0 can be used to stop music curently playing
|
||||
|
||||
|
||||
Music
|
||||
@ -88,4 +88,5 @@ Music
|
||||
|
||||
Music can be stored in the sounds folder either on server or locally and so long
|
||||
as it is named 'ambience_music.1', 'ambience_music.2' etc. then it will select
|
||||
a song randomly at midnight and play player.
|
||||
a song randomly to play every 20 minutes.
|
||||
|
||||
|
81
init.lua
81
init.lua
@ -4,8 +4,8 @@ ambience = {}
|
||||
-- settings
|
||||
local SOUNDVOLUME = 1.0
|
||||
local MUSICVOLUME = 0.6
|
||||
local MUSICINTERVAL = 60 * 20
|
||||
local play_music = minetest.settings:get_bool("ambience_music") ~= false
|
||||
local pplus = minetest.get_modpath("playerplus")
|
||||
local radius = 6
|
||||
local playing = {}
|
||||
local sound_sets = {} -- all the sounds and their settings
|
||||
@ -97,20 +97,14 @@ minetest.register_on_joinplayer(function(player)
|
||||
if player then
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
playing[name] = {music = -1}
|
||||
|
||||
local mvol, svol
|
||||
local meta = player:get_meta()
|
||||
|
||||
mvol = meta:get_string("ambience.mvol")
|
||||
svol = meta:get_string("ambience.svol")
|
||||
|
||||
mvol = tonumber(mvol) or MUSICVOLUME
|
||||
svol = tonumber(svol) or SOUNDVOLUME
|
||||
|
||||
playing[name].mvol = mvol
|
||||
playing[name].svol = svol
|
||||
playing[name] = {
|
||||
mvol = tonumber(meta:get_string("ambience.mvol")) or MUSICVOLUME,
|
||||
svol = tonumber(meta:get_string("ambience.svol")) or SOUNDVOLUME,
|
||||
music = 0,
|
||||
music_handler = nil
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
@ -126,33 +120,23 @@ end)
|
||||
-- plays music and selects sound set
|
||||
local get_ambience = function(player, tod, name)
|
||||
|
||||
-- play server or local music if music enabled and music not already playing
|
||||
if play_music
|
||||
and playing[name] and playing[name].music < 0
|
||||
and playing[name].mvol > 0 then
|
||||
-- if enabled and not already playing, play local/server music on interval check
|
||||
if play_music and playing[name] and playing[name].mvol > 0 then
|
||||
|
||||
-- count backwards
|
||||
playing[name].music = playing[name].music -1
|
||||
-- increase music interval
|
||||
playing[name].music = playing[name].music + 1
|
||||
|
||||
-- play music every 20 minutes
|
||||
if playing[name].music < -(60 * 20) then
|
||||
-- play music on interval check
|
||||
if playing[name].music > MUSICINTERVAL and playing[name].music_handler == nil then
|
||||
|
||||
playing[name].music = minetest.sound_play("ambience_music", {
|
||||
playing[name].music_handler = minetest.sound_play("ambience_music", {
|
||||
to_player = name,
|
||||
gain = playing[name].mvol
|
||||
})
|
||||
|
||||
-- reset music timer after 10 minutes
|
||||
minetest.after(60 * 10, function(name)
|
||||
|
||||
if playing[name] then
|
||||
playing[name].music = -1
|
||||
end
|
||||
end, name)
|
||||
playing[name].music = 0 -- reset interval
|
||||
end
|
||||
|
||||
--print("-- music count", playing[name].music)
|
||||
|
||||
--print("-- music timer", playing[name].music .. "/" .. MUSICINTERVAL)
|
||||
end
|
||||
|
||||
-- get foot and head level nodes at player position
|
||||
@ -160,15 +144,13 @@ local get_ambience = function(player, tod, name)
|
||||
local prop = player:get_properties()
|
||||
local eyeh = prop.eye_height or 1.47 -- eye level with fallback
|
||||
|
||||
pos.y = pos.y + eyeh
|
||||
pos.y = pos.y + eyeh -- head level
|
||||
|
||||
local nod_head = pplus and name and playerplus[name]
|
||||
and playerplus[name].nod_head or minetest.get_node(pos).name
|
||||
local nod_head = minetest.get_node(pos).name
|
||||
|
||||
pos.y = (pos.y - eyeh) + 0.2 -- foot level
|
||||
|
||||
local nod_feet = pplus and name and playerplus[name]
|
||||
and playerplus[name].nod_feet or minetest.get_node(pos).name
|
||||
local nod_feet = minetest.get_node(pos).name
|
||||
|
||||
pos.y = pos.y - 0.2 -- reset pos
|
||||
|
||||
@ -177,7 +159,7 @@ local get_ambience = function(player, tod, name)
|
||||
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
|
||||
{x = pos.x + radius, y = pos.y + radius, z = pos.z + radius}, set_nodes)
|
||||
|
||||
-- loop through sets in order and choose first that meets it's conditions
|
||||
-- loop through sets in order and choose first that meets conditions set
|
||||
for n = 1, #sound_set_order do
|
||||
|
||||
local set = sound_sets[ sound_set_order[n] ]
|
||||
@ -202,7 +184,7 @@ local get_ambience = function(player, tod, name)
|
||||
end
|
||||
end
|
||||
|
||||
return nil, nil -- ADDED
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
|
||||
@ -225,12 +207,8 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
player_name = player:get_player_name()
|
||||
|
||||
--local t1 = os.clock()
|
||||
|
||||
local set_name, MORE_GAIN = get_ambience(player, tod, player_name)
|
||||
|
||||
--print(string.format("elapsed time: %.4f\n", os.clock() - t1))
|
||||
|
||||
ok = playing[player_name] -- everything starts off ok if player found
|
||||
|
||||
-- are we playing something already?
|
||||
@ -258,9 +236,8 @@ minetest.register_globalstep(function(dtime)
|
||||
-- if chance is lower than set frequency then select set
|
||||
if ok and set_name and chance < sound_sets[set_name].frequency then
|
||||
|
||||
-- choose random sound from set
|
||||
number = random(#sound_sets[set_name].sounds)
|
||||
ambience = sound_sets[set_name].sounds[number]
|
||||
number = random(#sound_sets[set_name].sounds) -- choose random sound from set
|
||||
ambience = sound_sets[set_name].sounds[number] -- grab sound information
|
||||
|
||||
-- play sound
|
||||
handler = minetest.sound_play(ambience.name, {
|
||||
@ -342,13 +319,14 @@ minetest.register_chatcommand("mvol", {
|
||||
|
||||
local mvol = tonumber(param) or playing[name].mvol
|
||||
|
||||
-- ability to stop music by setting volume to 0
|
||||
if mvol == 0 and playing[name].music
|
||||
and playing[name].music >= 0 then
|
||||
-- stop music currently playing by setting volume to 0
|
||||
if mvol == 0 and playing[name].music_handler then
|
||||
|
||||
minetest.sound_stop(playing[name].music)
|
||||
minetest.sound_stop(playing[name].music_handler)
|
||||
|
||||
playing[name].music = -1
|
||||
playing[name].music_handler = nil
|
||||
|
||||
minetest.chat_send_player(name, S("Music stopped!"))
|
||||
end
|
||||
|
||||
if mvol < 0 then mvol = 0 end
|
||||
@ -371,3 +349,4 @@ dofile(minetest.get_modpath("ambience") .. "/soundsets.lua")
|
||||
|
||||
|
||||
print("[MOD] Ambience Lite loaded")
|
||||
|
||||
|
2
mod.conf
2
mod.conf
@ -1,5 +1,5 @@
|
||||
name = ambience
|
||||
description = Adds realistic sound effects into your world.
|
||||
depends = default
|
||||
optional_depends = fire, playerplus
|
||||
optional_depends = fire
|
||||
min_minetest_version = 5.0
|
||||
|
@ -139,7 +139,7 @@ ambience.add_set("lava", {
|
||||
})
|
||||
|
||||
else
|
||||
print ("[MOD] Ambience - found env_sounds, flowing water and lava sounds disabled.")
|
||||
print ("[MOD] Ambience - found env_sounds, using for water and lava sounds.")
|
||||
end
|
||||
|
||||
-- Only add fire sounds set if flame_sound is disabled or fire redo active
|
||||
@ -148,9 +148,7 @@ local flame_sound = minetest.settings:get_bool("flame_sound", true)
|
||||
local fire_redo = minetest.get_modpath("fire") and fire.mod and fire.mod == "redo"
|
||||
|
||||
if flame_sound and not fire_redo then
|
||||
|
||||
print ("[MOD] Ambience - fire sounds not enabled, already active in fire mod.")
|
||||
|
||||
else
|
||||
|
||||
-- Small fire sound plays when near lower than 9 flames
|
||||
@ -440,3 +438,4 @@ ambience.add_set("high_up", {
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user