Event Proximity Icons
Authors: ForeverZer0
Version: 1.4
Type: Event Add-On
Key Term: Misc Add-on
IntroductionThis 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(http://dl.dropbox.com/u/20787370/Scripts/Event%20Proximity%20Events/EventProx1.png)
(http://dl.dropbox.com/u/20787370/Scripts/Event%20Proximity%20Events/EventProx2.png)
DemoDemo Link (https://dl.dropbox.com/u/20787370/Scripts/Event%20Proximity%20Icons.zip)
Script#+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
# 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
InstructionsPlace above "Main", and below default scripts.
Instructions are within the script.
CompatibilityPixel 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.
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 NotesPlease report any bugs/issues so that they can be resolved.
Enjoy!
Wow thanks a lot for this :) gonna try it
Lol! :D Good script!!
Nice job F0!
Instead of drawing an icon, could the sprite within the event just... glow or something? Or both.
Just an idea.
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
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
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 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:
error of something in line 162, undefined method, only happens with blizz-abs
Did you place this below or above Blizz-ABS?
*facepalm*
I take my bug report back! Thanks g_g
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.
(http://img813.imageshack.us/img813/8871/errork.png)
You mean the wrong event is getting the icon?
ie. Event_A has a comment Tag, but the icon appears over Event_B?
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.
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?
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).
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.
Ah, yes, I keep forgetting about this one.
I'll make a note and fix it within the next day or so.
*sits and waits for that next day or so* XD
* Updates script to version 1.2 *
Fixed the bug with save data. I was storing Bitmaps in a class that gets marshaled, and Bitmaps are not able to be marshaled.
I ended up just moving the icons to a hash in Game_Temp that gets changed whenever the map is loaded.
Thanks to Taiine for her reminders. ;)
Your script don't like BABS. :P
I was discovering an oddity with in my game. It seemed the icons didn't want to show up when you drew near the event, but rather a space up and to the left of it.
(http://images.devs-on.net/Image/wwsfCqHIqT5DbpH-Region.png)
My games test map. Girl at the very bottom has a red orb behind her head that appears not when you get close to her, but rather when I step into where I am (the guy with the white hair)
This also happens in your demo when the BABS is added to it. The icons no longer show when you move near the event, but rather when you move close to the distance I show here.
Its the pixel movement, it messes with the coordinates.
I'll see if I can add some compatibility, I always forget about pixel-movement in BABS...
Ah good I've been waiting for this. Thanks for the fix.
*pokes the stubborn script*
Probably won't be until tomorrow. I'm setting up a fresh install of an OS right at the moment. That's gonna be a few hours minimum.
I did get RMXP reinstalled already if thats any consolation. ;)
*puts a sticky note on FZ's forehead as a reminder!* :naughty:
*double posts to add another sticky note to FZ0's forehead as a reminder to check her last reminder!*
;)
>.>
<.<
(http://www.practicallyefficient.com/wp-content/uploads/2010/09/sticky-note-man-pe.png)
*runs*
But really, have less then 7 days before my nets cut off, really hoping to have this before then. :(
* Updates script to v.1.3 *
It is now compatible with Blizz-ABS pixel-movement.
*add's another sticky note with her thanks on it*
XD
This script is fantastic and very use friendly.
I used to place a question mark on top of the NPCs that give quest to the player on my game. I discover a small bug when you use local switch. Example: When you talk to an NPC I add the quest to the player and use the comment to show the quest icon, then I active the first local switch so the NPC shows a different message, and I use no comments because in this case I don't want to show the icon (because the quest is already taken. Here is the problem, when the second conversation ends, the icon don't dissapear and begin to move when the players do.
I resolved myself this problem adding (in configuration) a new comment to the script with no content and adding in the second switch a comment with no content:
TAGS = ['quest', 'SEARCH', 'ATTACK', '']
# These are th codes that will be searched for in event page comments
ICONS = ['quest', 'search', 'attack', '']
# These are the filenames of the respective codes, located in Pictures folder
Thanks to ForeverZer0, I was doing this with events and was a really hard work, now is so easy using this script.
I done goofed
(http://www.mediafire.com/convkey/ad65/bhuu7fa0vmw2uiu5g.jpg)
Switched tags to TAGS = "['Event', 'Search', 'Enemy']" and all the Pictures corresponds.
The error begins after the title screen when entering a map. I disabled Glow_Only
Drago's Smooth Scroller probably conflicts with this.
I know this topic is kinda old and they necroposted but I just wanted to give ForeverZer0 props for creating this haha
I seriously requested the same thing but with windows like 2 years ago haha
(http://i1070.photobucket.com/albums/u499/Landith1/coincidence.png)
This is so much cooler though because it gives a whole new interactive element to your game.
Just nice job on such a simple script :)
I edited the script coords so that the icon would show on your character's head and would like to know if how I made it is correct and won't give me any trouble in the future.
Lines are these (193-194):
@icon_sprite.x = $game_player.screen_x - 5
@icon_sprite.y = $game_player.screen_y - 58
It works but since I don't know how to script I'd rather ask to be 100% sure. (The minus values are there because without them the icon shows at the bottom of your character.)
After some more testing I've found that if a map contains more than one event proximity icon and you save and reload you get the following error:
"Script 'Proximity Icons' line 140: NoMethodError occurred.
undefined method '[]' for nil:Nilclass"
This occurs even in a fresh project with just this script installed. For example if you create two npcs with TALK or one npc with TALK and SEARCH either will crash the game when reloaded from a save.
I've been getting the same error Raziel has been getting.
Even if I don't have an event with a comment in it I still get the same error whenever I kill an enemy/use a skill that has a sprite on it.
(I use BABS)
flag = $game_temp.proximity_data[character.id][0]
That line is line 140 if that helps.
Hey F0, I'm thinking about using this script, but the bug that Raziel and Landith have been having,
makes this difficult, because I'm planning to have multiple quests in the same map in multiple locations.
Any chance you could try to fix this bug?
I'll take a look some after work and see if I can find a fix.
Thanks a bunch.
* Updates script and demo to version 1.4 *
Ok, all fixed. I made a rather amateur mistake when making this. I used a hash in Game_Temp to store sprite data, including the icons. I used Game_Temp simply because it does not get saved, since Bitmaps cannot be saved. That was rather stupid of me, I didn't need to store the icons at all, I can just use string and load them when needed with RPG::Cache using that.
I ended up moving @proximity_data to Game_Map so that it gets saved with and loaded with the game and no more "undefined" errors. Old save files you may try to use will be corrupted, so erase them if you plan on using the new version of the script.
Thank you for fixing this.
level++
Glad I waited before using it, thanks a lot for the fix.
*lvls up*
Thanks for taking the time to fix this I appreciate it.
No problem, it only took a couple of minutes.
Any chance you would see why this script: http://save-point.org/thread-2414.html conflicts with this script?
I get an error:
91 NoMethodError occurred.
Undefined method '[]=' for nil:NilClass
Line is:
$game_map.proximity_data[event.id] = [false, []]
I was thinking on trying a tileset swap for the footstep sound script of G_G to have different versions of sounds without having the need on doubling the maps in my game to be on different tilesets. (In my project you started bare footed so I want to use the bare foot noise then you change clothes and obviously stepping sound will switch too.)
Thanks
this should fix it place this below the tileset swap
class Game_Map
attr_accessor :proximity_data
alias zer02_proximity_setup setup
def setup(map_id)
@proximity_data = {}
zer02_proximity_setup(map_id)
end
end
Yes, it happens because the author of that script does not know how to alias and overwrites the whole method. You *should* be able to simply change the order of the scripts and place this one below that one to fix it instead of adding a redundant alias method.
It made it work, thanks.
Shame the sound doesn't change when I switch tileset but stops if I use a tileset from the database that doesn't give any sound :/
Quote from: Vexus on August 08, 2012, 10:33:33 am
It made it work, thanks.
Shame the sound doesn't change when I switch tileset but stops if I use a tileset from the database that doesn't give any sound :/
you using game guy's terrain step sound script right?
from what I see, the script change the sound based on terrain tag
you can just switch the terrain tag on the map instead switching the entire tile
http://littledrago.blogspot.com/2012/08/rgss-terrain-tag-changer.html
This is going off topic but the same problem with tileset swap happens.
First time you switch sound it works but if you try to revert the sound no sound plays.
Sometime this weekend, I'll make an alternate version of my script. It'll allow you to have multiple sets of sounds per tileset, then with a script call, you'll be able to choose which set of sounds you want to use.
No need to do all that work for me really I can just figure out a work around. (Having double maps till you find some shoes)
Still thanks if you do but if it's time consuming don't worry about it.
Any idea why sometimes events in a whole map or certain event's icon doesn't show?
I got 2 identical maps (For the step sound script to have different sounds) and icons show on one but on the other no icon shows when I go near events.
There's also a problem but I don't know how to create it as it happened randomly (Tough less than 10 times) where an icon wouldn't go away unless you opened/closed menu, go in a new map or go near another event which shows an icon.
No clue.
I would guess that it is some sort of script conflicting with it. Hard to say without a repeatable example.
Well it seems to give problems (Error) if I place it under blizz abs, could it be the cause?
Might be, unfortunately I have no clue what scripts you are using, what order they are in, or a definitive answer as to when it occurs. This makes it pretty much impossible to give you any type of help with the matter.
If you uploaded a project, and maybe got a better idea how to make it reoccur, I might be able to help. If you could even get an idea, like it "it happens 1 out of every 10 times I do this:", it would help tremendously.
For now here's a screenshot of my script list:
(http://img337.imageshack.us/img337/703/scriptsk.png)
[Edit]
Pmed you a demo.
I found the problem, ABSEAL is not updating the events, which is what its supposed to do.
Here is a small script, which I will add to the main post, which will fix this issue.
It basically just tells ABSEAL to update the event if it is a proximity event and within ABSEAL's range.
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
Place it below BlizzABS the scripts.
yes, yes, yes, YES! *POWERS UP* I've been craving a script like this. To think I was about to call it quits with rpg maker. I have some new ideas :o
Sorry for the necropost but I'm getting an error on line 133:
flag = $game_map.proximity_data[character.id][0]
When an event is attacking me (Using Blizz abs)
Error is:
NoMethod error occurred.
undefined method '[]' for nil:Class.
This doesn't happen all the time but it happens quite often.
try change that line to
flag = (($game_map.proximity_data||={})[character.id]||=[])[0]
Thanks that seems to have fixed the error :)
Hello, ForeverZer0! I am using your scrip for my game, and it works great! There's just one thing, however; I use a lighting system that makes your events dark, and that's not what I need. I noticed you have a "show over top of everything" setting which fixed that particular issue, but I didn't expect it to show over top of everything including pictures, the player and even the text boxes. I looked into the script and found the viewport setting for when the setting is set to "true," and after some fixing, it shows above my lighting system and below text boxes, but not the player or the pictures. I don't mind it being on top of the player, because it's easier to see, but the pictures thing is kind of annoying. Is there any way to mend the script to make the pictures show over these icons?
Thanks!