From e00be2fc4370ef43e5c9c4eacf67c084b57fd542 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sat, 5 Apr 2025 20:42:13 +0200 Subject: [PATCH] added effect to play a sound --- api/custom_functions_you_can_override.lua | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/api/custom_functions_you_can_override.lua b/api/custom_functions_you_can_override.lua index e2764f0..fdafdef 100644 --- a/api/custom_functions_you_can_override.lua +++ b/api/custom_functions_you_can_override.lua @@ -530,6 +530,7 @@ yl_speak_up.custom_functions_r_[ "set_variable_to_random_number" ] = { end } + yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = { description = "Set a variable to a random value from a list.", param1_text = "Name of the variable:", @@ -560,6 +561,66 @@ yl_speak_up.custom_functions_r_[ "set_variable_to_random_value_from_list" ] = { end } + +yl_speak_up.custom_functions_r_[ "play_sound" ] = { + description = "Plays a sound.", + param1_text = "Name of the sound(file):", + param1_desc = "How is the sound(file) called?\n".. + "It has to be provided by another mod.\n".. + "Example: default_dirt_footstep", + param2_text = "Gain:", + param2_desc = "Number between 1 and 10. Default: 10.", + param3_text = "Pitch:", + param3_desc = "Applies a pitch-shift to the sound.\n".. + "Each factor of 20 results in a pitch-shift of +12 semitones.\n".. + "Default is 10.", + param4_text = "Max hear distance:", + param4_desc = "Default: 32 m. Can be set to a value between 3 and 64.", + code = function(player, n_id, r) + if(not(r) or not(r.r_param1) or r.r_param1 == "") then + return false + end + if(not(player)) then + return false + end + local pname = player:get_player_name() + + sound_param = {} + if(r.r_param2 and r.r_param2 ~= "") then + sound_param.gain = math.floor(tonumber(r.r_param2) or 0) + if(sound_param.gain < 1 or sound_param.gain > 10) then + sound_param.gain = 10 + end + sound_param.gain = sound_param.gain / 10 + end + if(r.r_param3 and r.r_param3 ~= "") then + sound_param.pitch = math.floor(tonumber(r.r_pitch) or 0) + if(sound_param.pitch < 1) then + sound_param.pitch = 10 + end + sound_param.pitch = sound_param.pitch / 10 + end + if(r.r_param4 and r.r_param4 ~= "") then + sound_param.max_hear_distance = math.min(tonumber(r.r_pitch) or 1, 32) + if(sound_param.max_hear_distance < 3) then + sound_param.max_hear_distance = 3 + end + if(sound_param.max_hear_distance > 64) then + sound_param.max_hear_distance = 64 + end + end + sound_param.loop = false + -- located at the NPC + sound_param.object = yl_speak_up.speak_to[pname].obj + if(not(sound_param.object)) then + return false + end + -- actually play the sound + core.sound_play(r.r_param1, sound_param, true) + return true + end +} + ----------------------------------------------------------------------------- -- Custom handling of special properties -----------------------------------------------------------------------------