vindaca510

V's Variable Voice Over System v0.1

Feb 7th, 2014
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.88 KB | None | 0 0
  1.  
  2.  
  3. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  4. #                                                                              #
  5. #                       V's Variable Voice Over System                         #
  6. #                                  Version 0.1                                 #
  7. #                                                                              #
  8. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  9. #                                Written By:  V                                #
  10. #                        Last Edited: February 7, 2013                         #
  11. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  12. #                                                                              #
  13. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  14.  
  15.  
  16. #==============================================================================#
  17. #------------------------------------------------------------------------------#
  18. # ** Disclaimer                                                                #
  19. #------------------------------------------------------------------------------#
  20. #                                                                              #
  21. # This script was intended for Non-commercial use only, if you wish to use     #
  22. # this script in a commercial game please PM me at which ever site you found   #
  23. # this script. Either way please give me credit in your game script as the     #
  24. # writer of this script, and send me a PM abuot the release of the game/demo.  #
  25. #                                                                              #
  26. #------------------------------------------------------------------------------#
  27. # ** How To Use                                                                #
  28. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  29. #                                                                              #
  30. # * This script has a set-up area below and a script call.                     #
  31. #                                                                              #
  32. # * To call the voice method use this script call.                             #
  33. #      voice(Voice_Type, [Voice_Id, Voice_Id, Voice_Id, Voice_Id])             #
  34. #                                                                              #
  35. # * Check out the demo for examples.                                           #
  36. #                                                                              #
  37. #------------------------------------------------------------------------------#
  38. # ** Description                                                               #
  39. #------------------------------------------------------------------------------#
  40. #                                                                              #
  41. #  v0.1                                                                        #
  42. # ~=~=~=~                                                                      #
  43. #                                                                              #
  44. # * This sript basically acts as a voice over system(In short).                #
  45. #                                                                              #
  46. #------------------------------------------------------------------------------#
  47. #==============================================================================#
  48. #==============================================================================
  49. # ** V's Variable Voice Over System
  50. #------------------------------------------------------------------------------
  51. #  This module manages customizable features and methods.
  52. #==============================================================================
  53. module Variable_Voice_Over_System
  54. module Specs
  55. Voice_Library = {}
  56.  
  57. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  58. #                                                                              #
  59. #                           Start Customizable Area.                           #
  60. #                                                                              #
  61. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  62. #                                                                              #
  63. #                      ONLY EDIT AFTER THE EQUALS SYMBOL.                      #
  64. #                                                                              #
  65. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  66.    
  67.    
  68.   #=============================================================================
  69.   # * Folder directory for storing voices fx
  70.   #=============================================================================
  71.  
  72.   Folder_Directory = 'Audio/SE/'
  73.  
  74.   #=============================================================================
  75.   # * Voice Set-Up
  76.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77.   # ** The "Main" represents the voice type. For example, it could be a type of
  78.   # voice like raspy or sweet. It could also represent a person's name.
  79.   #
  80.   # ** The number index is for word id and randomization purposes.
  81.   # (IMPORTANT~ Make sure that no number in repeated with-in a voice type
  82.   #
  83.   # ** The ":duration" is a set in frames and controls the time in between words
  84.   # or phrases. (60 frame / 1 second)
  85.   #
  86.   # ** The ":groupe_var_id" is a Variable that will control a group of word ids.
  87.   # This could be used for gender, race, names or any other thing you can set
  88.   # a variable to.
  89.   #
  90.   # ** The ":groupe_var_value" allows you to group words within the group_var_id.
  91.   # This will allow you to mantain gender while maintianing randomization. For
  92.   # example you could use, "Guy", "Man" or "Dude" what ever you like.
  93.   #=============================================================================
  94.   # ** REMEMBER You do not have to build your library word by word. You can also
  95.   # build it by the phrase.
  96.   #=============================================================================
  97.  
  98.  
  99.   Voice_Library["Main"] = {
  100.                             1 => { :file_name => "Cow",
  101.                                    :volume => 80,
  102.                                    :pitch => 100,
  103.                                    :duration => 200,
  104.                                    :group_var_id => 1,
  105.                                    :group_var_value => 0
  106.                                   }, # <---End of Voice_ID
  107.                                  
  108.                             2 => { :file_name => "Cat",
  109.                                    :volume => 80,
  110.                                    :pitch => 100,
  111.                                    :duration => 200,
  112.                                    :group_var_id => 1,
  113.                                    :group_var_value => 1
  114.                                   }, # <---End of Voice_ID
  115.                                  
  116.                             3 => { :file_name => "Frog",
  117.                                    :volume => 80,
  118.                                    :pitch => 100,
  119.                                    :duration => 200,
  120.                                    :group_var_id => 1,
  121.                                    :group_var_value => 1
  122.                                   }, # <---End of Voice_ID
  123.                                  
  124.                             4 => { :file_name => "Crow",
  125.                                    :volume => 80,
  126.                                    :pitch => 100,
  127.                                    :duration => 200,
  128.                                    :group_var_id => 1,
  129.                                    :group_var_value => 2
  130.                                   }, # <---End of Voice_ID
  131.                                  
  132.                           } # <---End of Voice_Type
  133.  
  134.   end
  135. end
  136.  
  137. #==============================================================================
  138. # ** Game_Interpreter
  139. #------------------------------------------------------------------------------
  140. #  An interpreter for executing event commands. This class is used within the
  141. # Game_Map, Game_Troop, and Game_Event classes.
  142. #==============================================================================
  143.  
  144. class Game_Interpreter
  145.  
  146.   #--------------------------------------------------------------------------
  147.   # * Includes Module's Variables With Class
  148.   #--------------------------------------------------------------------------
  149.  
  150.   include Variable_Voice_Over_System::Specs
  151.  
  152.   #--------------------------------------------------------------------------
  153.   # * Aliasing Method: Object Initialization
  154.   #--------------------------------------------------------------------------
  155.   def voice(voice_index, voices)
  156.     new_voices = []
  157.     voice_fxs = voices
  158.     voice_fxs.size.times { |i|
  159.       var_value = $game_variables[Voice_Library[voice_index][voice_fxs[i]][:group_var_id]]
  160.       value = Voice_Library[voice_index][voice_fxs[i]][:group_var_value]
  161.       new_voices.push voice_fxs[i] if var_value == value
  162.     }
  163.     if new_voices.size < 1
  164.       voice_fxs.size.times { |i|
  165.         var = Voice_Library[voice_index][voice_fxs[i]][:group_var_id]
  166.         new_voices.push voice_fxs[i] if var != 0
  167.       }
  168.     end
  169.     if new_voices.size == 1
  170.       voice_id = new_voices[rand(new_voices.size) - 1]
  171.     else
  172.       voice_id = new_voices[0]
  173.     end
  174.     play_vfx(voice_index, voice_id)
  175.   end
  176.  
  177.   #--------------------------------------------------------------------------
  178.   # * Aliasing Method: Object Initialization
  179.   #--------------------------------------------------------------------------
  180.   def play_vfx(voice_index, voice_id)
  181.     voice_fx = Voice_Library[voice_index][voice_id]
  182.     Audio.se_play(Folder_Directory + voice_fx[:file_name], voice_fx[:volume], voice_fx[:pitch])
  183.     wait(voice_fx[:duration])
  184.   end
  185.  
  186. end
Advertisement
Add Comment
Please, Sign In to add comment