Variable-based Battle Themes

Variable-Based Battle Themes
Version: 1


Introduction
This script allows developers to set battle themes depending on the value of a game variable. Useful if you want your project's battle theme changed when the player has progressed pretty far in the game.

Features
  • Set variable ID and control battle themes through the variable's value.

Screenshots
No screencaps.

Demo
No demo.

Script
If you are using my "Individual Troop Themes" script, place this script above it!

XP:
  1. =begin
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ Variable-based Battle Themes XP                                              ║
  4. ║ by PK8                                                                       ║
  5. ║ September 29th, 2009                                                         ║
  6. ║ http://rmvxp.com                                                             ║
  7. ╟──────────────────────────────────────────────────────────────────────────────╢
  8. ║ ■ Table of Contents                                                          ║
  9. ║ ├─ Author's Notes                - Line 16─18                                ║
  10. ║ ├─ Introduction & Description    - Line 20─23                                ║
  11. ║ ├─ Features                      - Line 25,26                                ║
  12. ║ ├─ How to Use                    - Line 28─36                                ║
  13. ║ ├─ Methods Aliased               - Line 38,39                                ║
  14. ║ └─ Thanks                        - Line 41─44                                ║
  15. ╟──────────────────────────────────────────────────────────────────────────────╢
  16. ║ ■ Author's Notes                                                             ║
  17. ║ After working on Individual Troop Themes, I wanted to work on this script. I ║
  18. ║ was pretty bored so yeah.                                                    ║
  19. ╟──────────────────────────────────────────────────────────────────────────────╢
  20. ║ ■ Introduction & Description                                                 ║
  21. ║ This script allows developers to set battle themes depending on the value of ║
  22. ║ a game variable. Useful if you want your project's battle theme changed when ║
  23. ║ the player has progressed pretty far in the game.                            ║
  24. ╟──────────────────────────────────────────────────────────────────────────────╢
  25. ║ ■ Features                                                                   ║
  26. ║ ─ Set variable ID and control battle themes through the variable's value.    ║
  27. ╟──────────────────────────────────────────────────────────────────────────────╢
  28. ║ ■ How to Use                                                                 ║
  29. ║ Varba_Var: Set game variable ID.                                             ║
  30. ║                                                                              ║
  31. ║ Varba_Theme[variable id value] = ["file", volume, pitch]                     ║
  32. ║ ^ Sets battle theme based on the value of the variable ID (Varba_Theme).     ║
  33. ║                                                                              ║
  34. ║ Note: If you're using Individual Troop Themes, please paste this script above║
  35. ║       Individual Troop Themes. It's so Individual Troop Themes can override  ║
  36. ║       the Variable-Based Battle Theme script.                                ║
  37. ╟──────────────────────────────────────────────────────────────────────────────╢
  38. ║ ■ Methods Aliased                                                            ║
  39. ║ ─ initialize of Spriteset_Battle                                             ║
  40. ╟──────────────────────────────────────────────────────────────────────────────╢
  41. ║ ■ Thanks                                                                     ║
  42. ║ ─ If it weren't for JoeYoung's original "Individual Troop Themes" request, I ║
  43. ║   wouldn't have worked on this script.                                       ║
  44. ║ ─ Lowell helping me out in terms of explaining this.                         ║
  45. ╚══════════════════════════════════════════════════════════════════════════════╝
  46. =end
  47.  
  48. #------------------------------------------------------------------------------
  49. # * Customise
  50. #------------------------------------------------------------------------------
  51. class PK8
  52.   Varba_Theme = {} # Do not touch this.
  53.  
  54.   Varba_Var = 1 # Set variable ID.
  55.  
  56.   # The value of Varba_Var controls the battle theme.
  57.   #          [id] = [Music File, Volume, Pitch]
  58.   Varba_Theme[1] = ["003-Battle03", 100, 100]
  59.   Varba_Theme[2] = ["009-LastBoss01", 100, 100]
  60. end
  61.  
  62. #==============================================================================
  63. # ** Spriteset_Battle
  64. #------------------------------------------------------------------------------
  65. #  This class brings together battle screen sprites. It's used within
  66. #  the Scene_Battle class.
  67. #==============================================================================
  68. class Spriteset_Battle
  69.   alias_method(:pk8_var_battle_theme_initialize, :initialize)
  70.   def initialize
  71.     pk8_var_battle_theme_initialize
  72.     start_var_battle_theme
  73.   end
  74.  
  75.   #----------------------------------------------------------------------------
  76.   # * Start Variable-based Battle Theme
  77.   #----------------------------------------------------------------------------
  78.   def start_var_battle_theme
  79.     PK8::Varba_Theme.each_key { | i |
  80.     # If Variable ID Value equals the key.
  81.     if $game_variables[PK8::Varba_Var] == i
  82.       # If specified BGM isn't nil or empty.
  83.       if PK8::Varba_Theme[i][0] != nil and !PK8::Varba_Theme[i][0].empty?
  84.         # Sets BGM volume to 100 if nil.
  85.         PK8::Varba_Theme[i][1] = 100 if PK8::Varba_Theme[i][1] == nil
  86.         # Sets BGM pitch to 100 if nil.
  87.         PK8::Varba_Theme[i][2] = 100 if PK8::Varba_Theme[i][2] == nil
  88.         # Plays BGM.
  89.         Audio.bgm_play("Audio/BGM/#{PK8::Varba_Theme[i][0]}",
  90.         PK8::Varba_Theme[i][1], PK8::Varba_Theme[i][2])
  91.       end
  92.       break
  93.     end }
  94.   end
  95. end
Expand to see the code.

VX:
  1. =begin
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ Variable-based Battle Themes VX                                              ║
  4. ║ by PK8                                                                       ║
  5. ║ September 29th, 2009                                                         ║
  6. ║ http://rmvxp.com                                                             ║
  7. ╟──────────────────────────────────────────────────────────────────────────────╢
  8. ║ ■ Table of Contents                                                          ║
  9. ║ ├─ Author's Notes                - Line 16─18                                ║
  10. ║ ├─ Introduction & Description    - Line 20─23                                ║
  11. ║ ├─ Features                      - Line 25,26                                ║
  12. ║ ├─ How to Use                    - Line 28─36                                ║
  13. ║ ├─ Methods Aliased               - Line 38,39                                ║
  14. ║ └─ Thanks                        - Line 41─44                                ║
  15. ╟──────────────────────────────────────────────────────────────────────────────╢
  16. ║ ■ Author's Notes                                                             ║
  17. ║ After working on Individual Troop Themes, I wanted to work on this script. I ║
  18. ║ was pretty bored so yeah.                                                    ║
  19. ╟──────────────────────────────────────────────────────────────────────────────╢
  20. ║ ■ Introduction & Description                                                 ║
  21. ║ This script allows developers to set battle themes depending on the value of ║
  22. ║ a game variable. Useful if you want your project's battle theme changed when ║
  23. ║ the player has progressed pretty far in the game.                            ║
  24. ╟──────────────────────────────────────────────────────────────────────────────╢
  25. ║ ■ Features                                                                   ║
  26. ║ ─ Set variable ID and control battle themes through the variable's value.    ║
  27. ╟──────────────────────────────────────────────────────────────────────────────╢
  28. ║ ■ How to Use                                                                 ║
  29. ║ Varba_Var: Set game variable ID.                                             ║
  30. ║                                                                              ║
  31. ║ Varba_Theme[variable id value] = ["file", volume, pitch]                     ║
  32. ║ ^ Sets battle theme based on the value of the variable ID (Varba_Theme).     ║
  33. ║                                                                              ║
  34. ║ Note: If you're using Individual Troop Themes, please paste this script above║
  35. ║       Individual Troop Themes. It's so Individual Troop Themes can override  ║
  36. ║       the Variable-Based Battle Theme script.                                ║
  37. ╟──────────────────────────────────────────────────────────────────────────────╢
  38. ║ ■ Methods Aliased                                                            ║
  39. ║ ─ call_battle of Scene_Map                                                   ║
  40. ╟──────────────────────────────────────────────────────────────────────────────╢
  41. ║ ■ Thanks                                                                     ║
  42. ║ ─ If it weren't for JoeYoung's original "Individual Troop Themes" request, I ║
  43. ║   wouldn't have worked on this script.                                       ║
  44. ║ ─ Lowell helping me out in terms of explaining this.                         ║
  45. ╚══════════════════════════════════════════════════════════════════════════════╝
  46. =end
  47.  
  48. #------------------------------------------------------------------------------
  49. # * Customise
  50. #------------------------------------------------------------------------------
  51. class PK8
  52.   Varba_Theme = {} # Do not touch this.
  53.  
  54.   Varba_Var = 1 # Set variable ID.
  55.  
  56.   # The value of Varba_Var controls the battle theme.
  57.   #          [id] = [Music File, Volume, Pitch]
  58.   Varba_Theme[1] = ["Battle4", 100, 100]
  59.   Varba_Theme[2] = ["Battle5", 100, 100]
  60. end
  61.  
  62. #==============================================================================
  63. # ** Scene_Map
  64. #------------------------------------------------------------------------------
  65. #  This class performs the map screen processing.
  66. #==============================================================================
  67. class Scene_Map
  68.   alias_method(:pk8_var_battle_theme_call_battle, :call_battle)
  69.   def call_battle
  70.     pk8_var_battle_theme_call_battle
  71.     start_var_battle_theme
  72.   end
  73.  
  74.   #----------------------------------------------------------------------------
  75.   # * Start Variable-based Battle Theme
  76.   #----------------------------------------------------------------------------
  77.   def start_var_battle_theme
  78.     PK8::Varba_Theme.each_key { | i |
  79.     # If Variable ID Value equals the key.
  80.     if $game_variables[PK8::Varba_Var] == i
  81.       # If specified BGM isn't nil or empty.
  82.       if PK8::Varba_Theme[i][0] != nil and !PK8::Varba_Theme[i][0].empty?
  83.         # Sets BGM volume to 100 if nil.
  84.         PK8::Varba_Theme[i][1] = 100 if PK8::Varba_Theme[i][1] == nil
  85.         # Sets BGM pitch to 100 if nil.
  86.         PK8::Varba_Theme[i][2] = 100 if PK8::Varba_Theme[i][2] == nil
  87.         # Plays BGM.
  88.         Audio.bgm_play("Audio/BGM/#{PK8::Varba_Theme[i][0]}",
  89.         PK8::Varba_Theme[i][1], PK8::Varba_Theme[i][2])
  90.       end
  91.       break
  92.     end }
  93.   end
  94. end
Expand to see the code.


Instructions
Instructions are in the script. Pretty much set the game variable ID and set battle themes based on the value of the variable ID.

FAQ
Awaiting question.

Compatibility
XP: I'm not sure if it's SDK compatible. It aliases Spriteset_Battle's initialize method.
VX: It aliases Scene_Map's call_battle method.

Credits and Thanks
If it weren't for JoeYoung's original "Individual Troop Themes" request, I wouldn't have worked on this script.
Lowell helping me out in terms of explaining this.

Author's Notes
After working on Individual Troop Themes, I wanted to work on this script. I was pretty bored so yeah.

Terms and Conditions
Credit me, please? :3
Really cool! Good job!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=68373