Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Variable-based Battle Themes

PK8

Member

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:
Ruby:
<span style="color:#000080; font-style:italic;">=begin

<span style="color:#000080; font-style:italic;">╔══════════════════════════════════════════════════════════════════════════════╗

<span style="color:#000080; font-style:italic;">║ Variable-based Battle Themes XP                                              ║

<span style="color:#000080; font-style:italic;">║ by PK8                                                                       ║

<span style="color:#000080; font-style:italic;">║ September 29th, 2009                                                         ║

<span style="color:#000080; font-style:italic;">║ [url=http://rmvxp.com]http://rmvxp.com[/url]                                                             ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Table of Contents                                                          ║

<span style="color:#000080; font-style:italic;">║ ├─ Author's Notes                - Line 16─18                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Introduction & Description    - Line 20─23                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Features                      - Line 25,26                                ║

<span style="color:#000080; font-style:italic;">║ ├─ How to Use                    - Line 28─36                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Methods Aliased               - Line 38,39                                ║

<span style="color:#000080; font-style:italic;">║ └─ Thanks                        - Line 41─44                                ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Author's Notes                                                             ║

<span style="color:#000080; font-style:italic;">║ After working on Individual Troop Themes, I wanted to work on this script. I ║

<span style="color:#000080; font-style:italic;">║ was pretty bored so yeah.                                                    ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Introduction & Description                                                 ║

<span style="color:#000080; font-style:italic;">║ This script allows developers to set battle themes depending on the value of ║

<span style="color:#000080; font-style:italic;">║ a game variable. Useful if you want your project's battle theme changed when ║

<span style="color:#000080; font-style:italic;">║ the player has progressed pretty far in the game.                            ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Features                                                                   ║

<span style="color:#000080; font-style:italic;">║ ─ Set variable ID and control battle themes through the variable's value.    ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ How to Use                                                                 ║

<span style="color:#000080; font-style:italic;">║ Varba_Var: Set game variable ID.                                             ║

<span style="color:#000080; font-style:italic;">║                                                                              ║

<span style="color:#000080; font-style:italic;">║ Varba_Theme[variable id value] = ["file", volume, pitch]                     ║

<span style="color:#000080; font-style:italic;">║ ^ Sets battle theme based on the value of the variable ID (Varba_Theme).     ║

<span style="color:#000080; font-style:italic;">║                                                                              ║

<span style="color:#000080; font-style:italic;">║ Note: If you're using Individual Troop Themes, please paste this script above║

<span style="color:#000080; font-style:italic;">║       Individual Troop Themes. It's so Individual Troop Themes can override  ║

<span style="color:#000080; font-style:italic;">║       the Variable-Based Battle Theme script.                                ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Methods Aliased                                                            ║

<span style="color:#000080; font-style:italic;">║ ─ initialize of Spriteset_Battle                                             ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Thanks                                                                     ║

<span style="color:#000080; font-style:italic;">║ ─ If it weren't for JoeYoung's original "Individual Troop Themes" request, I ║

<span style="color:#000080; font-style:italic;">║   wouldn't have worked on this script.                                       ║

<span style="color:#000080; font-style:italic;">║ ─ Lowell helping me out in terms of explaining this.                         ║

<span style="color:#000080; font-style:italic;">╚══════════════════════════════════════════════════════════════════════════════╝

<span style="color:#000080; font-style:italic;">=end

 

#------------------------------------------------------------------------------

# * Customise

#------------------------------------------------------------------------------

class PK8

  Varba_Theme = {} # Do not touch this.

  

  Varba_Var = 1 # Set variable ID.

  

  # The value of Varba_Var controls the battle theme.

  #          [id] = [Music File, Volume, Pitch]

  Varba_Theme[1] = ["003-Battle03", 100, 100]

  Varba_Theme[2] = ["009-LastBoss01", 100, 100]

end

 

#==============================================================================

# ** Spriteset_Battle

#------------------------------------------------------------------------------

#  This class brings together battle screen sprites. It's used within

#  the Scene_Battle class.

#==============================================================================

class Spriteset_Battle

  alias_method(:pk8_var_battle_theme_initialize, :initialize)

  def initialize

    pk8_var_battle_theme_initialize

    start_var_battle_theme

  end

  

  #----------------------------------------------------------------------------

  # * Start Variable-based Battle Theme

  #----------------------------------------------------------------------------

  def start_var_battle_theme

    PK8::Varba_Theme.each_key { | i |

    # If Variable ID Value equals the key.

    if $game_variables[PK8::Varba_Var] == i

      # If specified BGM isn't nil or empty.

      if PK8::Varba_Theme[i][0] != nil and !PK8::Varba_Theme[i][0].empty?

        # Sets BGM volume to 100 if nil.

        PK8::Varba_Theme[i][1] = 100 if PK8::Varba_Theme[i][1] == nil

        # Sets BGM pitch to 100 if nil.

        PK8::Varba_Theme[i][2] = 100 if PK8::Varba_Theme[i][2] == nil

        # Plays BGM.

        Audio.bgm_play("Audio/BGM/#{PK8::Varba_Theme[i][0]}",

        PK8::Varba_Theme[i][1], PK8::Varba_Theme[i][2])

      end

      break 

    end }

  end

end
VX:
Ruby:
<span style="color:#000080; font-style:italic;">=begin

<span style="color:#000080; font-style:italic;">╔══════════════════════════════════════════════════════════════════════════════╗

<span style="color:#000080; font-style:italic;">║ Variable-based Battle Themes VX                                              ║

<span style="color:#000080; font-style:italic;">║ by PK8                                                                       ║

<span style="color:#000080; font-style:italic;">║ September 29th, 2009                                                         ║

<span style="color:#000080; font-style:italic;">║ [url=http://rmvxp.com]http://rmvxp.com[/url]                                                             ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Table of Contents                                                          ║

<span style="color:#000080; font-style:italic;">║ ├─ Author's Notes                - Line 16─18                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Introduction & Description    - Line 20─23                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Features                      - Line 25,26                                ║

<span style="color:#000080; font-style:italic;">║ ├─ How to Use                    - Line 28─36                                ║

<span style="color:#000080; font-style:italic;">║ ├─ Methods Aliased               - Line 38,39                                ║

<span style="color:#000080; font-style:italic;">║ └─ Thanks                        - Line 41─44                                ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Author's Notes                                                             ║

<span style="color:#000080; font-style:italic;">║ After working on Individual Troop Themes, I wanted to work on this script. I ║

<span style="color:#000080; font-style:italic;">║ was pretty bored so yeah.                                                    ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Introduction & Description                                                 ║

<span style="color:#000080; font-style:italic;">║ This script allows developers to set battle themes depending on the value of ║

<span style="color:#000080; font-style:italic;">║ a game variable. Useful if you want your project's battle theme changed when ║

<span style="color:#000080; font-style:italic;">║ the player has progressed pretty far in the game.                            ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Features                                                                   ║

<span style="color:#000080; font-style:italic;">║ ─ Set variable ID and control battle themes through the variable's value.    ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ How to Use                                                                 ║

<span style="color:#000080; font-style:italic;">║ Varba_Var: Set game variable ID.                                             ║

<span style="color:#000080; font-style:italic;">║                                                                              ║

<span style="color:#000080; font-style:italic;">║ Varba_Theme[variable id value] = ["file", volume, pitch]                     ║

<span style="color:#000080; font-style:italic;">║ ^ Sets battle theme based on the value of the variable ID (Varba_Theme).     ║

<span style="color:#000080; font-style:italic;">║                                                                              ║

<span style="color:#000080; font-style:italic;">║ Note: If you're using Individual Troop Themes, please paste this script above║

<span style="color:#000080; font-style:italic;">║       Individual Troop Themes. It's so Individual Troop Themes can override  ║

<span style="color:#000080; font-style:italic;">║       the Variable-Based Battle Theme script.                                ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Methods Aliased                                                            ║

<span style="color:#000080; font-style:italic;">║ ─ call_battle of Scene_Map                                                   ║

<span style="color:#000080; font-style:italic;">╟──────────────────────────────────────────────────────────────────────────────╢

<span style="color:#000080; font-style:italic;">║ ■ Thanks                                                                     ║

<span style="color:#000080; font-style:italic;">║ ─ If it weren't for JoeYoung's original "Individual Troop Themes" request, I ║

<span style="color:#000080; font-style:italic;">║   wouldn't have worked on this script.                                       ║

<span style="color:#000080; font-style:italic;">║ ─ Lowell helping me out in terms of explaining this.                         ║

<span style="color:#000080; font-style:italic;">╚══════════════════════════════════════════════════════════════════════════════╝

<span style="color:#000080; font-style:italic;">=end

 

#------------------------------------------------------------------------------

# * Customise

#------------------------------------------------------------------------------

class PK8

  Varba_Theme = {} # Do not touch this.

  

  Varba_Var = 1 # Set variable ID.

  

  # The value of Varba_Var controls the battle theme.

  #          [id] = [Music File, Volume, Pitch]

  Varba_Theme[1] = ["Battle4", 100, 100]

  Varba_Theme[2] = ["Battle5", 100, 100]

end

 

#==============================================================================

# ** Scene_Map

#------------------------------------------------------------------------------

#  This class performs the map screen processing.

#==============================================================================

class Scene_Map

  alias_method(:pk8_var_battle_theme_call_battle, :call_battle)

  def call_battle

    pk8_var_battle_theme_call_battle

    start_var_battle_theme

  end

  

  #----------------------------------------------------------------------------

  # * Start Variable-based Battle Theme

  #----------------------------------------------------------------------------

  def start_var_battle_theme

    PK8::Varba_Theme.each_key { | i |

    # If Variable ID Value equals the key.

    if $game_variables[PK8::Varba_Var] == i

      # If specified BGM isn't nil or empty.

      if PK8::Varba_Theme[i][0] != nil and !PK8::Varba_Theme[i][0].empty?

        # Sets BGM volume to 100 if nil.

        PK8::Varba_Theme[i][1] = 100 if PK8::Varba_Theme[i][1] == nil

        # Sets BGM pitch to 100 if nil.

        PK8::Varba_Theme[i][2] = 100 if PK8::Varba_Theme[i][2] == nil

        # Plays BGM.

        Audio.bgm_play("Audio/BGM/#{PK8::Varba_Theme[i][0]}",

        PK8::Varba_Theme[i][1], PK8::Varba_Theme[i][2])

      end

      break 

    end }

  end

end

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
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top