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
script Spoiler
#==========================================================================
# ** 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
Expand to see the code.


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:
Content Hidden Spoiler
sg_eventicon(4,1)
Expand to see the code.

Puts icon #1 above character 4 at the default position

sg_eventicon(27,'003-Weapon03')
Expand to see the code.

Puts icon '003-Weapon03' above character 27

sg_eventicon(11,1,-12,-50)
Expand to see the code.

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:
sg_uneventicon(9)
Expand to see the code.


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. :)

[QUOTE=SephirothSpawn]why not create a sub-sprite in Sprite_Character, create it and move it accordingly?[/QUOTE]
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. :)

[QUOTE=SephirothSpawn]Perhaps event commenting could make things easier as well rather than auto-start event with a bunch of call scripts[/QUOTE]
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.
Quote:
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:
#==============================================================================
# ** 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 [email hidden]
        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
Expand to see the code.


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?
[QUOTE=Evilupstart;139201]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.[/QUOTE]
Use the View Range script and add the follwoing red line in the update method of the SG_EventIcon class
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
Expand to see the code.

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)

  alias sandgolem_eventicons_init initialize
  def initialize
    sandgolem_eventicons_init
    @sg_eventicon_sprites = []
  end
Expand to see the code.
Worked like a charm. Thanks.
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. :)
Ok, i waiting for the next version...
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 ;)
how would i go about making one appear above the players head?
Yay! Fabulous thing!

But I'd really prefer setting the icons up via event commenting. At the moment I just put an parallel process into each event running the shortcutfor this specific event, then switching a self switch and then moving on to the next eventpage where the real actions are in... works, but leaves me with one less self switch... And setting up a parallel main process for the map (as for BG Music and other stuff) works too but gets awfull laggy in my project if I add the call script. Sooo that would be nice ;)

Another thing is, when the Event moves around and goes somewhere where it is overlapped by a high priority tile, the icon stays visible, which is per se not a bad thing, but I guess if it would fade a litte it'd look nicer. (If that's even possible)

That's it so far ;)

Greets,
Dukey

P.S.: Oh I just found out when using it. I get a weird error when i want to load a savegame.
Look :

http://www.igzorn.phantactics.de/files/ ... veload.png[/IMG]


In line 143 is this method:
def update
    sandgolem_eventicons_mapupdate
    $game_temp.sg_eventicon_sprites.each { |i| i.update if i != nil } # <-- line 143
  end
Expand to see the code.


Any ideas, anyone? ;)

Greets, Dukey
@Duke Igthorn
I guess that is because you saved that slot before adding the script. Try to start a new game and saving in other slot and loading this slot.
tibuda;153112 wrote:
@Duke Igthorn
I guess that is because you saved that slot before adding the script. Try to start a new game and saving in other slot and loading this slot.


Nope that's not it, all saves were created after the inclusion of the script, as I'm aware of this circumstance.
Thanks, anyways ;)

Greets,
Dukey
Did you try this?
http://www.rmxp.org/forums/showpost.php?p=139377&postcount=14
Landarma;153961 wrote:


Ahh silly me! I didn't!
Well I did now and it works like a charm and saves and loads a nicely as a new cargo ship ;)

THANKS A LOT!

It is a bit laggy though, but not too much as it would disturb me greatly...

Greets,
Dukey
I still get the error when I load a game. I already put the thing in Game_Temp.
I might use this, very simple, yet massively effective for multitudes of tasks in a game :) Good job SG!
okay, i've got that to work BUT
all the things with Marshal.load(file) in them start having errors, and when I go into my menu and save and click load it says stack level too deep. When I load a saved game and save it gives me the error. help!
I really want to use this. but if it means seleting 10 other scripts, it's not really worth it.
EDIT: correct me if I'm wrong, so this is how Game_Temp should look, right?
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :map_bgm                  # map music (for battle memory)
  attr_accessor :message_text             # message text
  attr_accessor :message_proc             # message callback (Proc)
  attr_accessor :choice_start             # show choices: opening line
  attr_accessor :choice_max               # show choices: number of items
  attr_accessor :choice_cancel_type       # show choices: cancel
  attr_accessor :choice_proc              # show choices: callback (Proc)
  attr_accessor :num_input_start          # input number: opening line
  attr_accessor :num_input_variable_id    # input number: variable ID
  attr_accessor :num_input_digits_max     # input number: digit amount
  attr_accessor :message_window_showing   # message window showing
  attr_accessor :common_event_id          # common event ID
  attr_accessor :in_battle                # in-battle flag
  attr_accessor :battle_calling           # battle calling flag
  attr_accessor :battle_troop_id          # battle troop ID
  attr_accessor :battle_can_escape        # battle flag: escape possible
  attr_accessor :battle_can_lose          # battle flag: losing possible
  attr_accessor :battle_proc              # battle callback (Proc)
  attr_accessor :battle_turn              # number of battle turns
  attr_accessor :battle_event_flags       # battle event flags: completed
  attr_accessor :battle_abort             # battle flag: interrupt
  attr_accessor :battle_main_phase        # battle flag: main phase
  attr_accessor :battleback_name          # battleback file name
  attr_accessor :forcing_battler          # battler being forced into action
  attr_accessor :shop_calling             # shop calling flag
  attr_accessor :shop_goods               # list of shop goods
  attr_accessor :name_calling             # name input: calling flag
  attr_accessor :name_actor_id            # name input: actor ID
  attr_accessor :name_max_char            # name input: max character count
  attr_accessor :menu_calling             # menu calling flag
  attr_accessor :menu_beep                # menu: play sound effect flag
  attr_accessor :save_calling             # save calling flag
  attr_accessor :debug_calling            # debug calling flag
  attr_accessor :player_transferring      # player place movement flag
  attr_accessor :player_new_map_id        # player destination: map ID
  attr_accessor :player_new_x             # player destination: x-coordinate
  attr_accessor :player_new_y             # player destination: y-coordinate
  attr_accessor :player_new_direction     # player destination: direction
  attr_accessor :transition_processing    # transition processing flag
  attr_accessor :transition_name          # transition file name
  attr_accessor :gameover                 # game over flag
  attr_accessor :to_title                 # return to title screen flag
  attr_accessor :last_file_index          # last save file no.
  attr_accessor :debug_top_row            # debug screen: for saving conditions
  attr_accessor :debug_index              # debug screen: for saving conditions

  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
   #=========================EDIT=================================
    alias sandgolem_eventicons_init initialize
  def initialize
    sandgolem_eventicons_init
    @sg_eventicon_sprites = []
  end
   #=======================END EDIT===============================
    @map_bgm = nil
    @message_text = nil
    @message_proc = nil
    @choice_start = 99
    @choice_max = 0
    @choice_cancel_type = 0
    @choice_proc = nil
    @num_input_start = 99
    @num_input_variable_id = 0
    @num_input_digits_max = 0
    @message_window_showing = false
    @common_event_id = 0
    @in_battle = false
    @battle_calling = false
    @battle_troop_id = 0
    @battle_can_escape = false
    @battle_can_lose = false
    @battle_proc = nil
    @battle_turn = 0
    @battle_event_flags = {}
    @battle_abort = false
    @battle_main_phase = false
    @battleback_name = ''
    @forcing_battler = nil
    @shop_calling = false
    @shop_id = 0
    @name_calling = false
    @name_actor_id = 0
    @name_max_char = 0
    @menu_calling = false
    @menu_beep = false
    @save_calling = false
    @debug_calling = false
    @player_transferring = false
    @player_new_map_id = 0
    @player_new_x = 0
    @player_new_y = 0
    @player_new_direction = 0
    @transition_processing = false
    @transition_name = ""
    @gameover = false
    @to_title = false
    @last_file_index = 0
    @debug_top_row = 0
    @debug_index = 0
  end
end
Expand to see the code.
NO! It should be in other script LOL

class Game_Temp
   #=========================EDIT=================================
    alias sandgolem_eventicons_init initialize
  def initialize
    sandgolem_eventicons_init
    @sg_eventicon_sprites = []
  end
   #=======================END EDIT===============================
end
Expand to see the code.
But this is what he said:

Try putting this in the Game_Temp area of this script, line 43ish: (between the attr_ & def lines)
EDIT: so I tried to do what you said,(to make a new script above main)and it doesn't work!!
EDIT2:When I finish loading a game, it works, but when I go to the menu and load, it says Game_Temp stack level too deep.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=13189