• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
  • Reminder: AI-generated content is not allowed on the forums per the Rules and Regulations. Please contact us if you have any questions!
DialogueSound

Resource DialogueSound 1.0

KayDiiA

whismur
Member
Joined
Mar 30, 2021
Posts
18
KayDiiA submitted a new resource:

DialogueSound - Make your dialogue heard!

Hello everyone! I'm back with another somewhat useless Plugin, but it's something I wanted for my project, so I just did it anyway...

This script adds sound effects to text displayed during dialogue, kinda like Undertale.
I included a couple of sounds I made real quick to demonstrate, which are boopSINE and boopSQUARE

Commands:
DialogueSound.enable_sound - Which will enable the SE
DialogueSound.disable_sound - Which will disable the SE...

Read more about this resource...
 
This is one of those plugins that I wish I had 2 years ago because it's great but it would be unreasonable for me to add it to everything now nearly half-way in, haha. Seriously though, nice work and thanks for making this easy for so many people (and I might still put it in somewhere)!
 
If you wanted to make this more robust, I'd recommend adding the ability to add a command within the text itself to use a specific sound effect. Something along the lines of "\tds[boopSINE]This text uses the boopSINE sound effect, but \tds[boopSQUARE]this one's a square!" (tds stands for text dialogue sound)
 
This is one of those plugins that I wish I had 2 years ago because it's great but it would be unreasonable for me to add it to everything now nearly half-way in, haha. Seriously though, nice work and thanks for making this easy for so many people (and I might still put it in somewhere)!
Its something I really wanted for my project, to give it a unique feel. It's one of those thing I would've expected to have been made already, but I couldn't find it anywhere, so I took a few nights to work on it and decided that I don't wanna keep it to myself, I'd love to see it used in more games! So I just released it 😅 I'm always glad to help the community
 
If you wanted to make this more robust, I'd recommend adding the ability to add a command within the text itself to use a specific sound effect. Something along the lines of "\tds[boopSINE]This text uses the boopSINE sound effect, but \tds[boopSQUARE]this one's a square!" (tds stands for text dialogue sound)
You know I never thought about that. That's a great idea. Thanks for that. I'll look into doing that when I get free time
 
Would you be able to add compatibility with other plugins? cough Arcky's Region Map cough
If not all good. Gotta pick and choose I suppose, love the script regardless.
 
Would you be able to add compatibility with other plugins? cough Arcky's Region Map cough
If not all good. Gotta pick and choose I suppose, love the script regardless.
I will see what I can do! My project doesn't use that plugin, so I didn't notice it was incompatible. Thanks for letting me know!
 
Hi there, the script wasn't really working on my end, played the default SE normally, but stopped playing after trying to change the SE with DialogueSound.set_sound_effect("SE_NAME"), even if trying DialogueSound.set_sound_effect("boopSINE") made it stop playing.

I have revised the code and rewritten some stuff and got it working on my end, happy to share my findings here.
#===============================================================================
# A script that plays a Sound Effect (SE) for each letter in a message,
# similar to dialogue boxes in games like Undertale.
#
# Usage:
# DialogueSound.set_sound_effect("SE_NAME") # Use this to change the sound.
# DialogueSound.enable_sound # Enables the typing sound.
# DialogueSound.disable_sound # Disables the typing sound.
#===============================================================================
module DialogueSound
# --- Configuration ---
@sound_effect_name = "boopSINE" # Default SE file name (must exist in Audio/SE).
@sound_enabled = true

# --- Internal State ---
@sound_interval = 2
@letter_count = 0
@previous_position = 0

# Sets the interval based on player's text speed
def self.set_sound_interval
case $PokemonSystem.textspeed
when 0 then @sound_interval = 2 # Slow
when 1 then @sound_interval = 3 # Normal
when 2 then @sound_interval = 5 # Fast
else @sound_interval = 2
end
end

# Resets counters for a new message
def self.reset
@letter_count = 0
@previous_position = 0
set_sound_interval
end

# Plays the sound effect if conditions are met
def self.play_sound_effect(current_position, char)
return unless @sound_enabled
# Ignore spaces, blank characters, and control characters
return if char.strip.empty? || char == "\\" || char == "[" || char == "]"

if current_position > @previous_position
if @letter_count % @sound_interval == 0
if @sound_effect_name && !@sound_effect_name.empty?
# Play the sound with default volume (100) and pitch (100)
pbSEPlay(@sound_effect_name, 100, 100)
end
end

@letter_count += 1
@previous_position = current_position
end
end

# --- Script Commands ---

# Sets the sound file name and ensures the input string is clean.
def self.set_sound_effect(name)
# CRITICAL FIX: Use gsub to remove ALL forms of whitespace
# (spaces, tabs, newlines) from the input string.
cleaned_name = name.to_s.gsub(/[\s\n\r\t]/, "")
@sound_effect_name = cleaned_name
end

def self.enable_sound
@sound_enabled = true
end

def self.disable_sound
@sound_enabled = false
end
end

#===============================================================================
# Override for pbMessageDisplay (Hooks into the core message function)
#===============================================================================
alias original_pbMessageDisplay pbMessageDisplay
def pbMessageDisplay(msgwindow, message, letterbyletter = true, commandProc = nil)
DialogueSound.reset

original_pbMessageDisplay(msgwindow, message, letterbyletter, commandProc) do
if letterbyletter && msgwindow && msgwindow.waitcount == 0 && msgwindow.text
current_position = msgwindow.position
current_char = msgwindow.text[current_position] || ""

DialogueSound.play_sound_effect(current_position, current_char)
end

yield if block_given?
end
end
 
Back
Top