From e05ada22bb5d72d268a3e45f6910466f712d9273 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sat, 10 Jan 2026 09:31:41 +0000 Subject: [PATCH] add induvidual sound chance values of playing --- README.md | 2 +- api.txt | 10 +++++----- init.lua | 8 ++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index cfeadb9..3c9bd83 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/api.txt b/api.txt index f6d82fa..3718677 100644 --- a/api.txt +++ b/api.txt @@ -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 diff --git a/init.lua b/init.lua index 2740fa4..f56c7f8 100644 --- a/init.lua +++ b/init.lua @@ -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