1
0
mirror of https://codeberg.org/tenplus1/ambience.git synced 2026-01-11 19:25:25 +01:00

add induvidual sound chance values of playing

This commit is contained in:
tenplus1
2026-01-10 09:31:41 +00:00
parent b742b1b3c3
commit e05ada22bb
3 changed files with 12 additions and 8 deletions

View File

@@ -24,5 +24,5 @@ Based on Immersive Sounds .36 mod by Neuromancer and optimized to run on servers
- 1.9 - Tidy code, refactor music playing, add biome name to sound_check.
- 2.0 - Add Mineclone support, add ethereal leaf check, remove minetest.after for custom timer, add Polish translation, tweak & tidy code.
- 2.1 - Add ambience.group_total() function for easy counting of group: nodes inside a set.
- 2.2 - Adds background sounds to sets that play looped in the background while normal sounds play on top (when conditions met).
- 2.2 - Adds background sounds to sets that play looped in the background while normal sounds play on top (when conditions met), and sound chance.
Code license: MIT

10
api.txt
View File

@@ -46,10 +46,10 @@ ambience.add_set("village", {
{"name = "village_background", gain = 0.5, fade = 1.0},
},
sounds = {
{name = "dogbark", gain = 0.4, ephemeral = true}, -- quick sound effect
{name = "talking_villagers", gain = 0.3}, -- stops when out of range
{name = "chicken", gain = 0.6, ephemeral = true},
{name = "chicken", gain = 0.6, pitch = 1.2, ephemeral = true},
{name = "dogbark", gain = 0.4, ephemeral = true, chance = 7}, -- quick sound effect
{name = "talking_villagers", gain = 0.3, chance = 3}, -- stops when out of range
{name = "chicken", gain = 0.6, ephemeral = true, chance = 5},
{name = "chicken", gain = 0.6, pitch = 1.2, ephemeral = true, chance = 5},
},
sound_check = function(def)
local number = def.totals["mymod:village_sound_block"] or 0
@@ -60,7 +60,7 @@ ambience.add_set("village", {
})
ambience.add_set("windy", {
frequency = 500,
frequency = 80,
nodes = {"default:sand"},
sounds = {
{name = "wind", length = 9, gain = 0.3, fade = 1.0}, -- fade in sound

View File

@@ -275,7 +275,7 @@ if ok and not playing[pname].bg and set_def and #set_def.background > 0 then
pitch = bg_amb.pitch, fade = bg_amb.fade, loop = true
})
--print("-- bg start", playing[pname].bg)
--print("-- bg start", playing[pname].bg, set_name)
playing[pname].bg_set = set_name
end
@@ -321,6 +321,10 @@ end
number = random(#set_def.sounds) -- choose random sound from set
ambience = set_def.sounds[number] -- grab sound information
-- selected sound chance of playing from a set
if random((ambience.chance or 1)) == 1 then
-- play sound
handler = core.sound_play(ambience.name, {
to_player = pname,
@@ -330,7 +334,7 @@ end
--print ("playing... " .. ambience.name .. " (" .. chance .. " < "
-- .. sound_sets[set_name].frequency .. ") @ ", MORE_GAIN, handler)
end
if handler then
-- set what player is currently listening to if handler found