Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Event/Quest Icons

This script is currently being updated. Don't use it at the moment unless you really want to. There are a few annoying bugs & kinks to work out.

SG Event Icons
Version: 2

Introduction
Allows you to have icons that will be shown on events and follow them around the screen.

Note for wannabe scripters: Don't try to learn from this one!

Screenshots
From alexia testing out an earlier version,
http://i145.photobucket.com/albums/r228 ... sticon.png[/IMG]

More screenshots are a couple posts down. :)

Features
  • Compatible with almost everything
  • Fades in while appearing
  • Optional saved settings per map, or reset after changing maps
  • Preset optional icon coordinate placement for RTP characters, centered above them
  • Shortcuts for often used icons
  • Very easy to set up
  • Very simple call script per icon
Script
Code:
#==========================================================================
# ** SG Event Icons
#==========================================================================
# sandgolem 
# Version 2
# 21.01.07
#==========================================================================

SG_EventIcon_DefaultOpacity = 60
SG_EventIcon_MaxOpacity = 180
SG_EventIcon_FadeInSpeed = 3

SG_EventIcon_MapMemory = true
  # Switch this to false to disable the map's icons from being remembered.
  
SG_EventIcon_Types = {
  1 => '001-Weapon01',
  2 => '002-Weapon02' }
  # These are shortcuts you can use instead of always putting in a file name.

#==========================================================================
#
# To check for updates or find more scripts, visit:
# http://www.gamebaker.com/rmxp/scripts/
#
# Need help? Support topic:
#   http://forums.gamebaker.com/showthread.php?t=701
#
#==========================================================================

if Object.const_defined?('SDK')
  SDK.log('SG Event Icons', 'sandgolem', 2, '21.01.07')
  if SDK.state('SG Event Icons') != true
    @sg_eventicons_disabled = true
  end
end

if !@sg_eventicons_disabled
#--------------------------------------------------------------------------

class Game_Temp
  attr_accessor :sg_eventicon_sprites
  
  def sg_eventicon_dispose
    return if !@sg_eventicon_sprites
    @sg_eventicon_sprites.each { |i| i.dispose if i != nil }
    @sg_eventicon_sprites = []
  end
end

class Game_Map
  attr_accessor :sg_eventicons
  
  def sg_geteventicons
    return @sg_eventicons if !SG_EventIcon_MapMemory
    return @sg_eventicons[@map_id]
  end

  def sg_geteventicons=(new)
    if !SG_EventIcon_MapMemory
      @sg_eventicons = (new)
    else
      @sg_eventicons[@map_id] = (new)
    end
  end
  
  def sg_cleareventicons
    for i in 0...@sg_eventicons[@map_id].size
      return if @sg_eventicons[@map_id][i] != nil
    end
    @sg_eventicons[@map_id] = nil
  end
  
  alias sandgolem_eventicons_mapsetup setup
  def setup(map_id)
    if !@sg_eventicons or @map_id != map_id
      if !SG_EventIcon_MapMemory
        @sg_eventicons = []
      else
        @sg_eventicons = {} if !@sg_eventicons
        sg_cleareventicons if @sg_eventicons[@map_id]
        @sg_eventicons[map_id] = [] if !@sg_eventicons[map_id]
      end
      $game_temp.sg_eventicon_dispose
      $game_temp.sg_eventicon_sprites = []
    end
    sandgolem_eventicons_mapsetup(map_id)
  end
  
  def sg_eventicon_opacity(opac = SG_EventIcon_DefaultOpacity)
    return if !$game_temp.sg_eventicon_sprites
    $game_temp.sg_eventicon_sprites.each { |i| i.opacity = opac if i != nil }
  end
  
  def sg_eventicon_show
    # Called by the start of Scene_Map, redraws old icons
    if !$game_map.sg_geteventicons
      $game_map.sg_geteventicons = []
      $game_temp.sg_eventicon_sprites = []
    end
    return if $game_map.sg_geteventicons == []
    for i in 0...$game_map.sg_geteventicons.size
      z = $game_map.sg_geteventicons[i]
      next if z == nil
      sg_eventicon(z[0],z[1],z[2],z[3])
    end
    sg_eventicon_opacity
  end
  
  def sg_eventicon(event,type,xoff,yoff)
    $game_temp.sg_eventicon_sprites = [] if !$game_temp.sg_eventicon_sprites
    icon = SG_EventIcon.new
    $game_temp.sg_eventicon_sprites += [icon]
    icon.event = @events[event]
    icon.xoff = xoff
    icon.yoff = yoff
    icon.x = @events[event].screen_x + xoff
    icon.y = @events[event].screen_y + yoff    
    icon.bitmap = RPG::Cache.icon(type)
    icon.z = 541
    icon.opacity = SG_EventIcon_DefaultOpacity
  end
end

class Scene_Map 
  alias sandgolem_eventicons_transfer transfer_player
  def transfer_player
    $game_map.sg_eventicon_opacity(0)
    sandgolem_eventicons_transfer
    $game_map.sg_eventicon_show
  end
  
  alias sandgolem_eventicons_mapmain main
  def main
    $game_map.sg_eventicon_show
    sandgolem_eventicons_mapmain
    $game_temp.sg_eventicon_dispose
  end
  
  alias sandgolem_eventicons_mapupdate update
  def update
    sandgolem_eventicons_mapupdate
    $game_temp.sg_eventicon_sprites.each { |i| i.update if i != nil }
  end
end

def sg_eventicon(event,type,xoff = -12,yoff = -74)
  type = SG_EventIcon_Types[type] if type.is_a?(Numeric)
  $game_map.sg_geteventicons += [[event,type,xoff,yoff]]
  $game_map.sg_eventicon(event,type,xoff,yoff)
end
  
def sg_uneventicon(event)
  z = $game_map.sg_geteventicons
  for i in 0...z.size
    if z[i] != nil && z[i][0] == event
      z[i] = nil
      $game_temp.sg_eventicon_sprites[i].dispose
      $game_temp.sg_eventicon_sprites[i] = nil
    end
  end
  z.delete(nil)
  $game_temp.sg_eventicon_sprites.delete(nil)
end

class SG_EventIcon < Sprite
  attr_accessor :eventid, :event, :xoff, :yoff, :type
  
  def update
    if self.opacity < SG_EventIcon_MaxOpacity
      self.opacity += SG_EventIcon_FadeInSpeed
    end
    self.x = @event.screen_x + @xoff
    self.y = @event.screen_y + @yoff
  end
end

#--------------------------------------------------------------------------
end

Instructions
Script goes somewhere above main, under the other default scripts.

Icons are triggered to appear & go away via call scripts. You can either do this by autorun events or during any others.

To make an icon appear:
Code:
sg_eventicon(4,1)
Puts icon #1 above character 4 at the default position

Code:
sg_eventicon(27,'003-Weapon03')
Puts icon '003-Weapon03' above character 27

Code:
sg_eventicon(11,1,-12,-50)
Puts icon #1 above character 11 at a new x & y coordinate based on his own. You'll need to play around with the numbers a little.

To get rid of all the icons associated with one event:
Code:
sg_uneventicon(9)

Compatibility
Should work with everything, though if you're using other scripts and there's a problem please post a link to it.

Last minute bug report: Breaks old saved games if you decide to switch icons being remembered per map. I'm not going to bother fixing that one unless someone really needs it

Merci Beaucoups
Alexia for requesting a script I actually wanted to make :)
 
Nice. Looks very good.


I have a suggestion though: why not create a sub-sprite in Sprite_Character, create it and move it accordingly? To me this would be more simple and have less lag. That's what I did here, just incase you like the idea. ;)

Perhaps event commenting could make things easier as well rather than auto-start event with a bunch of call scripts. Just my opinion.


Good stuff sandgolem. Very neat.
 
Sandgolem, thanks for creating this! This script is actually pretty versatile and can be used in different ways.

**EDIT**
Just thought of another use for this script. You could use this script to identify merchants and the like. Another thing you could do is identify an important person that the player has to talk to before progressing in the story. As I said before, very versatile.

This is how I'll be using it in my game.

http://i145.photobucket.com/albums/r228 ... iconex.png[/IMG]

Once the player accepts the quest, a page will appear over the npc's head. This coordinates with the journal that the main protagonist keeps.

**2nd Edit**
Here's another screen you might want to use.

http://i145.photobucket.com/albums/r228 ... screen.png[/IMG]

Btw, I was able to add more short cuts. Thanks for making the script easy to customize.
 
This is much like FFXII's npc system. The quest/recipiant idea is good too, like World of Warcraft with quest starters having a '!' above their head and people involved in quests having a '?' above.
 
Glad you like it Alexia. :)

SephirothSpawn said:
why not create a sub-sprite in Sprite_Character, create it and move it accordingly?
I tried it originally, but it didn't perform as well with a few events having them. I probably didn't optimize it right though, I'll check your script to see how you did. Something to try again if I update this or make a similar script. :)

SephirothSpawn said:
Perhaps event commenting could make things easier as well rather than auto-start event with a bunch of call scripts
I didn't even think of doing that. Does it hurt map loading time much to have a script go through all events commands looking for them?
 
Sorry for posting so quick between, er.. posts, but is there a way to make the icon fade in when a player is a certain distance away? Maybe 4-6 squares away, and then fade out as the player moves away.
 
Didn't notice your first post until you mentioned it :) But yes, I can write a quick patch for that if you'll use it. It would affect all the icons though and not just specific ones.
 
I didn't even think of doing that. Does it hurt map loading time much to have a script go through all events commands looking for them?

I haven't noticed any drastic loading time change. This is all there really is to it:
Code:
#==============================================================================
# ** Game_Event
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_etd_gmevt_refresh refresh
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Original Refresh Method
    seph_etd_gmevt_refresh
    # Erase ETD Display Text
    @etd_display_text = nil
    # Checks to see if display text
    unless @list.nil? || @erased
      for i in 0...@list.size
        if @list[i].code == 108
          @list[i].parameters[0].dup.gsub!(/\[[Ee][Tt][Dd](.+?)\]/) do
            @etd_display_color = ETD_Default_EventText_Color
            @etd_display_text = $1
          end
        end
      end
    end
  end
end

That isn't extremely optimized, but works fairly well.
 
This is great, its usefull to a Diablo game or a harvest moon, this really pretty..
but i get an error when i go to the menu, says an error about "[]"..
and when i go to another map, and back to the previus map the icons have opacity of 255 and i call the script to erase the icon and the icon is not erase... what happen?
 
Evilupstart;139201 said:
Sorry for posting so quick between, er.. posts, but is there a way to make the icon fade in when a player is a certain distance away? Maybe 4-6 squares away, and then fade out as the player moves away.
Use the View Range script and add the follwoing red line in the update method of the SG_EventIcon class
Code:
class SG_EventIcon < Sprite
  attr_accessor :eventid, :event, :xoff, :yoff, :type
  
  def update
    [COLOR=Red]self.visible = VR.in_range?(@event, $game_player, 6)[/COLOR]
    if self.opacity < SG_EventIcon_MaxOpacity
      self.opacity += SG_EventIcon_FadeInSpeed
    end
    self.x = @event.screen_x + @xoff
    self.y = @event.screen_y + @yoff
  end
end
You can replace that 6 for the range you want.
 
sandgolem, I received a weird error. I was able to call the icon and dispose it. But after I disposed the icon, I opened the menu, which was fine. But when I pressed esc to exit the menu, I received the following error:

Script 'QuestIcon' line 104: NoMethodError occurred.
undefined method '[] for nil:NilClass

btw, the brackets are actually supposed to be a box. Any ideas on what is causing this?
 
Alexia,
Hmm... I thought I fixed that earlier today. Weird. Give me a few minutes to test again and you'll have your update. :)

script updated
Changes are only in sg_eventicon_show & sg_uneventicon if anyone's done much editing. Please let me know if there's any more problems, I might've undid that fix for a reason.

Mephisto,
It sounds like you might have another script conflicting. Try the update and if you still have the same problem, which others are you using?
 
Hey, sorry to bother you again, but I received another error. This time, I did not initialize any icons but tried to load a saved game. I received an error on line 142. It said "undefined method 'each' for nil:NilClass.

Also, with the other error, it happened after I disposed the icon. The menu worked fine after I initialized it.

**EDIT**
Hold on, I didn't see your update. Let me try that one and see if it possibly fixes the other error.

**2nd EDIT**
Okay, I'm still receiving the same error when I try to load a saved game. Now it's on line 143. Do you know what might be causing this?
 
Try putting this in the Game_Temp area of this script, line 43ish: (between the attr_ & def lines)

Code:
  alias sandgolem_eventicons_init initialize
  def initialize
    sandgolem_eventicons_init
    @sg_eventicon_sprites = []
  end
 
Well, i have the

character icon graphics by sephirotspawn
Multiples currencyes by sandgolem.XD
artifacts colors by you
map autoscroll.-

and its all!
 
Those don't sound like they would cause problems. If you zip up your project's data directory (not the full thing!) and PM it to me, I'll take a look at it.

I'll be implementing a couple more features into this soon - the fix above, icons via comments (Thanks Sephy), ranged fading & better icon management. Please be quick if you have any other bug reports or good ideas on what to add. :)
 
I have a suggestion sandgolem ^_^
Maybe you could have a switch that turns on when the health of the player is at x% and the icon of the users choice would appear above the player. This could be useful to lots of people. It'd just be a reminder to heal :)
Well, great script ^_^
Your Friend,
Dylan ;)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top