Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- # Event Proximity Icons
- # Author: ForeverZer0
- # Version: 1.1
- # Date: 5.16.2011
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #
- # Introduction:
- # This script will allow you to have various icons appear over events' heads
- # when the player gets within a certain range of them, and the appropriate
- # tag is found asa comment in their page.
- #
- # Features:
- # - Easy to use
- # - Can use any number of custom tags you want
- # - Adjustable coordinates for icons
- # - Adjustable cycle times for changing icons
- # - Adjustable proximity before icons show
- # - Icons transition in/out smoothly
- # - Can use glow feature instead of icons
- # - Set custom glow color and speed
- #
- # Instructions:
- # - See configuration below.
- # - Make sure all icons are located in Graphics/Pictures directory
- #
- # Credits:
- # - ForeverZer0, for the script
- # - Zexion, for requesting it
- #
- ##+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- # BEGIN CONFIGURATION
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- TAGS = ['TALK', 'SEARCH', 'ATTACK']
- # These are th codes that will be searched for in event page comments
- ICONS = ['talk', 'search', 'attack']
- # These are the filenames of the respective codes, located in Pictures folder
- PROXIMITY = 3
- # The number of tiles away the player must be to event to show the icons.
- CYCLE_TIME = 2
- # The number of seconds before the icon cycles to the next one (if available)
- ICON_OFFSET = [0, -8]
- # The offset of the icon coodinates, adjust to your icon size
- # [X_OFFSET, Y_OFFSET]
- GLOW_ONLY = false
- # Set to true to have sprites glow when within range instead of using icons
- GLOW_COLOR = Color.new(255, 255, 200, 128)
- # The color of the glow. (RED, GREEN, BLUE, ALPHA)
- GLOW_SPEED = 40
- # The glow speed. 40 = 1 second
- ALWAYS_ON_TOP = false
- # Set to true if icons always display over everything else.
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- # END CONFIGURATION
- #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
- #===============================================================================
- # ** Game_Event
- #===============================================================================
- class Game_Event
- attr_reader :icons
- attr_reader :icon_flag
- alias zer0_proximity_init initialize
- def initialize(map_id, event)
- # Normal method
- zer0_proximity_init(map_id, event)
- # Set flag if event will use a sprite for the icons
- @icon_flag, @icons = false, []
- # A little extra work now, but it greatly reduces the number of checks later
- @event.pages.each {|page| page.list.each {|command|
- if [108, 408].include?(command.code) &&
- command.parameters.any? {|param| TAGS.include?(param) }
- @icon_flag = true
- end
- }}
- refresh
- end
- alias zer0_proximity_tag_refresh refresh
- def refresh
- # Call normal refresh method
- zer0_proximity_tag_refresh
- # Check current page
- if !GLOW_ONLY && @icon_flag && @page != nil
- # Set default values
- @icons, @icon_index = [], 0
- # Iterate commands and check if tag is present. If so, set respective flag
- @page.list.each {|command|
- if [108, 408].include?(command.code) &&
- TAGS.include?(command.parameters[0])
- @icons.push(RPG::Cache.picture(command.parameters[0]))
- end
- }
- end
- end
- end
- #===============================================================================
- # ** Game_Event
- #===============================================================================
- class Sprite_Character
- alias zer0_proximity_tag_init initialize
- def initialize(viewport, character = nil)
- # Check if the sprite is that of an event, and has icons
- if character.is_a?(Game_Event) && character.icon_flag
- if ALWAYS_ON_TOP
- topview = Viewport.new(0, 0, 640, 480)
- topview.z = 9999
- end
- # Initialize sprite and bitmaps
- @icon_sprite = ALWAYS_ON_TOP ? Sprite.new(topview) : Sprite.new(viewport)
- @icon_sprite.opacity = @icon_index = 0
- end
- # Normal initialize method
- zer0_proximity_tag_init(viewport, character)
- end
- alias zer0_proximity_tag_upd update
- def update
- # Normal update method
- zer0_proximity_tag_upd
- # Update the icons if needed
- if @character.is_a?(Game_Event) && @character.icon_flag
- GLOW_ONLY ? update_glow : update_icons
- end
- end
- def update_glow
- # Check proximity, then set flash if within range.
- range_x = @character.x - $game_player.x
- range_y = @character.y - $game_player.y
- range = Math.hypot(range_x, range_y).abs
- if range <= PROXIMITY && Graphics.frame_count % GLOW_SPEED == 0
- self.flash(GLOW_COLOR, GLOW_SPEED)
- end
- end
- def update_icons
- # Return if no icons exist for page, or set icon if none is defined
- if @character.icons.empty?
- return
- elsif @icon_sprite.bitmap == nil
- @icon_sprite.bitmap = @character.icons[0]
- end
- bw = bh = 0
- # Calculate width and height of icon and figure into the coordinates
- if @icon_sprite.bitmap != nil
- bw = ((self.bitmap.width / 4) - @icon_sprite.bitmap.width) / 2
- by = -@icon_sprite.bitmap.height
- end
- # Set coordinates of icon relative to sprite
- @icon_sprite.x = (self.x - self.ox) + bw + ICON_OFFSET[0]
- @icon_sprite.y = (self.y - self.oy) + bh + ICON_OFFSET[1]
- # Check range, fading in/out smoothly as needed
- range_x = @character.x - $game_player.x
- range_y = @character.y - $game_player.y
- range = Math.hypot(range_x, range_y).abs
- @icon_sprite.opacity += (range <= PROXIMITY) ? 10 : -10
- # Cycle icon bitmap as needed
- if @icon_sprite.opacity > 0 && Graphics.frame_count % (CYCLE_TIME * 40) == 0
- @icon_index = (@icon_index + 1) % @character.icons.size
- @icon_sprite.bitmap = @character.icons[@icon_index]
- end
- end
- alias zer0_proximity_icon_dispose dispose
- def dispose
- # Disposed the icon sprite
- if @icon_sprite != nil && !@icon_sprite.disposed?
- @icon_sprite.dispose
- end
- zer0_proximity_icon_dispose
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement