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.

[Filled] crazy request - terrain sounds

Terrain flag sounds for xp

i know this sounds crazy but i was hope that it wouldnt be too difficult to make a script that allows you to set sound effects for walking on a terrain flaged tile.

for example: say you walk on grass you can set that as terrain flag 1 and the game will play the sound effect set for walking on grass, if 2 the sound of walking on wood, eta. ofcourse you would have to be able to choose tile set and which flags are for which sounds.

thanks for any input

p.s. did i leave anything out?
 
(Make better topic titles)

I haven't tested this, but let me know how it turns out.

Code:
module TerrainSounds
  Play_For_Player = true
  Play_For_Events = true

  Tileset_Terrain_SE = {}
  # For each sound effect you wish to play, 
  # add Tileset_Terrain_SE[[tileset_id, terrain_id]] = ['se filename', volume, pitch]

  def self.se_play(character)
    return if character.is_a?(Game_Player) && Play_For_Player == false
    return if character.is_a?(Game_Event) && Play_For_Events == false
    tileset_id = $game_map.map.tileset_id
    terrain_tag = character.terrain_tag
    key = [tileset_id, terrain_tag]
    if Tileset_Terrain_SE.has_key?(key)
      args = Tileset_Terrain_SE[key]
      name = "Audio/SE/#{args[0]}"
      volume = args.size > 1 ? args[1] : 80
      pitch = args.size > 2 ? args[2] : 100
      Audio.se_play(name, volume, pitch)
    end
  end
end

class Game_Map
  attr_reader :map
end

class Game_Character
  alias_method :seph_terrainse_gmchr_is, :increase_steps
  def increase_steps
    seph_terrainse_gmchr_is
    TerrainSounds.se_play(self)
  end
end

If you have any trouble setting anything up or it doesn't work, just let me know. :)
 
it works on all my maps without event, but if there is a event walking around it crashes, no matter if play_for_events is true or false

edit: it says "unititalized constant TerrainSounds::Play_for_Event"
 

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