Change Vehicle Music

Hi,

This request is for a commercial project.

I'm in need of a script that will allow more control of vehicle music. Currently, we are only allowed to set one BGM per type of vehicle and use that throughout the project. But it would be great if it were possible to not change music at all, or to control the music based on location. After much searching, I've found this method that works through eventing. However, as the last post states, there is a sort of audio glitch using that method and in my opinion, it is quite an awful experience during gameplay.

I'm thinking that a script that will allow the stored data to be replaced with one of the user's choice during a script call should be fairly easy to write? Unless there is a more effective method, that's all I can think of.

Cheers.
bump
I tried looking through the default scripts to see if I can find the variable where the default vehicle BGM data is stored, but I was not able to locate anything that looked useful.

I'm thinking that maybe if this variable can be located, then a script call would be able to change the BGM when required.
In a new script slot below all others.

Code:
class Game_System  def vehicle_bgm    @vehicle_bgm || $data_system.airship.bgm  end    def vehicle_bgm=(vehicle_bgm)    @vehicle_bgm = vehicle_bgm  endendclass Game_Vehicle < Game_Character  def get_on    @driving = true    @walk_anime = true    @step_anime = true    @walking_bgm = RPG::BGM.last    if @type != :airship      system_vehicle.bgm.play    else      $game_system.vehicle_bgm.play    end  endendclass Game_Interpreter  def set_airship_bgm(name, volume = 100, pitch = 100)    $game_system.vehicle_bgm = RPG::BGM.new(name, volume, pitch)  endend
To change airship BGM during game (not while IN airship):

Code:
Script: set_airship_bgm("name"[, volume[, pitch]])
It will be saved in your save file. If you don't set it, the default airship BGM, as set in the system tab, will be used.
Thanks for your reply.

This request was actually concerning any vehicle, not just the airship.

Can this script be applied to the other vehicles as well?

Thanks.
Spoiler
class Game_System def airship_bgm @airship_bgm || $data_system.airship.bgm end def airship_bgm=(airship_bgm) @airship_bgm = airship_bgm end def ship_bgm @ship_bgm || $data_system.ship.bgm end def ship_bgm=(ship_bgm) @ship_bgm = ship_bgm end def boat_bgm @boat_bgm || $data_system.boat.bgm end def boat_bgm=(boat_bgm) @boat_bgm = boat_bgm endendclass Game_Vehicle < Game_Character def get_on @driving = true @walk_anime = true @step_anime = true @walking_bgm = RPG::BGM.last case @type when :boat $game_system.boat_bgm.play when :ship $game_system.ship_bgm.play when :airship $game_system.airship_bgm.play end endendclass Game_Interpreter def change_airship_bgm(name, volume = 100, pitch = 100) $game_system.airship_bgm = RPG::BGM.new(name, volume, pitch) end def change_ship_bgm(name, volume = 100, pitch = 100) $game_system.ship_bgm = RPG::BGM.new(name, volume, pitch) end def change_boat_bgm(name, volume = 100, pitch = 100) $game_system.boat_bgm = RPG::BGM.new(name, volume, pitch) endend
change_airship_bgm

change_ship_bgm

change_boat_bgm
I've tried testing with the boat BGM using the original format of the script call. So I'm using:

change_boat_bgm("name"[, volume[, pitch]])

Testing with BGM 'Dungeon4', that translates to:

change_boat_bgm("Dungeon4"[, 100[, 100]])

At script call, the program crashes with error:

Script 'Game_Interpreter' line 1411: SyntaxError occured.

unexpected ',', expecting ']'

change_boat_bgm("Dungeon4"[, 100[, 100]])

Edit:

I've analysed the script and this seems to work:

change_boat_bgm("Dungeon4",100,100)

Is this the correct format for the script call?

Oh, and do you require me to credit you for this?

Thanks.
The [] means it's optional. If you want to leave it as the default (100), leave it out.


So:


change_boat_bgm("Dungeon4")


will be fine.


No, you don't need to credit me.


Just add a couple of lines at the top of the script stating that I wrote it. Start them with # so they appear as comments and don't break anything.
Cheers! Thanks for your time mate. You've been very helpful.
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.

Original thread: https://forums.rpgmakerweb.com/threads/change-vehicle-music.43036/