Help - Search - Members - Calendar
Full Version: DeadlyDan_Footsteps
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS2-Submissions
deadlydan
Hey guys, another script release smile.gif Hope you like it, this time, it's footstep sounds, basically, this script allows you to enable and disable the ability to sound footsteps when the player walks. This is useful for creepy games for example, creaky floorboards etc.

The script has some minor problems which are explained in the script information, but overall it's pretty good. It features a different pitch for each step, and the footsteps are faster when you dash.

You can download the footstep sound files i use here:
http://www.megaupload.com/?d=O9VRGJ1Y

Here is the script, hope you enjoy it smile.gif The instructions are inside the script. Thanks.

CODE
#==============================================================================
# ■ DeadlyDan_Footsteps by DeadlyDan
#------------------------------------------------------------------------------
#  Enables ability to "sound" footsteps when walking over specific tiles
#==============================================================================
# Usage:
=begin
  
  Simple, place the audio files in your SE directory, and try the game.
  
  There are some known bugs in this, if anyone has any fixes just let me know:)
  
  To add custom sounds for custom tiles you can do for example:
  
  FOOTSTEP_WOOD = [15] # The tilenumber ID that you get with debug_tileid function
  FOOTSTEP_WOOD_FILE = "Audio/SE/stepwood" # The filename for the sound
  
  then add underneath the # Insert custom sounds here line:
  
  footstep_check ( FOOTSTEP_WOOD, FOOTSTEP_WOOD_FILE, 0 )
  
  The last number in that function stands for the layer, since the wood tile i
  selected is on the ground layer, it's layer is 0.  
  
  (NOTE)
  There is a problem that when you go on carpet it makes dirt and snow sounds,
  i currently can't find a way to fix this, so, the best thing to do is to call
  the command $game_player.footsteps_enabled = false.
  
  To enable footsteps while stopping the carpet and tables from making the snow
  and dirt sounds, there's an uneasy solution of placing a touch event which
  calls $game_player.footsteps_enabled = false.
  
  Sorry about this inconvenience.

=end

class Game_Player < Game_Character
  
  FOOTSTEP_GRASS = [28, 29, 30]
  FOOTSTEP_GRASS_LONG = [29, 30]
  FOOTSTEP_GRASS_FILE = "Audio/SE/stepgrass"
  
  FOOTSTEP_DIRT = [32, 33, 34]
  FOOTSTEP_DIRT_LONG = [32 ,34]
  FOOTSTEP_DIRT_FILE = "Audio/SE/stepdirt"
  
  FOOTSTEP_SAND = [36, 37, 38]
  FOOTSTEP_SAND_LONG = [36, 38]
  FOOTSTEP_SAND_FILE = "Audio/SE/stepdirt"
  
  FOOTSTEP_SNOW = [39, 41]
  FOOTSTEP_SNOW_LONG = [40, 41]
  FOOTSTEP_SNOW_FILE = "Audio/SE/stepsnow"
  
  FOOTSTEP_WOOD = [15]
  FOOTSTEP_WOOD_FILE = "Audio/SE/stepwood"
  
  FOOTSTEP_PITCH = 100
  FOOTSTEP_PITCH2 = 90

  attr_accessor :last_foot
  attr_accessor :footsteps_enabled
  
  alias foot_initialize initialize
  def initialize
    foot_initialize
    @last_foot = 0
    @last_foot_pitch = FOOTSTEP_PITCH2
    @next_foot_pitch = FOOTSTEP_PITCH
    @footsteps_enabled = true
  end
  
  alias foot_move_left move_left
  def move_left ( turn_ok = true )
    foot_move_left ( turn_ok )
    if ( @move_failed == false )
      sound_foot
    end
  end
    
  alias foot_move_right move_right
  def move_right ( turn_ok = true )
    foot_move_right ( turn_ok )
    if ( @move_failed == false )
      sound_foot
    end
  end
  
  alias foot_move_up move_up
  def move_up ( turn_ok = true )
    foot_move_up ( turn_ok )
    if ( @move_failed == false and @footsteps_enabled )
      sound_foot
    end
  end
  
  alias foot_move_down move_down
  def move_down ( turn_ok = true )
    foot_move_down ( turn_ok )
    if ( @move_failed == false and @footsteps_enabled )
      sound_foot
    end
  end
  
  def no_layer_tile? ( layer )
    result = [false, false, false]
    for i in 0..2
      if ( @map_tile_id[i] == 0 )
        result[i] = true
      end
    end
    if ( layer == 0 )    
      if ( result[1] and result[2] )
        return true
      else
        return false
      end
    end
    else if ( layer == 1 )
      if ( result[2] )
        return true
      else
        return false
      end
    else
      return true
    end
  end
  
  def debug_tileid
    $game_message.texts[0] = @map_tile_tex[0]
    $game_message.texts[1] = @map_tile_tex[1]
    $game_message.texts[2] = @map_tile_tex[2]
  end
  
  def footstep_check ( footstep, file, layer )
    for i in 0..footstep.length
      if ( ( @map_tile_tex[layer] == footstep[i].to_s ) and ( no_layer_tile? ( layer ) ) )
        Audio.se_play ( file, 100, @next_foot_pitch )
        @last_foot = Graphics.frame_count
        return nil
      end
    end
  end
  
  def sound_foot
    if ( dash? )
      mul = 6
    else
      mul = 7
    end
    if ( Graphics.frame_count > ( @last_foot + mul ) )
      @map_tile_id = []
      @map_tile_tex = []
      for i in 0..2
        @map_tile_id.push ( $game_map.data[@x, @y, i] )
        @map_tile_tex.push ( @map_tile_id[i].to_s[0,2] )
      end
      
      # Use "debug_tileid" here to bring up the numbers of all the current tiles
      # to use with definitions of the tileids, walk over tiles ingame...
      
      if ( @last_foot_pitch == FOOTSTEP_PITCH )
        @next_foot_pitch = FOOTSTEP_PITCH2
        @last_foot_pitch = FOOTSTEP_PITCH2
      else
        @next_foot_pitch = FOOTSTEP_PITCH
        @last_foot_pitch = FOOTSTEP_PITCH
      end
      
      # Ground layer
      footstep_check ( FOOTSTEP_GRASS, FOOTSTEP_GRASS_FILE, 0 )
      footstep_check ( FOOTSTEP_DIRT, FOOTSTEP_DIRT_FILE, 0 )
      footstep_check ( FOOTSTEP_SAND, FOOTSTEP_SAND_FILE, 0 )
      footstep_check ( FOOTSTEP_SNOW, FOOTSTEP_SNOW_FILE, 0 )
      footstep_check ( FOOTSTEP_WOOD, FOOTSTEP_WOOD_FILE, 0 )
      
      # Layer 1
      footstep_check ( FOOTSTEP_GRASS_LONG, FOOTSTEP_GRASS_FILE, 1 )
      footstep_check ( FOOTSTEP_DIRT_LONG, FOOTSTEP_DIRT_FILE, 1 )
      footstep_check ( FOOTSTEP_SAND_LONG, FOOTSTEP_SAND_FILE, 1 )
      footstep_check ( FOOTSTEP_SNOW_LONG, FOOTSTEP_SNOW_FILE, 1 )
      
      # Insert custom sounds here
      
    end
  end
  
end
woratana
Sounds Good!

I think if this script can use with event, that will be great!

I've script the script like this in RMXP before, these are the features I have in my script:
- Sound depends on Terrain
- Event can has step sound.
- Step sound of event will loud or low depends on distance from that event and player
- Skip from play step sound every step, because sometimes it's disturbing when there's sound every step.
- Change volume of step sound for each event.
I think this may inspired your idea~^^
deadlydan
Oh right, nah, my idea was actually inspired by a creepy RPG i once made in RM2k, where it was tedious to make the floorboards creek, thanks though.

I guess this code could be easily imported to be useable in events, you could just change Game_Player to Game_Character.
woratana
I suggest you to make it possible to use sound just for some event, and allow to open/stop sound from each event.

Because if every event have sound, if may increase lag or it may really disturb the player.

>_<
deadlydan
Yeah, thats simple enough, in the future i'll add such things, at the moment, it's not my top priority to add anything else to this script... Thanks smile.gif
X-Snake-X
Another great Script from you!
It just need some improvements happy.gif
kikaider125
I have a question, is there any simple way to change the volume of the footsteps? they just seem a little loud.
deadlydan
change the 100 in the line:

CODE
Audio.se_play ( file, 100, @next_foot_pitch )


to what ever volume you want.
ch.maker
When I am flying by airship, it makes the same sound, as if I were walking
How can I fix that bug?

Sorry about my English mellow.gif
Ilikepie123
QUOTE (deadlydan @ Feb 4 2008, 02:45 PM) *
change the 100 in the line:

CODE
Audio.se_play ( file, 100, @next_foot_pitch )


to what ever volume you want.

I think it would require a LOT of scripting. And your English was perfect o.o... There were no gramatical errors or anything visable... O.o...
Mech-Ah
Never mind.
An excellent script.
deadlydan
QUOTE (ch.maker @ Feb 12 2008, 03:07 PM) *
When I am flying by airship, it makes the same sound, as if I were walking
How can I fix that bug?

Sorry about my English mellow.gif


While in an airship set it to enabled = false.
ch.maker
QUOTE (deadlydan @ Mar 13 2008, 02:18 AM) *
QUOTE (ch.maker @ Feb 12 2008, 03:07 PM) *
When I am flying by airship, it makes the same sound, as if I were walking
How can I fix that bug?

Sorry about my English mellow.gif


While in an airship set it to enabled = false.


Thank you! laugh.gif
francesco34
im having a problem if i start the game whit the script and there satnd line 67 stack to deep
buran
What I can do to know the tile's ID?

PS. Sorry about my English, I speak better Portuguese ^o^"
Denna.Maes
QUOTE (buran @ Apr 23 2008, 12:50 PM) *
What I can do to know the tile's ID?

PS. Sorry about my English, I speak better Portuguese ^o^"


I've got the same question sleep.gif
tekken999
Does this apply to custom sprites because mine doesnt make any sound and i havent enountered any errors in the script?
miget man12
Umm... I don't know if anyone really cares about this anymore, but I'll post this anyway:
(please note that I'm not entirely sure about all of this, so this might not work exactly as said)
The Tile IDs are shown in the attached picture, Those which have 2 numbers have the Ground Level and the 1st layer (used in the 'TALL' sections)
i.e.:
CODE
  FOOTSTEP_GRASS = [28, 29, 30]
This will have The following:
Click to view attachment
CODE
  FOOTSTEP_GRASS_LONG = [29, 30]
This will add these:
Click to view attachment
...I think!

and thus, you will have these:
Click to view attachment
if you understood that, you should be able to use this to choose which Tileset ID's you want to use:
Click to view attachment
let me know if you have any more questions smile.gif

~Miget man12
Digioso
Update:
I had a small bug in there which prevented playing the layer 1 sounds. It's fixed now. I updated the attached version with the fix.

Update 2:
The game crashed if you didn't have a config file. Now it works as promised without a file and uses default sounds.

Sorry for the necropost, but I think it's worth it (and it's my first posting here on this forum...). smile.gif

I wanted to use this script for my own game but found out that it's not compatible to tilesets swapped with SwapXT because the tileids are hardcoded in the script.
So... well I changed that. tongue.gif

You can now create a configuration file where you can put the tileids in for swapped maps. So no more "Stone-Footsteps" when you're walking over grass. The script will check the file and if it finds a map configured in there it will use this configuration.
If you're on a map not configured or if you don't have the configuration file at all it will use the standard sounds from DeadlyDans initial script.

Instructions on how to use this and how to create the config file is provided in the script itself.
The newest version of this script can always be found here: http://www.digioso.org/DeadlyDan_Footsteps

I'm thinking of writing a little program that helps you create the config file as well but I don't know when I'll have to time for that as I'm currently working on my first game and spent all my time there. smile.gif

If you have any questions feel free to ask.

If you're planning to use this please give credit to DeadlyDan and me.

@Miget man12: With the "debug_tileid" method in the script you can make it show you the tileid with each step you do.
Could you test it with this and tell me if you still think it's wrong? Well what you could do basically is just walking over the tiles you think are wrong. If you here the wrong sound (or none where you expected a sound to be) then something isn't right. I can have a look at this and try to fix it then.
I'll see if I can test a few things as well. Have to create a few more configs for my own game so if there's anything wrong I'll probably stumble upon it. So far my results were that the script is correct.
Digioso
Another update. If you saved and loaded your game with this script enabled your game would crash.
I didn't know that I have to save and load the stuff I coded as well... Well... that's fixed now!

Newest version is available at the link above and attached to this posting.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.