Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # SES: Play SE on Walk
- # v1.1
- # 4.14.2012
- # Compatibility: VXAce/RGSS3
- # Author: Enelvon
- # Requested by Ae
- #===============================================================================
- # Terms of Use:
- #
- # This script may be used for free in any game, whether it's commercial or not.
- # The only requirement is that I be credited in some visible manner. You may not
- # claim this script as your own work. You are free to modify this script, but
- # may not redistribute it except for in a thread that I have started that relates
- # to it in some way.
- #===============================================================================
- # Changelog:
- # 4.14.2012: v1.0 - Script written.
- # 4.14.2012: v1.1 - Now allows offscreen events to update in a radius of your
- # choosing, but they won't be making noise unless you set them
- # to. Added support for Tileset IDs instead of Map IDs.
- #===============================================================================
- # This script was requested by my dear friend, Ae. They wanted to recreate a
- # function from RPG Maker 2003 that allowed a sound effect to be played when
- # the player was walking on certain tiles.
- #===============================================================================
- # Required Scripts: Enelvon Script Core v1.0 or higher
- # Known Incompatibilities: None, though there are some redefinitions so it's a
- # possibility that some may occur. Refer to the Redefinitions section at the
- # bottom of my comments for a complete list of what was redefined.
- #===============================================================================
- # Installation: Place below Materials and the Enelvon Script Core. Edit the
- # constants in SES::WalkSE to customize the script.
- #===============================================================================
- # Instructions:
- #
- # ***Constants for SES::WalkSE***
- #
- # Events_Make_Sound - setting this to true causes events to make sounds when
- # walking on tiles that produce sounds, just like players do.
- #
- # Use_Tileset_ID - if this is set to true, the IDs for WalkingSoundsTerrain will
- # refer to Tileset IDs for what sound to produce. If it is set to false, it
- # will refer to map IDs.
- #
- # WalkingSoundsTerrain - this is a hash of SEs by Terrain Tag ID and Tileset or
- # Map ID. It consists of hashes (one per map ID) and three-part arrays. The
- # first part is the name of the SE to play when stepping on a tile with the
- # given terrain tag. The second is the volume of the sound. The third is the
- # pitch of the sound.
- #
- # WalkingSoundsRegion - this is a hash of SEs by Region ID. Values in this will
- # overwrite values from WalkingSoundsTerrain, and are universal across all
- # maps and tilesets. It consists of three-part arrays written in the same
- # format as those for terrain tag-based sounds, minus the Map/Tileset ID
- # hash.
- #
- # Event_Update_X - this is a hash consisting of Map IDs and X values. By default
- # VXAce only updates events that are within twelve squares horizontally of
- # the center of the screen. This is inconvenient for some game types, such as
- # those that are heavily stealth-based. This setting allows you to change the
- # horizontal update distance on a per-map basis. Setting it to 999 allows for
- # updating of all events on the map, but may produce lag, especially on maps
- # that have a heavy event load. This setting may be completely ineffective if
- # you don't also edit Event_Update_Y.
- #
- # Event_Update_Y - this is a hash consisting of Map IDs and Y values. By default
- # VXAce only updates events that are within eight squares vertically of the
- # center of the screen. This is inconvenient for some game types, such as
- # those that are heavily stealth-based. This setting allows you to change the
- # vertical update distance on a per-map basis. Setting it to 999 allows for
- # updating of all events on the map, but may produce lag, especially on maps
- # that have a heavy event load. This setting may be completely ineffective if
- # you don't also edit Event_Update_X.
- #
- # Sound_Toggle_Events - this is the RegExp that allows events to make or not make
- # sounds individually, ignoring the value of Events_Make_Sound. There is more on
- # this in the next section.
- #
- # Event_Unique_Sound - this is the RegExp that allows events to make their own
- # sound regardless of what would normally be produced by the tile they're
- # stepping on. There is more on this in the next section.
- #
- # Event_Always_Sound - this is the RegExp that allows events to make sounds even
- # while offscreen. There is more on this in the next section.
- #
- # ***Additional: Event Comments***
- #
- # You can customize this script for each event page in your game by adding tags
- # in Comments boxes. Each box can contain only one tag, unfortunately - but you
- # can have as many boxes as you want. These are the tags available in this script:
- #
- # MakeWalkSound: !Bool!
- # Place this in a Comments box to cause the event to play/not play a sound
- # regardless of what Events_Make_Sound is set to.
- # Replacements:
- # !Bool! with either true (play a sound) or false (don't play a sound)
- #
- # WalkSound: !SE!, !Volume!, !Pitch!
- # Place this in a Comments box to change the sound played when the event walks.
- # It will always play while the event is moving, regardless of what sounds the
- # tiles it's walking on would usually play.
- # Replacements:
- # !SE! with the name of the sound, minus its extension.
- # !Volume! with the volume of the sound, 0-100.
- # !Pitch! with the pitch of the sound, 0-100.
- #
- # AlwaysSound: !Volume!, !Pitch!
- # Place this in a Comments box to cause an event to produce walking sounds
- # even when offscreen. NOTE: Events will not make sounds outside of the map's
- # update range even if they have this tag.
- # Replacements:
- # !Volume! with the volume of the walking sound when the event is offscreen.
- # !Pitch! with the pitch of the walking sound when the event is offscreen.
- #
- #===============================================================================
- # Redefinitions:
- #
- # These are the methods that are redefined by this script. This information is
- # included for purposes of pinpointing compatibility errors between scripts.
- #
- # ***class Game_Characterbase***
- #
- # move_straight(d, turn_ok = true)
- #
- # ***class Game_Event***
- #
- # near_the_screen?(dx = 12, dy = 8)
- #
- ################################################################################
- module SES
- module WalkSE
- Events_Make_Sound = true # true - events will make walking sounds
- # false - events will not make walking sounds
- Use_Tileset_ID = true # true - WalkingSoundsTerrain will use Tileset IDs
- # false - WalkingSoundsTerrain will use Map IDs
- WalkingSoundsTerrain = {
- #Map/Tileset ID => {
- 1 => {
- #Terrain Tag => [Sound, Volume, Pitch],
- 1 => ["Knock", 80, 100],
- },
- }
- # Default hash for Map/Tileset IDs that aren't listed in WalkingSoundsTerrain.
- # You can edit it (just add Terrain Tag ID arrays, not Map/Tileset IDs) to
- # create a global set of sounds for unlisted maps.
- WalkingSoundsTerrain.default = {}
- WalkingSoundsRegion = {
- #Region ID => [Sound, Volume, Pitch],
- 1 => ["Knock", 80, 100],
- }
- Event_Update_X = {
- #Map ID => X, (X = Number of squares from the center of the screen that will
- # be updated horizontally)
- 1 => 12,
- }
- # Default X value for all maps whose IDs aren't in Event_Update_X
- Event_Update_X.default = 12
- Event_Update_Y = {
- #Map ID => Y, (Y = Number of squares from the center of the screen that will
- # be updated vertically)
- 1 => 8,
- }
- # Default Y value for all maps whose IDs aren't in Event_Update_Y
- Event_Update_Y.default = 8
- # RegExp for ignoring Events_Make_Sound
- Sound_Toggle_Events = /^MakeWalkSound: (true|false)/i
- # RegExp for giving events unique walking sounds
- Event_Unique_Sound = /^WalkSound: ([\w]+), ([\d]+), ([\d]+)/i
- # RegExp for causing an event to make sounds while updating offscreen
- Event_Always_Sound = /^AlwaysSound: ([\d]+), ([\d]+)/i
- end
- end
- $imported = {} if $imported.nil?
- $imported["SES - WalkSE"] = true
- class Game_CharacterBase
- def offscreen
- max_x = $game_map.display_x + $game_map.screen_tile_x
- x_valid = @real_x <= max_x && @real_x >= $game_map.display_x
- max_y = $game_map.display_y + $game_map.screen_tile_y
- y_valid = @real_y <= max_y && @real_y >= $game_map.display_y
- return false if x_valid && y_valid
- return true
- end
- def move_straight(d, turn_ok = true)
- @move_succeed = passable?(@x, @y, d)
- if @move_succeed
- Audio.se_stop
- set_direction(d)
- @x = $game_map.round_x_with_direction(@x, d)
- @y = $game_map.round_y_with_direction(@y, d)
- @real_x = $game_map.x_with_direction(@x, reverse_dir(d))
- @real_y = $game_map.y_with_direction(@y, reverse_dir(d))
- increase_steps
- sound = true
- if self.is_a?(Game_Event)
- sound = @page.makesound
- sound = false if offscreen && !@page.alwayssound[0]
- end
- if SES::WalkSE::Use_Tileset_ID
- se = SES::WalkSE::WalkingSoundsTerrain[$game_map.tileset.id][terrain_tag]
- else
- se = SES::WalkSE::WalkingSoundsTerrain[$game_map.map_id][terrain_tag]
- end
- se = SES::WalkSE::WalkingSoundsRegion[region_id] if !SES::WalkSE::WalkingSoundsRegion[region_id].nil?
- se = @page.walksound if self.is_a?(Game_Event) && @page.walksound != ""
- if self.is_a?(Game_Event) && offscreen && @page.alwayssound[0]
- se[1] = @page.alwayssound[1]
- se[2] = @page.alwayssound[2]
- end
- Audio.se_play("Audio/SE/#{se[0]}", se[1], se[2]) if sound && !se.nil?
- elsif turn_ok
- set_direction(d)
- check_event_trigger_touch_front
- end
- end
- end
- class Game_Map
- attr_reader :tileset_id
- end
- class Game_Event < Game_Character
- def near_the_screen?(dx = SES::WalkSE::Event_Update_X[$game_map.map_id], dy = SES::WalkSE::Event_Update_Y[$game_map.map_id])
- ax = $game_map.adjust_x(@real_x) - Graphics.width / 2 / 32
- ay = $game_map.adjust_y(@real_y) - Graphics.height / 2 / 32
- ax >= -dx && ax <= dx && ay >= -dy && ay <= dy
- end
- end
- class RPG::Event::Page
- alias en_walkse_sc en_scan_comments
- def en_scan_comments(comments = [])
- @makesound = SES::WalkSE::Events_Make_Sound
- @walksound = ""
- @alwayssound = [false, 0, 0]
- comments.push([SES::WalkSE::Sound_Toggle_Events, "$1.to_s.downcase == 'true' ? @makesound = true : @makesound = false"])
- comments.push([SES::WalkSE::Event_Unique_Sound, "@walksound = [$1.to_s, $2.to_i, $3.to_i]"])
- comments.push([SES::WalkSE::Event_Always_Sound, "@alwayssound = [true, $1.to_i, $2.to_i]"])
- en_walkse_sc(comments)
- end
- traits = [:makesound, :walksound, :alwayssound]
- traits.each_index { |i|
- define_method(traits[i]) {
- en_scan_comments if eval("@#{traits[i]}.nil?")
- return eval("@#{traits[i]}")
- }
- }
- end
Advertisement
Add Comment
Please, Sign In to add comment