Simple Scriptlet

Discussion in 'RGSS3 Script Requests' started by hyde9318, Jul 20, 2012.

Thread Status:
Not open for further replies.
  1. hyde9318

    hyde9318 RMC Coordinator Veteran

    Messages:
    2,593
    Likes Received:
    680
    Location:
    Michigan, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Hello everyone. I am sure that this has probably been done before, and if it has, can you please point me in the right direction (preferable in the form of a direct URL if possible).

    I am looking for a scriptlet that will allow me to add sound to text. You may know of this being used in many RPG games. It is when text appears on screen, a short sound it played when every letter shows up on the screen. You can think of a typewriter, and how you can hear it when each letter is typed out.

    If this has to be made from scratch, there are a few little things I would like. One, I would like to be about to set the specific SE that I want to be played. Preferably, I would also like the option to set the pitch and volume of said SE. Second, the scriptlet should be compatible with YanFly's Message System Ace.

    And this is not required, but it would be cool to have one more feature. (note, I would like to be able to turn this feature on and off at will) One last feature that I would like (but do not require) would be a random pitch per letter for the SE. For instance, pitch for the first letter is 17, then 23 for the second, -13 for the third, and so forth. Then, somewhere in the script, I can set a range for the random pitch (I.E. only allow pitches -30 - 30).

    Allowing a random pitch to be played per letter would somewhat give the illusion of speech, and make text a bit less boring.

    Anyways, if you need anything or would like to ask me a question, please go right ahead.
     
    #1
  2. mobychan

    mobychan CodeMaster Veteran

    Messages:
    297
    Likes Received:
    44
    Location:
    Baden-Würrtemberg - Germany
    First Language:
    German
    I think this works, but I don't have sound here, so could you test it?

    Code:
    module TSE
    # The name of the file that will be played, must be placed in Audio/SE
    SE = "Bell1"
    # The pitch range of the file being played
    # [start_pitch, end_pitch]
    # start and end pitch can be the same to have a static pitch
    Pitch = [-30, 30]
    # The volume of the file being played
    Volume = 100
    end
    
    #==============================================================================
    # ** Sound
    #==============================================================================
    module Sound
    # System Sound Effect
    def self.play_text_se
    file = "Audio/SE/" + TSE::SE
    pitch = rand(TSE::Pitch[1] - TSE::Pitch[0]) + TSE::Pitch[0]
    p file
    p pitch
    Audio.se_play(file, TSE::Volume, pitch)
    end
    end
    
    #==============================================================================
    # ** Window_Message
    #==============================================================================
    class Window_Message < Window_Base
    #--------------------------------------------------------------------------
    # * Normal Character Processing
    #--------------------------------------------------------------------------
    def process_normal_character(c, pos)
    super
    Sound.play_text_se
    wait_for_one_character
    end
    end
    
    also, do you want to be able to change the pitch range in game or just while developing?
     
    Last edited by a moderator: Jul 20, 2012
    #2
  3. hyde9318

    hyde9318 RMC Coordinator Veteran

    Messages:
    2,593
    Likes Received:
    680
    Location:
    Michigan, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Well, it seems as though DWM2 is having nothing but YanFly and Moby scripts, lol. Thank you for this Moby, you are my hero yet again. DWM2 owes its being mostly to you.

    And just while developing. I dont care too much about changing it mid-game. Just want a sudo-voice type sound to play while people are speaking. I was testing the game earlier and a part during the opening chapter just about made me fall asleep due to silent text. I think this will really help a lot.

    EDIT: Ok, after a bit of testing, I have another Idea, sorry.

    Would it be possible to allow the choice between the script playing the sound every letter, every other letter, or every fourth letter? I am noticing that with some SEs, it sounds rather odd sometimes when played really fast and continuously. I would like to see if slower would sound better or worse.
     
    Last edited by a moderator: Jul 20, 2012
    #3
  4. mobychan

    mobychan CodeMaster Veteran

    Messages:
    297
    Likes Received:
    44
    Location:
    Baden-Würrtemberg - Germany
    First Language:
    German
    No problem ^^

    just read it and thought, "hey, that could work!" and it did work XD
     
    #4
  5. hyde9318

    hyde9318 RMC Coordinator Veteran

    Messages:
    2,593
    Likes Received:
    680
    Location:
    Michigan, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Hey sorry, I edited my post above. Didnt notice you already replied.

    And hey, you were quick. I didnt think anyone would find this til tomorrow.
     
    #5
  6. mobychan

    mobychan CodeMaster Veteran

    Messages:
    297
    Likes Received:
    44
    Location:
    Baden-Würrtemberg - Germany
    First Language:
    German
    ok, I'll look at it, thought about it just minutes ago XD
     
    #6
  7. hyde9318

    hyde9318 RMC Coordinator Veteran

    Messages:
    2,593
    Likes Received:
    680
    Location:
    Michigan, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Only other things I can think of is that YanFly's Message system allows for instant messages if you press a button, so when the message is instant, it sounds like someone just pulled a zipper, lol.

    And I have also figured out that "Cursor1" sounds probably the best, with random pitch at 150 and 175. not much of a random there, but it sounds really good.
     
    #7
  8. mobychan

    mobychan CodeMaster Veteran

    Messages:
    297
    Likes Received:
    44
    Location:
    Baden-Würrtemberg - Germany
    First Language:
    German
    ok, so here it is ^^

    you can now play the sound every x letter, x is being set in the module (Interval = x) ^^

    The instant message is a built in feature of the maker, and there won't be any sound now, when it's used ^^

    I also edited the script to use the sound and pitch you told me, so you don't have to edit that anymore ^^

    Code:
    module TSE
      # The name of the file that will be played, must be placed in Audio/SE
      SE = "Cursor1"
      # The pitch range of the file being played
      # [start_pitch, end_pitch]
      # start and end pitch can be the same to have a static pitch
      Pitch = [150, 175]
      # The volume of the file being played
      Volume = 100
      # The interval at which the sound is being played, every x characters
      Interval = 4
    end
    
    #==============================================================================
    # ** Sound
    #==============================================================================
    module Sound
      # System Sound Effect
      def self.play_text_se
        file = "Audio/SE/" + TSE::SE
        pitch = rand(TSE::Pitch[1] - TSE::Pitch[0]) + TSE::Pitch[0]
        Audio.se_play(file, TSE::Volume, pitch)
      end
    end
    
    #==============================================================================
    # ** Window_Message
    #==============================================================================
    class Window_Message < Window_Base
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      alias tse_init initialize unless $@
      def initialize
        tse_init
        @character = 0
      end
      #--------------------------------------------------------------------------
      # * Normal Character Processing
      #--------------------------------------------------------------------------
      alias tse_process_normal_character process_normal_character unless $@
      def process_normal_character(c, pos)
        tse_process_normal_character(c, pos)
        Sound.play_text_se if @character % TSE::Interval == 0 && !@line_show_fast
        p @character if @character % TSE::Interval == 0 && !@line_show_fast
        @character += 1
      end
      alias tse_process_new_page process_new_page unless $@
      #--------------------------------------------------------------------------
      # * New Page Character Processing
      #--------------------------------------------------------------------------
      def process_new_page(text, pos)
        tse_process_new_page(text, pos)
        @character = 0
      end
    end
    
     
    #8
  9. hyde9318

    hyde9318 RMC Coordinator Veteran

    Messages:
    2,593
    Likes Received:
    680
    Location:
    Michigan, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Oh... dayum... that's nice. That's just real nice. It sounds so beautiful.... *tears up*.

    I wasn't crying, I swear.

    lol. You did an awesome job. You should really slap a header on that and add it to the RGSS3 section, either here or RMP... or both. I can see this being used alot. And if you dont have time, I can do the thread for you if you just want to put a header on. Or you can, either way.

    Edit: Ok, just for shits and giggles, I tried something and it sounds AWESOME. I took a SE I had of a single piano note. Then I put the random pitch at 50 - 150. Then, interval of 2. Now my text plays songs for me, lol.
     
    Last edited by a moderator: Jul 20, 2012
    #9
  10. Mr. Bubble

    Mr. Bubble Makes stuff. Member

    Messages:
    853
    Likes Received:
    163
    Location:
    Portland, Oregon
    This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
     
    #10
Thread Status:
Not open for further replies.

Share This Page