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.

Play sound at beginning of battle

Script Request Template
New Script

Script Title:
Battle Start-Battle Cry

RMXP or RMVX:
RMXP

Detailed Description:
So pretty much, I would like to be able to play a sound upon entering a battle, depending on who's in the party. The script would choose a character at random (from those in the battle) and play their sound. A good example would be like final fantasy 10 when the battle began, Tidus would say something.
I would also like it to choose at random a sound file in regard to the character. So that it doesn't have the same saying every time the battle starts.

Screen shots:
Not necessary

Other Scripts I am using (in order):
Weather Script byb Ccoa
Enu SBS
Location_steps by Juan
Particle Engine by Arev
Tons of add-ons by Blizzard
Status by Fyre
Character Shadow by Sprite_Ombre
Map_location by Hunter x
Worldmap_minichars by Charlie Lee
LM by god kknows who? It doesn't say
LBL_Message System by Slipknot
Shop_Status by RPG advocate
LvlUP_Notifier by Blizzard
Blue Magic by Fomar
Heal on lvlUP (I don't know who)
Skip title by (someone?)
Custom individual battle commands by StupidStormy36
 

EOG

Member

Put this before Main
Code:
 

class Scene_Battle

  def play

    $game_system.se_play(RPG::AudioFile.new(sprintf("%s%i",$game_party.actors[rand($game_party.actors.size-1)].name,rand(3))))

  end #def

end #class

 

To play sound do this for all troops
pict.png

Sounds should be in Audio\SE folder and names are "name_of_character+number" example: "Aluxes0"
Script is set for 4 diffrent( "Aluxes0", "Aluxes1", "Aluxes2", "Aluxes3" etc.) sounds for every actor.
to change number of sounds change "rand(3)" in script to rand(x)where x is number of sounds you want +1
 
Thank you very much for the help, I'll check it out now.

It works beautifully but here's a modification I would like to see.

I would like to have a bubble animation or something appear above their head when they say their bit. Would that be possible?
 

EOG

Member

Post before Main

Code:
 

class Scene_Battle

  MP3_kbs = 128 #you set bitrate here

  def play

    actors =[]

    for actor in $game_party.actors

      next if actor.dead?

      actors << actor

    end #for

    actor = actors[rand(actors.size)]

    sound = rand(4)

    temp = actor.states.clone

    for i in 0...actor.states.size

      actor.states.pop

    end #for

    actor.states << 17 #you set number of speeking animation here

    size = File.size(sprintf("Audio/SE/%s%i.mp3",actor.name,sound))

    time = size/(MP3_kbs/8) * Graphics.frame_rate

    $game_system.se_play(RPG::AudioFile.new(sprintf("%s%i",actor.name,sound)))

    for i in 0..time

      Graphics.update

      @spriteset.update

    end #for

    Graphics.frame_count -= time

    actor.states.pop

    for i in temp

      actor.states << i

    end #for

  end #def

end #class

 
"$scene.play" is still need in every troop
To set animation that will be played you need to make new state at number 017 see image tutorial.
tutorialh.png

WARNING: 'Cause RPG Maker cannot check how long sound will be played and cannot check if it finished play you have to use 128 kb/s MP3 format(I've made a mathematical funtion that guess how long will MP3 file will be played)

EDIT: I was wrong rand(3) is only for 3 voices(0,1,2), rand(4) is 0,1,2,3
EDIT2: It has bug. Dead people talks :D I'll fix it in na hour. Will not post new post but edit this one and PM you.
EDIT3: Bug fixed.
 
Hmmm here's a small request.

I only want the animation to play one time.

After the sound plays, the battle doesn't start. It just sits there looking stupid, lol.

My sounds run a max of 4 seconds. If you could just put the time scale to 4 seconds instead of having it calculate time, it would probably be smaller and easier to handle.
 

EOG

Member

If it plays for too long you do not use mp3 128 file

Here is script that plays only for 4 secs
Code:
 

 

class Scene_Battle

  def play

    actors =[]

    for actor in $game_party.actors

      next if actor.dead?

      actors << actor

    end #for

    actor = actors[rand(actors.size)]

    sound = rand(4)

    temp = actor.states.clone

    for i in 0...actor.states.size

      actor.states.pop

    end #for

    actor.states << 17 #you set number of speeking animation here

    time = 4 * Graphics.frame_rate

    $game_system.se_play(RPG::AudioFile.new(sprintf("%s%i",actor.name,sound)))

    for i in 0..time

      Graphics.update

      @spriteset.update

    end #for

    Graphics.frame_count -= time

    actor.states.pop

    for i in temp

      actor.states << i

    end #for

  end #def

end #class

 
 

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