SHARE
TWEET

[RMXP] Event Proximity Events 1.1

ForeverZer0 May 21st, 2011 224 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  2. # Event Proximity Icons
  3. # Author: ForeverZer0
  4. # Version: 1.1
  5. # Date: 5.16.2011
  6. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  7. #
  8. # Introduction:
  9. #   This script will allow you to have various icons appear over events' heads
  10. #   when the player gets within a certain range of them, and the appropriate
  11. #   tag is found asa comment in their page.
  12. #
  13. # Features:
  14. #   - Easy to use
  15. #   - Can use any number of custom tags you want
  16. #   - Adjustable coordinates for icons
  17. #   - Adjustable cycle times for changing icons
  18. #   - Adjustable proximity before icons show
  19. #   - Icons transition in/out smoothly
  20. #   - Can use glow feature instead of icons
  21. #   - Set custom glow color and speed
  22. #
  23. # Instructions:
  24. #   - See configuration below.
  25. #   - Make sure all icons are located in Graphics/Pictures directory
  26. #
  27. # Credits:
  28. #   - ForeverZer0, for the script
  29. #   - Zexion, for requesting it
  30. #
  31. ##+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  32.  
  33. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  34. #                            BEGIN CONFIGURATION
  35. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  36.  
  37.   TAGS = ['TALK', 'SEARCH', 'ATTACK']
  38.   # These are th codes that will be searched for in event page comments
  39.   ICONS = ['talk', 'search', 'attack']
  40.   # These are the filenames of the respective codes, located in Pictures folder
  41.  
  42.   PROXIMITY = 3
  43.   # The number of tiles away the player must be to event to show the icons.
  44.  
  45.   CYCLE_TIME = 2
  46.   # The number of seconds before the icon cycles to the next one (if available)
  47.  
  48.   ICON_OFFSET = [0, -8]
  49.   # The offset of the icon coodinates, adjust to your icon size
  50.   # [X_OFFSET, Y_OFFSET]
  51.  
  52.   GLOW_ONLY = false
  53.   # Set to true to have sprites glow when within range instead of using icons
  54.   GLOW_COLOR = Color.new(255, 255, 200, 128)
  55.   # The color of the glow.  (RED, GREEN, BLUE, ALPHA)
  56.   GLOW_SPEED = 40
  57.   # The glow speed.  40 = 1 second
  58.  
  59.   ALWAYS_ON_TOP = false
  60.   # Set to true if icons always display over everything else.
  61.  
  62. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  63. #                               END CONFIGURATION
  64. #+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  65.  
  66. #===============================================================================
  67. # ** Game_Event
  68. #===============================================================================
  69.  
  70. class Game_Event
  71.  
  72.   attr_reader :icons
  73.   attr_reader :icon_flag
  74.  
  75.   alias zer0_proximity_init initialize
  76.   def initialize(map_id, event)
  77.     # Normal method
  78.     zer0_proximity_init(map_id, event)
  79.     # Set flag if event will use a sprite for the icons
  80.     @icon_flag, @icons = false, []
  81.     # A little extra work now, but it greatly reduces the number of checks later
  82.     @event.pages.each {|page| page.list.each {|command|
  83.       if [108, 408].include?(command.code) &&
  84.         command.parameters.any? {|param| TAGS.include?(param) }
  85.         @icon_flag = true
  86.       end
  87.     }}
  88.     refresh
  89.   end
  90.  
  91.   alias zer0_proximity_tag_refresh refresh
  92.   def refresh
  93.     # Call normal refresh method
  94.     zer0_proximity_tag_refresh
  95.     # Check current page
  96.     if !GLOW_ONLY && @icon_flag && @page != nil
  97.       # Set default values
  98.       @icons, @icon_index = [], 0
  99.       # Iterate commands and check if tag is present. If so, set respective flag
  100.       @page.list.each {|command|
  101.         if [108, 408].include?(command.code) &&
  102.           TAGS.include?(command.parameters[0])
  103.           @icons.push(RPG::Cache.picture(command.parameters[0]))
  104.         end
  105.       }
  106.     end
  107.   end
  108. end
  109.  
  110. #===============================================================================
  111. # ** Game_Event
  112. #===============================================================================
  113.  
  114. class Sprite_Character
  115.  
  116.   alias zer0_proximity_tag_init initialize
  117.   def initialize(viewport, character = nil)
  118.     # Check if the sprite is that of an event, and has icons
  119.     if character.is_a?(Game_Event) && character.icon_flag
  120.       if ALWAYS_ON_TOP
  121.         topview = Viewport.new(0, 0, 640, 480)
  122.         topview.z = 9999
  123.       end
  124.       # Initialize sprite and bitmaps
  125.       @icon_sprite = ALWAYS_ON_TOP ? Sprite.new(topview) : Sprite.new(viewport)
  126.       @icon_sprite.opacity = @icon_index = 0
  127.     end
  128.     # Normal initialize method
  129.     zer0_proximity_tag_init(viewport, character)
  130.   end
  131.  
  132.   alias zer0_proximity_tag_upd update
  133.   def update
  134.     # Normal update method
  135.     zer0_proximity_tag_upd
  136.     # Update the icons if needed
  137.     if @character.is_a?(Game_Event) && @character.icon_flag
  138.       GLOW_ONLY ? update_glow : update_icons
  139.     end
  140.   end
  141.  
  142.   def update_glow
  143.     # Check proximity, then set flash if within range.
  144.     range_x = @character.x - $game_player.x
  145.     range_y = @character.y - $game_player.y
  146.     range = Math.hypot(range_x, range_y).abs
  147.     if range <= PROXIMITY && Graphics.frame_count % GLOW_SPEED == 0
  148.       self.flash(GLOW_COLOR, GLOW_SPEED)
  149.     end
  150.   end
  151.  
  152.   def update_icons
  153.     # Return if no icons exist for page, or set icon if none is defined
  154.     if @character.icons.empty?
  155.       return
  156.     elsif @icon_sprite.bitmap == nil
  157.       @icon_sprite.bitmap = @character.icons[0]
  158.     end
  159.     bw = bh = 0
  160.     # Calculate width and height of icon and figure into the coordinates
  161.     if @icon_sprite.bitmap != nil
  162.       bw = ((self.bitmap.width / 4) - @icon_sprite.bitmap.width) / 2
  163.       by = -@icon_sprite.bitmap.height
  164.     end
  165.     # Set coordinates of icon relative to sprite
  166.     @icon_sprite.x = (self.x - self.ox) + bw + ICON_OFFSET[0]
  167.     @icon_sprite.y = (self.y - self.oy) + bh + ICON_OFFSET[1]
  168.     # Check range, fading in/out smoothly as needed
  169.     range_x = @character.x - $game_player.x
  170.     range_y = @character.y - $game_player.y
  171.     range = Math.hypot(range_x, range_y).abs
  172.     @icon_sprite.opacity += (range <= PROXIMITY) ? 10 : -10
  173.     # Cycle icon bitmap as needed
  174.     if @icon_sprite.opacity > 0 && Graphics.frame_count % (CYCLE_TIME * 40) == 0
  175.       @icon_index = (@icon_index + 1) % @character.icons.size
  176.       @icon_sprite.bitmap = @character.icons[@icon_index]
  177.     end
  178.   end
  179.  
  180.   alias zer0_proximity_icon_dispose dispose
  181.   def dispose
  182.     # Disposed the icon sprite
  183.     if @icon_sprite != nil && !@icon_sprite.disposed?
  184.       @icon_sprite.dispose
  185.     end
  186.     zer0_proximity_icon_dispose
  187.   end
  188. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top