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.

[RESOLVED] Disposed Sprite help [RMXP]

EDIT: Resolved, i figured it out. its not hard aha XD
Hey Guys!

I've been tinkering with this Event Name Display script, trying to get it to show enemy names when used with Mr Mo's ABS.

It works, but on some events it causes a Disposed Sprite error.
Can anyone see the loophole here?
It occurs at line 243.

Code:
#==============================================================================

# ** Event Text Display

#==============================================================================

# Created By: Áص¹

# Modified By: SephirothSpawn

# Modified By: Me™

# Version 2.1

# 2006-03-04

#==============================================================================

# * Instructions :

#

#  ~ Creating Event With Test Display

#   - Put a Comment on the Page With

#   [CD____]

#   - Place Text to Be Displayed in the Blank

#------------------------------------------------------------------------------

# * Customization :

#

#  ~ NPC Event Colors

#   - Event_Color = Color

#

#  ~ Player Event Color

#   - Player_Color = Color

#

#  ~ Player Text

#   - Player_Text = text_display *

#

#  ~ text_display

#   - 'Name', 'Class', 'Level', 'Hp', 'Sp'

#==============================================================================

 

#------------------------------------------------------------------------------

# * SDK Log Script

#------------------------------------------------------------------------------

SDK.log('Event Text Display', 'SephirothSpawn', 2, '2006-03-04')

 

#------------------------------------------------------------------------------

# * Begin SDK Enable Test

#------------------------------------------------------------------------------

if SDK.state('Event Text Display') == true

 

#==============================================================================

# ** Game_Character

#==============================================================================

 

class Game_Character

  #--------------------------------------------------------------------------

  # * Dispaly Text Color (Event & Player)

  #--------------------------------------------------------------------------

  Event_Color = Color.new(166, 255, 0)

  Player_Color = Color.new(68, 245, 255)

  Enemy_Color = Color.new(255, 61, 0)

  #--------------------------------------------------------------------------

  # * Display Choices

  # ~ 'Name', 'Class', 'Level', 'Hp', 'Sp'

  #--------------------------------------------------------------------------

  Player_Text = 'Name'

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_accessor :text_display

end

 

#==============================================================================

# ** Game_Event

#==============================================================================

 

class Game_Event < Game_Character

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  alias seph_characterdisplay_gevent_refresh refresh

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    # Original Refresh Method

    seph_characterdisplay_gevent_refresh

    # Checks to see if display text

    # If the name contains CD, it takes the rest of the name as the text

    unless @list.nil?

      for i in 0...@list.size

        if @list[i].code == 108

          @list[i].parameters[0].dup.gsub!(/\[[Cc][Dd](.+?)\]/) do

            @text_display = [$1, Event_Color]

          end

                     @list[i].parameters[0].dup.gsub!(/ID (.*)/) do

            @text_display = [$data_enemies[$1.to_i].name, Enemy_Color]

                    end

          @list[i].parameters[0].dup.gsub!(/\[[Ee][Nn](.+?)\]/) do

            @etext_display = [$1, Enemy_Color]

          end

        end

      end

    end

    @text_display = nil if @erased

    #@text_display = nil if @erased

  end

end

 

#==============================================================================

# ** Game_Player

#==============================================================================

 

class Game_Player < Game_Character

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  alias seph_characterdisplay_gplayer_refresh refresh

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh

    # Original Refresh Method

    seph_characterdisplay_gplayer_refresh

    # Gets First Actor

    actor = $game_party.actors[0]

    # Determines Text

    case Player_Text

    when 'Name'

#      txt = $game_party.actors[0].name + ", #{actor.level}"

    if Network::Main.group == 'admin'

      txt = $game_party.actors[0].name + ", #{Network::Main.id}"

    else

      txt = $game_party.actors[0].name

    end

    

    when 'Class'

      txt = actor.class_name

    when 'Level'

      txt = "Lvl: #{actor.level}"

    when 'Hp'

      txt = "HP: #{actor.hp} / #{actor.maxhp}"

    when 'Sp'

      txt = "SP: #{actor.sp} / #{actor.maxsp}"

    else

      txt = ''

    end

    # Creates Text Display

    @text_display = [txt, Player_Color]

    

  end

end

 

#==============================================================================

# ** Sprite_Character

#==============================================================================

 

class Sprite_Character < RPG::Sprite

  #--------------------------------------------------------------------------

  # * Alias Listings

  #--------------------------------------------------------------------------

  alias seph_characterdisplay_scharacter_update update

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Original update Method

    seph_characterdisplay_scharacter_update

    # Character Display Update Method

    update_display_text

    if $game_temp.new_guild

            @_g_display = nil if @_g_display != nil

            $game_temp.new_guild = false

    end

  end

  #--------------------------------------------------------------------------

  # * Create Display Sprite

  #--------------------------------------------------------------------------

  def create_display_sprite(args)

    # Creates Display Bitmap

    bitmap = Bitmap.new(160, 24)

    bitmap.font.name = "Comic Sans MS"

    bitmap.font.size = 16

      

    # Draws Text Shadow

    if bitmap.font.respond_to?(:draw_shadow)

      bitmap.font.draw_shadow = false

    end

    bitmap.font.color = Color.new(0, 0, 0)

    bitmap.draw_text(1, 1, 160, 24, args[0], 1)

    # Changes Font Color

    bitmap.font.color = args[1]

    # Draws Text

    bitmap.draw_text(0, 0, 160, 24, args[0], 1)

    # Creates Display Text Sprite

    @_text_display = Sprite.new(self.viewport)

    @_text_display.bitmap = bitmap

    @_text_display.ox = 80

    @_text_display.oy = 24

    @_text_display.x = self.x

    @_text_display.y = self.y - self.oy / 2 - 24

    @_text_display.z = 30001

    @_text_display.visible = self.visible #true

  end

  

  def create_display_guild(args)

    # Creates Display Bitmap

    bitmap = Bitmap.new(160, 24)

    bitmap.font.name = "Comic Sans MS"

    bitmap.font.size = 16

      

    # Draws Text Shadow

    if bitmap.font.respond_to?(:draw_shadow)

      bitmap.font.draw_shadow = false

    end

    bitmap.font.color = Color.new(0, 0, 0)

    bitmap.draw_text(1, 1, 160, 24, args[0], 1)

    # Changes Font Color

    bitmap.font.color = args[1]

    # Draws Text

    bitmap.draw_text(0, 0, 160, 24, args[0], 1)

    $old_guild = args[0]

    # Creates Display Text Sprite

    @_g_display = Sprite.new(self.viewport)

    @_g_display.bitmap = bitmap

    @_g_display.ox = 80

    @_g_display.oy = 24

    @_g_display.x = self.x

    @_g_display.y = self.y - self.oy / 2 - 24

    @_g_display.z = 30001

    @_g_display.visible = self.visible #true

  end

  

  #--------------------------------------------------------------------------

  # * Dispose Display Sprite

  #--------------------------------------------------------------------------

  def dispose_display_text

    unless @_text_display.nil?

      @_text_display.dispose

      $game_map.need_refresh = true

    end

  end

  

  #--------------------------------------------------------------------------

  # * Update Display Sprite

  #--------------------------------------------------------------------------

  def update_display_text

   unless @character.text_display.nil?

      if @_text_display.nil?

        create_display_sprite(@character.text_display)

      end

      @_text_display.x = self.x

      @_text_display.y = self.y - self.oy / 2 - 24

   else

      unless @_text_display.nil?

        dispose_display_text

      end

    end

 

   unless !@character.is_a?(Game_Player)

    if $old_guild != $game_temp.guild_name and @_g_display != nil

      @_g_display.dispose

      @_g_display = nil

      create_display_guild([$game_temp.guild_name,Window_Edits::Guild_color])

    end

    if $game_temp.guild_name != ""

      if @_g_display.nil?

        create_display_guild([$game_temp.guild_name,Window_Edits::Guild_color])

      end

      @_g_display.x = self.x

      @_g_display.y = self.y - self.oy / 2 - 35

    end

   else

      unless @_g_display.nil?

      @_g_display.dispose

      $game_map.need_refresh = true

      end

    end

  end

  

end

 

#--------------------------------------------------------------------------

# * End SDK Enable Test

#--------------------------------------------------------------------------

end

Thanks
 

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