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.

Hear Steps v.2

arev

Sponsor

I'm reposting this script, since there's a request around :]

This script lets you hear the steps sound for any character on the map (if you wish so). The sound is louder the closer the character is.

Place this code above "Main":
Code:
#==============================================================================
# ** Hear_Steps
#------------------------------------------------------------------------------
#  by arevulopapo
#  9.11.2006
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  attr_accessor :hear_steps
  attr_accessor :step_sound
  #--------------------------------------------------------------------------
  alias hs_init initialize
  def initialize
    hs_init
    @hear_steps = false
    @step_sound = "Audio/SE/walk01"
  end
  alias hs_update update
  def update
    if self.moving? and self.hear_steps == true and (Graphics.frame_count + 2 * self.id) % (18 - @move_speed) == 0
      if self.screen_x > 0 and self.screen_x < 640 and self.screen_y > 0 and self.screen_y < 480
        volume = 100 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
        Audio.se_play(@step_sound, volume, 100)
      end
    end
    hs_update
  end
end

This line:
Code:
@step_sound = "Audio/SE/walk01"
determines the default sound for every character. If you want to change it use the "Call script" event command:
Code:
get_character(id).step_sound = "Audio/SE/walk03"
Where "id" is the id of an event.
To enable the sound (which is disabled by default) also use a "Call script" command:
Code:
get_character(id).hear_steps = true
If id = 0 the command will refer to the event it's being called by, if it's -1 it's for the player. Any number greater than 0 stands for event id.
For turning the sound off use:
Code:
get_character(id).hear_steps = nil
rather than:
Code:
get_character(id).hear_steps = false
It's said that it works better in the Game_Character class.
This script requires of course the sounds that are to be played.
You'll find them in the attached demo (don't bother different resolution).

Credits to me, and thanks to DerVVulfman for aliasing he methods and switching tips.
 

arev

Sponsor

Yeah, sure. Experiment with this line:
Code:
volume = 100 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
 

arev

Sponsor

Yes, it will. But you could change the sound by a parallel event, checking the terrain tag of a specific character.
 
Just a little helpful note, if you want to change the pitch of the characters footsteps find this line:

Code:
Audio.se_play(@step_sound, volume, 100)

Where it says volume, 100 change the 100 to a lower number, that will lower the pitch. 100 is the highest pitch it can go to so higher numbers won't work.

Hope that helps!
 

arev

Sponsor

gggg: Glad you like it :)
Grandor: Actually the pitch is from 50 to 150

I've edited the first post with a tip on turning the sounds OFF (thanks, DerVVulfman)
 
I am so sorry I didn't know about the rule of necroposting and I can't delete my post >_<
I just wanted to ask a question about that (how does it work) :

Yes, it will. But you could change the sound by a parallel event, checking the terrain tag of a specific character.

I am really sorry  :huh:
 
I had a script that can have different sounds by terrain tag.... :lol:
maybe I will post it sometime. :mystery: :mystery: :psy: :mystery:
 

Cloud

Member

I can´t hear anything ???
What´s wrong ???
I used this code:

#==============================================================================
# ** Hear_Steps
#------------------------------------------------------------------------------
#  by arevulopapo
#  9.11.2006
#==============================================================================

class Game_Character
  #--------------------------------------------------------------------------
  attr_accessor :hear_steps
  attr_accessor :step_sound
  #--------------------------------------------------------------------------
  alias hs_init initialize
  def initialize
    hs_init
    @hear_steps = false
    @step_sound = "Audio/SE/schritte"
  end
  alias hs_update update
  def update
    if self.moving? and self.hear_steps == true and (Graphics.frame_count + 2 * self.id) % (18 - @move_speed) == 0
      if self.screen_x > 0 and self.screen_x < 640 and self.screen_y > 0 and self.screen_y < 480
        volume = 100 - 5 * Math.sqrt((self.x - $game_player.x)**2 + (self.y - $game_player.y)**2)
        Audio.se_play(@step_sound, volume, 100)
      end
    end
    hs_update
  end
end


I put it above MAIN and Started the game...
But i can´t hear steps ????
 

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