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.

need help with icon status script

KAIRE

Member

a day ago i asked about using icons as status display instead of the default text and i was given a script... this script works, it replace the text with any icons i choose. however it's not a finish script....

the script: (paste above _main)
Code:
class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Make State Text String for Drawing
  #     actor       : actor
  #     width       : draw spot width
  #     need_normal : Whether or not [normal] is needed (true / false)
  #--------------------------------------------------------------------------
  def make_battler_state_text(battler, width, need_normal)
    # Make text string for state names
    text = []
    for states in battler.states
      unless $data_states[states].rating == 0
        next if states == nil
        text << $data_states[states].name
      end
    end
    # Return completed text string
    state_text = text.size == 0 ? "" : text
    return state_text
  end
  #--------------------------------------------------------------------------
  # * Draw State
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_state(actor, x, y, width = 120)
    text = make_battler_state_text(actor, width, true)
    self.contents.font.color = actor.hp == 0 ? knockout_color : normal_color
    for i in text
      self.contents.blt(x + text.index(i) * 32, y, RPG::Cache.icon(i), Rect.new(0, 0, 32, 32))
    end
  end
end

as you can see, there is no draw states for eneny but only actor...
so durring battle when an enemy is poison or whatever, the game froze and give an error in the window_help because it can not detect the enemy status...

window_help error(highlight in read.)
Code:
class Window_Help
  def set_enemy(enemy)
    text = enemy.name
    state_text = make_battler_state_text(enemy, 112, false)
    if state_text != ""
      [COLOR=Red]text += "  " + state_text[/COLOR]
    end
    set_text(text, 1)
  end

i need someone help here to make this work. thank you
 
Problem is that you're hoping to add icon graphics into a 'string'.

Cranked this out

Code:
#==============================================================================
# ** Window_Help
#------------------------------------------------------------------------------
#  This window shows skill and item explanations along with actor status.
#==============================================================================
class Window_Help < Window_Base
  #--------------------------------------------------------------------------
  # * Set Enemy
  #     enemy : name and status displaying enemy
  #--------------------------------------------------------------------------
  def set_enemy(enemy)
    x = (self.width - 32)/ 2
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, x - 8, 32, enemy.name, 2)
    text = make_battler_state_text(enemy, width, true)
    self.contents.font.color = enemy.hp == 0 ? knockout_color : normal_color
    for i in text
      self.contents.blt(8 + x + text.index(i) * 32, y, RPG::Cache.icon(i), Rect.new(0, 0, 32, 32))
    end
  end
end
What I did was divide the help window into two halves. The left half will show the enemy's name (right justified) and the right side will show the status icons.

It's not the BEST way to do it. But a better method would gauge the width of a text string 'before' it is drawn, then determine the proper position of the enemy name and the total number of icons.
 

KAIRE

Member

you know what I just found out... your code
Code:
#==============================================================================
# ** Window_Help
#------------------------------------------------------------------------------
#  This window shows skill and item explanations along with actor status.
#==============================================================================
class Window_Help < Window_Base
  #--------------------------------------------------------------------------
  # * Set Enemy
  #     enemy : name and status displaying enemy
  #--------------------------------------------------------------------------
  def set_enemy(enemy)
    x = (self.width - 32)/ 2
    self.contents.clear
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 0, x - 8, 32, enemy.name, 2)
    text = make_battler_state_text(enemy, width, true)
    self.contents.font.color = enemy.hp == 0 ? knockout_color : normal_color
    for i in text
      self.contents.blt(8 + x + text.index(i) * 32, y, RPG::Cache.icon(i), Rect.new(0, 0, 32, 32))
    end
  end
end
Doesn't really work... I mean it does, but there's a bit of a problem. Normally when you select attack from the command in battle and selecting an enemy target would shows the enemy name and such but with this script it doesn't. No help window pop ups with targeted enemy name when selecting normal attack. And what it shows in the help window sometime is messed up. Like it shows an enemy name instead of the selected spell or when the enemy/hero is attacking it sometime shows the enemy name instead of the spell they cast. it's weird and I know it's this code because I've tested it out with the code and without the code. without your code I go back to problem in post #1. with your code i have this problem...

Can I get some help on this? anybody can you fix this for me? Thanks.

And is the icon status code i have up there even complete? And who made it?


EDIT: I think I fixed it. I'm not sure but it seems right after I added
@text = nil
self.visible = true
 

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