[XP] Event Proximity Icons

Started by ForeverZer0, May 16, 2011, 02:29:57 am

Previous topic - Next topic

ForeverZer0

May 16, 2011, 02:29:57 am Last Edit: August 14, 2012, 02:53:35 pm by ForeverZer0
Event Proximity Icons
Authors: ForeverZer0
Version: 1.4
Type: Event Add-On
Key Term: Misc Add-on



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 as a 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

  • Ability to have event simply glow when within range instead of use icons

  • Can customize the color and speed of the glow effect




Screenshots

Spoiler: ShowHide

Spoiler: ShowHide



Demo

Demo Link


Script

The Script: ShowHide
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# Event Proximity Icons
# Author: ForeverZer0
# Version: 1.4
# Date: 6.4.2012
#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
#
# 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
#   - Taiine, for her constant reminders to add Blizz-ABS compatibility ;)
#
##+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
#                            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_Map
#===============================================================================

class Game_Map
 
 attr_accessor :proximity_data
 
 alias zer0_proximity_setup setup
 def setup(map_id)
   @proximity_data = {}
   zer0_proximity_setup(map_id)
 end
end

#===============================================================================
# ** Game_Event
#===============================================================================

class Game_Event
 
 alias zer0_proximity_init initialize
 def initialize(map_id, event)
   # Normal method
   $game_map.proximity_data[event.id] = [false, []]
   zer0_proximity_init(map_id, event)
   # 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) }
       $game_map.proximity_data[@id][0] = 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 && $game_map.proximity_data[@id][0] && @page != nil
     # Set default values
     $game_map.proximity_data[@id] = [false, []]
     # 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])
         $game_map.proximity_data[@id][0] = true
         $game_map.proximity_data[@id][1].push(command.parameters[0])
       end
     }
   end
 end
end

#===============================================================================
# ** Sprite_Character
#===============================================================================

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.id != 0
     flag = $game_map.proximity_data[character.id][0]
     if character.is_a?(Game_Event) && 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
   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 ![nil, 0].include?(@character.id)
     flag = $game_map.proximity_data[@character.id][0]
     if @character.is_a?(Game_Event) && flag
       GLOW_ONLY ? update_glow : update_icons
     end
   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 $game_map.proximity_data[@character.id][1].empty?
     return
   elsif @icon_sprite.bitmap == nil
     icon_name = $game_map.proximity_data[@character.id][1][0]
     @icon_sprite.bitmap = RPG::Cache.picture(icon_name)
   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
   if $BlizzABS
     pix = $BlizzABS.pixel
     char_x, char_y = @character.x, @character.y
     player_x, player_y = $game_player.x / pix , $game_player.y / pix
     if @character.is_a?(Map_Battler)
       char_x /= pix
       char_y /= pix
     end
   else
     char_x, char_y = @character.x, @character.y
     player_x, player_y = $game_player.x, $game_player.y
   end
   range_x = char_x - player_x
   range_y = char_y - 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
     size = $game_map.proximity_data[@character.id][1].size
     @icon_index = (@icon_index + 1) % size
     icon_name = $game_map.proximity_data[@character.id][1][@icon_index]
     @icon_sprite.bitmap = RPG::Cache.picture(icon_name)
   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



Instructions

Place above "Main", and below default scripts.
Instructions are within the script.


Compatibility

Pixel movement scripts may cause issues, though I DID add compatibility for Blizz-ABS pixel-movement.

BlizzABS's ABSEAL will under certain circumstances not update events without graphics, which may include some of your proximity events, causing them not to work. To fix this issue, place the small script below anywhere below the BlizzABS scripts.
BlizzABS ABSEAL Fix: ShowHide
class Game_Character
 
  alias zer0_proximity_update? update?
  def update?
    if self.is_a?(Game_Event) && $game_map.proximity_data.include?(self.id)
      if @trigger == 3 || @trigger == 4 || self.name.clone.gsub!('\\eal') {''}
        return true
      end
      return in_abseal_range?
    end
    return zer0_proximity_update?
  end
end




Credits and Thanks


  • ForeverZer0, for the script

  • Zexion, for the idea and the request

  • Taiine, for her moral support adding Blizz-ABS compatibility ;)

  • Vexus, for helping track down the ABSEAL bug




Author's Notes

Please report any bugs/issues so that they can be resolved.
Enjoy!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Zexion

Wow thanks a lot for this :) gonna try it

Melvin


G_G


Jragyn

Instead of drawing an icon, could the sprite within the event just... glow or something? Or both.

Just an idea.
A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Zexion

I forgot to say that this script is not compatible with some of the other ones I have mainly blizz abs. It causes a wierd bug in my cutscenes like it leaves ghost pixels, ghost maps, and screen flashes linger. But if i take out blizz abs it works fine! Is there a way to make them compatible? I really like this script so I don't want to give up on it lol

LiTTleDRAgo

Quoteclass Spriteset_Map
 
  alias zer0_icon_dispose dispose
  def dispose
    # Dispose the icons when the map is disposed
    $game_map.events.each_value {|event| event.dispose_icons }
    zer0_icon_dispose  # Missing?
  end
end

ForeverZer0

May 18, 2011, 09:27:02 pm #7 Last Edit: May 19, 2011, 01:09:32 am by Baraka
Fixing now, thanks for pointing it out.  :D

I'm actually changing the whole thing. I should have had all the actual processing in Sprite_Character to begin with, it will allow for a lot easier manipulation and more features.

Should have it up within the hour.


EDIT:

Updated to version 1.1
- Fixed the above mentioned bugs
- Added the "glow" option instead of using icons
- Totally restructured the script
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

PhoenixFire

I might be hijacking this script as well...      Maybe...

I haven't tested it out yet, but, I like the glowing concept. I might bother you about it later, but, for right now, I'm at work, so, no downloading to company computers  :facepalm:

Damn corporate rules :rulez:
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

Shalaren

error of something in line 162, undefined method, only happens with blizz-abs

G_G

Did you place this below or above Blizz-ABS?

Shalaren

*facepalm*
I take my bug report back! Thanks g_g

Zexion

Thanks you fixed the bug it had before, the ghost pixels and all! However I forgot to mention the other bug, err i did mention it but the post didn't go through and i was too tired to re-do it lol.
Anyways...the other bug was, the icon only triggers on one event on my map. The event that triggers it doesn't have a tag on it, but it shows up on the event with the tag. I know it sounds confusing so I made a pic.
Spoiler: ShowHide

ForeverZer0

You mean the wrong event is getting the icon?

ie. Event_A has a comment Tag, but the icon appears over Event_B?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Zexion

Quote from: ForeverZer0 on May 22, 2011, 03:46:52 am
You mean the wrong event is getting the icon?

ie. Event_A has a comment Tag, but the icon appears over Event_B?


Yes exactly! Except it only happens to 1 event. The other event with tags doesn't show at all Idk why.

Raziel 0128

Your script works nicely and is very useful but I've discovered an error with it.
If you attempt to save on a map using this code then you will get the following error:
"Script 'Scene_Save' Line 80: Type error occurred.
no marshal_dump is defined for class Bitmap"

This happens in your demo as well.
In future versions could you also allow glowing AND icons at the same time, for example if I wanted to have one item glow but another bring up a speech bubble?

yuhikaru

Another bug I found was that if the actual event page has a tag, and you change the event page while the player is within it's range, but the new event page doesn't have a tag, the icon won't be erased until you exit the map. (Example: Chest with tag 'OPEN', and when it's open doesn't have any tag).
I tried to correct it with this change, but I don't know if it's a good approach. Apparently works.
def update_icons
    # Return if no icons exist for page, or set icon if none is defined
    if @character.icons.empty?
      @icon_sprite.dispose  #ADD THIS LINE
      return
[....]

(And just a little bump on the save error thing).

Taiine

Don't mean to bump this. But I'm hoping for a fix to the
"Script 'Scene_Save' Line 80: Type error occurred.
no marshal_dump is defined for class Bitmap"
error on saving.

I was hoping to use this to mark exits that may not be fully obvious to some (like side door ways in homes) but that error when trying to save is proving problematic.

ForeverZer0

Ah, yes, I keep forgetting about this one.
I'll make a note and fix it within the next day or so.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Taiine

*sits and waits for that next day or so* XD