added effect to play a sound

This commit is contained in:
Sokomine 2025-04-05 20:42:13 +02:00
parent 710c8e1928
commit e00be2fc43

View File

@ -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
-----------------------------------------------------------------------------