Individual Troop Themes

Individual Troop Themes
Version: 1


Introduction
This script allows game makers to give a specific Troop ID their own theme song. Useful for Boss battles and other unique battles.

Features
  • Give a specific troop ID their own theme.
  • Set the song, volume and pitch.

Screenshots
No screencaps.

Demo
No demo is needed.

Script
XP
  1. =begin
  2. ╔══════════════════════════════════════════════════════════════════════════════╗
  3. ║ Individual Troop Themes XP                                                   ║
  4. ║ by PK8                                                                       ║
  5. ║ September 28th, 2009                                                         ║
  6. ║ http://rmvxp.com                                                             ║
  7. ╟──────────────────────────────────────────────────────────────────────────────╢
  8. ║ ■ Table of Contents                                                          ║
  9. ║ ├─ Author's Notes                - Line 16─18                                ║
  10. ║ ├─ Introduction & Description    - Line 20─22                                ║
  11. ║ ├─ Features                      - Line 24─26                                ║
  12. ║ ├─ How to Use                    - Line 28─30                                ║
  13. ║ ├─ Methods Aliased               - Line 32,33                                ║
  14. ║ └─ Thanks                        - Line 35,36                                ║
  15. ╟──────────────────────────────────────────────────────────────────────────────╢
  16. ║ ■ Author's Notes                                                             ║
  17. ║ This script was requested by a user in HBGames.org's IRC channel (I forgot   ║
  18. ║ his name) and I was interested in creating this script so... here you go!    ║
  19. ╟──────────────────────────────────────────────────────────────────────────────╢
  20. ║ ■ Introduction & Description                                                 ║
  21. ║ This script allows game makers to give a specific Troop ID their own theme   ║
  22. ║ song. Useful for Boss battles and other unique battles.                      ║
  23. ╟──────────────────────────────────────────────────────────────────────────────╢
  24. ║ ■ Features                                                                   ║
  25. ║ ─ Give a specific troop ID their own theme.                                  ║
  26. ║ ─ Set the song, volume and pitch.                                            ║
  27. ╟──────────────────────────────────────────────────────────────────────────────╢
  28. ║ ■ How to Use                                                                 ║
  29. ║ To give a troop ID their own battle theme, simply type this:                 ║
  30. ║ Troops_Theme[id] = ["file", volume, pitch]                                   ║
  31. ╟──────────────────────────────────────────────────────────────────────────────╢
  32. ║ ■ Methods Aliased                                                            ║
  33. ║ ─ initialize of Spriteset_Battle                                             ║
  34. ╟──────────────────────────────────────────────────────────────────────────────╢
  35. ║ ■ Thanks                                                                     ║
  36. ║ ─ JoeYoung requested something like this in the HBGames.org's IRC channel.   ║
  37. ╚══════════════════════════════════════════════════════════════════════════════╝
  38. =end
  39.  
  40. #------------------------------------------------------------------------------
  41. # * Customise
  42. #------------------------------------------------------------------------------
  43. class PK8
  44.   Troops_Theme = {} # Do not touch this.
  45.  
  46.   #          [id] = [Music File, Volume, Pitch]
  47.   Troops_Theme[1] = ["002-Battle02", 100, 100]
  48.   Troops_Theme[2] = ["009-LastBoss01", 100, 100]
  49. end
  50.  
  51. #==============================================================================
  52. # ** Spriteset_Battle
  53. #------------------------------------------------------------------------------
  54. #  This class brings together battle screen sprites. It's used within
  55. #  the Scene_Battle class.
  56. #==============================================================================
  57. class Spriteset_Battle
  58.   alias_method(:pk8_troops_theme_initialize, :initialize)
  59.   def initialize
  60.     pk8_troops_theme_initialize
  61.     start_troop_theme
  62.   end
  63.  
  64.   #----------------------------------------------------------------------------
  65.   # * Start Troop Theme
  66.   #----------------------------------------------------------------------------
  67.   def start_troop_theme
  68.     PK8::Troops_Theme.each_key { | i |
  69.     # If Troop ID equals the key.
  70.     if $game_temp.battle_troop_id == i
  71.       # If specified BGM isn't nil or empty.
  72.       if PK8::Troops_Theme[i][0] != nil and !PK8::Troops_Theme[i][0].empty?
  73.         # Sets BGM volume to 100 if nil.
  74.         PK8::Troops_Theme[i][1] = 100 if PK8::Troops_Theme[i][1] == nil
  75.         # Sets BGM pitch to 100 if nil.
  76.         PK8::Troops_Theme[i][2] = 100 if PK8::Troops_Theme[i][2] == nil
  77.         # Plays BGM.
  78.         Audio.bgm_play("Audio/BGM/#{PK8::Troops_Theme[i][0]}",
  79.         PK8::Troops_Theme[i][1], PK8::Troops_Theme[i][2])
  80.       end
  81.       break
  82.     end }
  83.   end
  84. end
Expand to see the code.

VX
  1. =begin
  2. ╔══════════════════════════════════════════════════════════════════════════════╗​
  3. ║ Individual Troop Themes VX                                                   ║
  4. ║ by PK8                                                                       ║
  5. ║ September 28th, 2009                                                         ║
  6. ║ http://rmvxp.com                                                             ║
  7. ╟──────────────────────────────────────────────────────────────────────────────╢​
  8. ║ ■ Table of Contents                                                          ║
  9. ║ ├─ Author's Notes                - Line 16─18                                ║
  10. ║ ├─ Introduction & Description    - Line 20─22                                ║
  11. ║ ├─ Features                      - Line 24─26                                ║
  12. ║ ├─ How to Use                    - Line 28─30                                ║
  13. ║ ├─ Methods Aliased               - Line 32,33                                ║
  14. ║ └─ Thanks                        - Line 35─37                                ║
  15. ╟──────────────────────────────────────────────────────────────────────────────╢​
  16. ║ ■ Author's Notes                                                             ║
  17. ║ This script was requested by a user in HBGames.org's IRC channel (I forgot   ║
  18. ║ his name) and I was interested in creating this script so... here you go!    ║
  19. ╟──────────────────────────────────────────────────────────────────────────────╢​
  20. ║ ■ Introduction & Description                                                 ║
  21. ║ This script allows game makers to give a specific Troop ID their own theme   ║
  22. ║ song. Useful for Boss battles and other unique battles.                      ║
  23. ╟──────────────────────────────────────────────────────────────────────────────╢​
  24. ║ ■ Features                                                                   ║
  25. ║ ─ Give a specific troop ID their own theme.                                  ║
  26. ║ ─ Set the song, volume and pitch.                                            ║
  27. ╟──────────────────────────────────────────────────────────────────────────────╢​
  28. ║ ■ How to Use                                                                 ║
  29. ║ To give a troop ID their own battle theme, simply type this:                 ║
  30. ║ Troops_Theme[id] = ["file", volume, pitch]                                   ║
  31. ╟──────────────────────────────────────────────────────────────────────────────╢​
  32. ║ ■ Methods Aliased                                                            ║
  33. ║ ─ call_battle of Scene_Map                                                   ║
  34. ╟──────────────────────────────────────────────────────────────────────────────╢​
  35. ║ ■ Thanks                                                                     ║
  36. ║ ─ JoeYoung requested something like this in the HBGames.org's IRC channel.   ║
  37. ║ ─ Decibel showing me how I could find the ID of the troop I'm battling.      ║
  38. ╚══════════════════════════════════════════════════════════════════════════════╝​
  39. =end
  40.  
  41. #------------------------------------------------------------------------------
  42. # * Customise
  43. #------------------------------------------------------------------------------
  44. class PK8
  45.   Troops_Theme = {} # Do not touch this.
  46.  
  47.   #          [id] = [Music File, Volume, Pitch]
  48.   Troops_Theme[1] = ["Airship", 100, 100]
  49.   Troops_Theme[2] = ["Battle10", 100, 100]
  50. end
  51.  
  52. #==============================================================================
  53. # ** Scene_Map
  54. #------------------------------------------------------------------------------
  55. #  This class performs the map screen processing.
  56. #==============================================================================
  57. class Scene_Map
  58.   alias_method(:pk8_troops_theme_call_battle, :call_battle)
  59.   def call_battle
  60.     pk8_troops_theme_call_battle
  61.     start_troop_theme
  62.   end
  63.  
  64.   #----------------------------------------------------------------------------
  65.   # * Start Troop Theme
  66.   #----------------------------------------------------------------------------
  67.   def start_troop_theme
  68.     PK8::Troops_Theme.each_key { | i |
  69.     # If Troop ID equals the key.
  70.     if $game_troop.troop.id == i
  71.       # If specified BGM isn't nil or empty.
  72.       if PK8::Troops_Theme[i][0] != nil and !PK8::Troops_Theme[i][0].empty?
  73.         # Sets BGM volume to 100 if nil.
  74.         PK8::Troops_Theme[i][1] = 100 if PK8::Troops_Theme[i][1] == nil
  75.         # Sets BGM pitch to 100 if nil.
  76.         PK8::Troops_Theme[i][2] = 100 if PK8::Troops_Theme[i][2] == nil
  77.         # Plays BGM.
  78.         Audio.bgm_play("Audio/BGM/#{PK8::Troops_Theme[i][0]}",
  79.         PK8::Troops_Theme[i][1], PK8::Troops_Theme[i][2])
  80.       end
  81.       break
  82.     end }
  83.   end
  84. end
Expand to see the code.


Instructions
Instructions are in the script.

FAQ
Awaiting question.

Compatibility
XP: I'm not sure if it's compatible with the SDK or any custom battle scripts. This script aliases Spriteset_Battle's initialize method.
VX: This script aliases Scene_Map's call_battle.

Credits and Thanks
XP/VX: JoeYoung requested something like this in HBGames.org's IRC channel.
VX: Decibel showing me how I could find the ID of the troop I'm battling. I decided to "cheat" by using instance_eval. I found a proper way.

Author's Notes
This script was requested by someone, I was interested, voila! :P

Terms and Conditions
Exclusive to RMVXP.com and HBGames.org. Credit me!
This looks great to me. If I'm not mistaken this is an old feature from RM2k or RM2k3 right? I remember missing it at the time and then never thinking about it.
This is a great script that should solve a problem that I was having thanks.

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