RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
HEARTS for health meter...?

0 Members and 4 Guests are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, this script creates the hearts in the script itself, (rather inefficiently), so if you wanted to do it the same way you would essentially have to simply find an algorithm that makes the star. It would be simpler if you used pictures.

***
Rep:
Level 83
X-PLAT!
here's a screen shot of my latest edit...



now I'm trying to make these "blue hearts" into "yellow stars"

I'm just using a copy of the heart script
(now the STAR script: by changing keywords,alias, HP to SP, etc...)
Spoiler for:
Code: [Select]
################################################################################
# THE "NEW" and "IMPROVED" STAR CONTAINER, STARS FOR MP, STAR SYSTEM SCRIPT!
# revised by ~g/A\/\/\|E|F/A\(C|= 101
# V 1.1(2009) 
#
# original script by DarkRog (2006)
# a BIG special thanks to modern algebra on helping me out on this.
#
# http://rmrk.net/index.php/topic,34542.0.html
#
################################################################################
# Instructions:
#
# Ok Kids! Simply copy and paste above Main like any plug'n'play script!
# Doesn't require any graphics!
# Easy to adjust your very own custom settings!
#
#(optional)
# - 1 switch (default is 2)
# - 1 variable (default is 2)
# you only need to assign a switch to enable/disable display
# and assign a variable to dynamically add/remove stars
################################################################################

class Window_Estrellas < Window_Base

   def initialize
     #super(-8, 410, 640, 96)#-----------=[x,y window position & x,y window size]
     #[bottom left] or
    super(-1, 2, 640, 96)#------------=[x,y window position & x,y window size]
     #[top left]


#[Star Containers] (number of stars you wish to display)
#--------------------------------------------------
#estrellas = 10 #[use this setting for a fixed number of stars] or...
estrellas = $game_variables[1]#to control amount of stars by variable.

#[Opacity] (how clear or solid in appearance)
#--------------------------------------------------
opacidad = 255 #opacity: 0= invisible to 255= solid

#[Options] 0 =Blank 1 =Hero's name 2 =Value/MaxValue 3 =Stars/Maxstars 4 =HP%
#--------------------------------------------------
opcion = 0#info text, review the options above:

      self.contents = Bitmap.new(width - 32, height - 32)
      self.contents.font.name = "Impact"#---------------------------=[FONT TYPE]
      self.contents.font.size = 24#---------------------------------=[FONT SIZE]
      self.z = 3000#-------------------------------------------------=[BLENDING]
      self.opacity = 0 #------------------------------------------=[WINDOW SKIN]
      @stars = estrellas
      @opacity = opacidad
      @option = opcion
      @hr = 0
      refresh
      end
      def refresh
      @stars = $game_variables[1]#-------------------------------=[Variable_ID] 
      self.contents.clear
      @e = $game_party.actors[0].sp
      @me = $game_party.actors[0].maxsp
      #n is the value, and mn the maxvalue:
      @hr = 0
      @lh = 0
#[containers]     #coordinates = i*14,= left point
                  #second number    4,
                  #third number     4,
                  #fourth number    4,                 
      for i in 0..@stars-1
         #self.contents.fill_rect(i*14, 4, 1, 2, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14, 4, 1, 2, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+1, 3, 1, 4, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+2, 2, 1, 6, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+3, 1, 1, 8, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+4, 0, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+5, 1, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+6, 2, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+7, 1, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+8, 0, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+9, 1, 1, 8, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+10, 2, 1, 6, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+11, 3, 1, 4, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+12, 4, 1, 2, Color.new(0, 0, 0, @opacity))
#[outline]     
    self.contents.fill_rect(i*14+1, 4, 1, 2, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+2, 3, 1, 4, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+3, 2, 1, 6, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+4, 1, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+5, 2, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+6, 3, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+7, 2, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+8, 1, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+9, 2, 1, 6, Color.new(255, 255, 255, @opacity))
   self.contents.fill_rect(i*14+10, 3, 1, 4, Color.new(255, 255, 255, @opacity))
   self.contents.fill_rect(i*14+11, 4, 1, 2, Color.new(255, 255, 255, @opacity))
#[fill in]
         @c = 200#red
         @l = @e*100/@me#100
         @ho = @l*@stars   #@c, 200, 100 = yellow
         c_color(1)
         self.contents.fill_rect(i*14+2, 4, 1, 2, Color.new(0, 0, @c, @opacity))
         c_color(2)
         self.contents.fill_rect(i*14+3, 3, 1, 4, Color.new(0, 0, @c, @opacity))
         c_color(3)
         self.contents.fill_rect(i*14+4, 2, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(4)
         self.contents.fill_rect(i*14+5, 3, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(5)
         self.contents.fill_rect(i*14+6, 4, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(6)
         self.contents.fill_rect(i*14+7, 3, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(7)
         self.contents.fill_rect(i*14+8, 2, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(8)
         self.contents.fill_rect(i*14+9, 3, 1, 4, Color.new(0, 0, @c, @opacity))
         c_color(9)
        self.contents.fill_rect(i*14+10, 4, 1, 2, Color.new(0, 0, @c, @opacity))

         @hr += 1
       end
       
#[update]
  def update
    @value=$game_variables[1]#-------------=[to update current amount of Stars]
    $old_sp = $game_party.actors[0].sp#--------=[to update current amount of SP]
  end

#[options]     
      if @option == 1
         self.contents.font.color.set(0, 0, 0)
   self.contents.draw_text(0 - 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 - 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
         self.contents.font.color = normal_color
           self.contents.draw_text(0, 7, 160, 32, $game_party.actors[0].name, 0)
      elsif @option == 2
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@e}/#{@me}", 0)
      elsif @option == 3
         self.contents.font.color.set(0, 0, 0)
      self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@ho/100}/#{@stars}", 0)
      elsif @option == 4
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@l}%", 0)
      end
   end
end
#[color method]
def c_color(a)
if @hr <= (@ho/100)-1
@c = 255 #
else
if @ho/10-@hr*10 >= a and @ho/10-@hr*10 <= 9

@c = 255 #
else
@c = 0 #
end
end
end

#############--------------------------------------=[alias method for Scene_Map]
# Scene_Map #
#############
class Scene_Map
 alias gface2_main main
   def main #MAIN
   @estrellas = Window_Estrellas.new
   gface2_main
   @estrellas.dispose
end
 alias gface2_update update
   def update #UPDATE
   gface2_update

      @estrellas.refresh if $old_sp != $game_party.actors[0].sp
      @estrellas.visible = $game_switches[1]#---------------------=[Variable_ID]
      @estrellas.update
    end
    end

@MA - how could I modify this script to be more efficient in creating the containers?

        - could you point me in the right direction for these algorithms??
          (multiple shapes!? now I'm excited! Stars, Lightning bolts, Diamonds, oh my!!!)

        I've been studying how this script creates and fills containers... still scratching my head (going bald)
        been messing around with these lines of code, no clue as to what I'm doing but I see the changes...
Code: [Select]
#[outline]     
    self.contents.fill_rect(i*14+1, 4, 1, 2, Color.new(255, 255, 255, @opacity))

        - if i were to incorporate pictures, would I have to assign a graphic for each heart and star???

though I have many questions, I'm actively looking for the answers...
and greatly appreciate how far you've brought me in my scripting level...
from 0 to level 0.2 ^,^ ~g
 




**
Rep:
Level 83
Detective Scrotes
would anyone possibly know how to make a "star shape" instead of a heart???

I would like to use this for MP as well...? that's right "Star Containers for MP!"

still working on vertical alignment... ~g


I would suggest you just make a star shape image instead of getting the engine to draw a star itself.

        - if i were to incorporate pictures, would I have to assign a graphic for each heart and star???

No, you would need one image, let's say of a star, called star.png.

Then let's say you have 10 SP and you want 10 stars draw.
Code: [Select]
bitmap = RPG::Cache.picture("star")
scr_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
for i in 0...$game_party.actors[0].sp
  self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)
end

That should draw 10 stars. You might have to fool around with the x position so that they have the correct spacing between them.
« Last Edit: September 17, 2009, 05:19:14 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - thanks for your suggestion... but I'm not so script savvy as you and modern algebra... yet ^,^
maybe years from now, hopefully I will be... but in the mean time I am a neophyte when it comes to Ruby.
I just get lucky making edits here and there...I still need an expert to verify that these scripts are properly written.

so would I start with using something like
Code: [Select]
@stars.bitmap = RPG::Cache.picture("heart graphic")
 

"?"

~g


**
Rep:
Level 83
Detective Scrotes
so would I start with using something like
Code: [Select]
@stars.bitmap = RPG::Cache.picture("heart graphic")
 
Close, however @stars.bitmap will give you an error if bitmap isn't a function of @stars.

You can keep it as just bitmap if you want. All that it is is a variable that is storing the picture file. So just name it what ever you want. You can call it star, bitmap, starbitmap what ever :).

I'll comment the code I wrote so that you can understand every step if you don't know what they do.

Code: [Select]
bitmap = RPG::Cache.picture("star")
This locates the file named "star" in the Graphics/Pictures folder and stores it in the variable "bitmap".

Code: [Select]
scr_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
This creates a new rectangle that is as big as the image. If it is smaller than the image, it would cut off part of the image. So you can think of it as a bounding box.

Code: [Select]
for i in 0...$game_party.actors[0].sp
  self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)
end
These lines will draw the stars. self.contents.blt(x, y, bitmap, src_rect) draws the image "bitmap" and the coordinates x, and y, and src_rect is the image's 'bounding box'. The for loop here will repeat the blt command as many times as the amount of sp your actor has. So in the example I gave it would repeat it 10 times.

Now 'i' in the for loop increases after every loop by 1. So the first time it does the blt command i = 0 and so the x coordinate of the image is just x. The second time i = 1 so the x coordinate is x + bitmap.width, and so on.

Hope that helps :).
« Last Edit: September 17, 2009, 05:43:08 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - thank you man you're awesome...i think my brain exploded...

@#*%!
  ~  ~
  `_`
   g

I did try to kick around the coding, compare them to other scripts...
this is what I came up with:

Code: [Select]
class Window_Estrellas < Window_Base #---------=[call class]

   def initialize#----------------------=[define load]
    super(-1, 2, 640, 96)#--------------=[x,y window position & x,y window size]          
  bitmap = RPG::Cache.picture("star")#---------------------------=[store bitmap]
  scr_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#----------=[bitmap box]  
      for i in 0...$game_party.actors[0].sp#-------------------=[display layout]
        self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)
        end

I either get a syntax error or src_rect error.

I'm not certain of which lines of code I should comment,
now that I'm using a different method to display containers...

I'm trying to use these graphics now:

Heart Icon

Star Icon

 
I'm really looking forward to seeing these scripts with graphics in action...
but wouldn't that require graphics for the container, outline, and fill as well?

thanks again! ~g
« Last Edit: September 17, 2009, 08:20:12 AM by gameface101 »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
the error is just a spelling error:

you set scr_rect, but then use src_rect.

You also, technically, don't need to set src_rect as it is the same as bitmap.rect in this case. But you should keep it for a reason I will soon explain.

When it comes to filling a star, it depends on how you want to fill it. If you want to fill it by row, you can change the src_rect so that only part of the bitmap is shown.

**
Rep:
Level 83
Detective Scrotes
I'm trying to use these graphics now:

Heart Icon

Star Icon

 
I'm really looking forward to seeing these scripts with graphics in action...
but wouldn't that require graphics for the container, outline, and fill as well?

thanks again! ~g
You would only need another image if you wanted a blank heart to display when the actor gets hurt.

If you want it to draw an 'empty' heart or star when hp and sp is used the you can do something like this.

Code: [Select]
for i in 0...$game_party.actors[0].maxsp # maxhp for hearts
   if i >= $game_party.actors[0].sp
    # Draw a complete heart/star
  else
    # Draw an empty heart/star
  end
end

***
Rep:
Level 83
X-PLAT!
@MA - nice catch! and now I understand what you mean by the src_rect decreasing in size...
          as if it were shrinking horizontally... whatever is the most simplest for now...
          as I feel I'm asking for too much already, that's why I'm trying my best as well.

          * if I could script like you and albertfish, I'd make it so that each heart/star
             would fill from bottom to top and empty from top to bottom...
             and once a container is completely emptied, for that empty container graphic
             to expand then disappear... only to reappear again when hp/sp has been restored.

@albertfish - so I've whipped up these to be the empty versions of the containers.
            empty heart
           
            empty star
           

            ok, so here's the latest edit to the script:
            I've tried to comment every line to the best of my knowledge
Spoiler for:
Code: [Select]
class Window_Estrellas < Window_Base#------------------------------=[call class]

   def initialize#------------------------------------------------=[define load]
#[bottom left]
     #super(-8, 410, 640, 96)#----------=[x,y window position & x,y window size]
#[top left]
    super(-1, 2, 640, 96)#--------------=[x,y window position & x,y window size]
   
#################################################################[PICTURE SETUP]           
# def draw_stars 
bitmap = RPG::Cache.picture("star")#-----------------------------=[store bitmap]
  src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#----------=[bitmap box]
      for i in 0...$game_party.actors[0].sp#-------------------=[display layout]
      self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)#crash
    end
  for i in 0...$game_party.actors[0].maxsp#-------------=[show maxhp for hearts]
   if i >= $game_party.actors[0].sp#-------------------=[condition for graphics]
    # Draw a complete heart/star
solid_star = RPG::Cache.picture("star")   
  else
    # Draw an empty heart/star
empty_star = RPG::Cache.picture("star container")     
   
#################################################################[PICTURE SETUP]


#[Star Containers] (number of stars you wish to display)
#--------------------------------------------------
#estrellas = 10 #[use this setting for a fixed number of stars] or...
estrellas = $game_variables[1]#to control amount of stars by variable.

#[Opacity] (how clear or solid in appearance)
#--------------------------------------------------
opacidad = 255 #opacity: 0= invisible to 255= solid

#[Options] 0 =Blank 1 =Hero's name 2 =Value/MaxValue 3 =Stars/Maxstars 4 =HP%
#--------------------------------------------------
opcion = 0#info text, review the options above:

      self.contents = Bitmap.new(width - 32, height - 32)
      self.contents.font.name = "Impact"#---------------------------=[FONT TYPE]
      self.contents.font.size = 24#---------------------------------=[FONT SIZE]
      self.z = 3000#-------------------------------------------------=[BLENDING]
      self.opacity = 0 #------------------------------------------=[WINDOW SKIN]
      @stars = estrellas
      @opacity = opacidad
      @option = opcion
      @hr = 0
      refresh
    end
  end#
  end#
      def refresh
      @stars = $game_variables[1]#--------------------------------=[Variable_ID] 
      self.contents.clear
      @e = $game_party.actors[0].sp
      @me = $game_party.actors[0].maxsp
      #n is the value, and mn the maxvalue:
      @hr = 0
      @lh = 0

#[containers]     #coordinates = i*14,= left point
                  #second number    4,
                  #third number     4,
                  #fourth number    4,                 
      for i in 0..@stars-1
         #self.contents.fill_rect(i*14, 4, 1, 2, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14, 4, 1, 2, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+1, 3, 1, 4, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+2, 2, 1, 6, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+3, 1, 1, 8, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+4, 0, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+5, 1, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+6, 2, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+7, 1, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+8, 0, 1, 10, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+9, 1, 1, 8, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+10, 2, 1, 6, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+11, 3, 1, 4, Color.new(0, 0, 0, @opacity))
         self.contents.fill_rect(i*14+12, 4, 1, 2, Color.new(0, 0, 0, @opacity))
#[outline]     
    self.contents.fill_rect(i*14+1, 4, 1, 2, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+2, 3, 1, 4, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+3, 2, 1, 6, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+4, 1, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+5, 2, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+6, 3, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+7, 2, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+8, 1, 1, 8, Color.new(255, 255, 255, @opacity))
    self.contents.fill_rect(i*14+9, 2, 1, 6, Color.new(255, 255, 255, @opacity))
   self.contents.fill_rect(i*14+10, 3, 1, 4, Color.new(255, 255, 255, @opacity))
   self.contents.fill_rect(i*14+11, 4, 1, 2, Color.new(255, 255, 255, @opacity))
#[fill in]
         @c = 200#red
         @l = @e*100/@me#100
         @ho = @l*@stars   #@c, 200, 100 = yellow
         c_color(1)
         self.contents.fill_rect(i*14+2, 4, 1, 2, Color.new(0, 0, @c, @opacity))
         c_color(2)
         self.contents.fill_rect(i*14+3, 3, 1, 4, Color.new(0, 0, @c, @opacity))
         c_color(3)
         self.contents.fill_rect(i*14+4, 2, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(4)
         self.contents.fill_rect(i*14+5, 3, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(5)
         self.contents.fill_rect(i*14+6, 4, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(6)
         self.contents.fill_rect(i*14+7, 3, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(7)
         self.contents.fill_rect(i*14+8, 2, 1, 6, Color.new(0, 0, @c, @opacity))
         c_color(8)
         self.contents.fill_rect(i*14+9, 3, 1, 4, Color.new(0, 0, @c, @opacity))
         c_color(9)
        self.contents.fill_rect(i*14+10, 4, 1, 2, Color.new(0, 0, @c, @opacity))

         @hr += 1
       end
       
#[update]
  def update
    @value=$game_variables[1]#-------------=[to update current amount of Stars]
    $old_sp = $game_party.actors[0].sp#--------=[to update current amount of SP]
  end

#[options]     
      if @option == 1
         self.contents.font.color.set(0, 0, 0)
   self.contents.draw_text(0 - 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 - 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
         self.contents.font.color = normal_color
           self.contents.draw_text(0, 7, 160, 32, $game_party.actors[0].name, 0)
      elsif @option == 2
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@e}/#{@me}", 0)
      elsif @option == 3
         self.contents.font.color.set(0, 0, 0)
      self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
      self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@ho/100}/#{@stars}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@ho/100}/#{@stars}", 0)
      elsif @option == 4
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@l}%", 0)
      end
   end
end#
#[color method]
def c_color(a)
if @hr <= (@ho/100)-1
@c = 255 #
else
if @ho/10-@hr*10 >= a and @ho/10-@hr*10 <= 9

@c = 255 #
else
@c = 0 #
end
end
end

#############--------------------------------------=[alias method for Scene_Map]
# Scene_Map #
#############
class Scene_Map
 alias gface2_main main
   def main #MAIN
   @estrellas = Window_Estrellas.new
   gface2_main
   @estrellas.dispose
end
 alias gface2_update update
   def update #UPDATE
   gface2_update

      @estrellas.refresh if $old_sp != $game_party.actors[0].sp
      @estrellas.visible = $game_switches[1]#---------------------=[Variable_ID]
      @estrellas.update
    end
  end

  I get a line 38 error undefined method for "blt" for nil:nilclass
  I'm guessing it has something to do with using some of the existing lines of codes...?
 
Code: [Select]
   def initialize#------------------------------------------------=[define load]
    super(-1, 2, 640, 96)#--------------=[x,y window position & x,y window size]
           
 and am I sequencing it correctly??

 -class
-def initialize
*
*
*
def refresh
*
*
*
def update
*
*
*
alias

thanks guys, it's as if you naturally use 20% of the brain
                  as I'm trying to keep up with my 5% ~ g

           

**
Rep:
Level 83
Detective Scrotes
@gameface101 the nil class error is because it is attempting to draw the graphic, but no content container has being defined. To do so add this line:
Code: [Select]
def initialize#------------------------------------------------=[define load]
  super(-1, 2, 640, 96)#--------------=[x,y window position & x,y window size]
  self.contents = Bitmap.new(width-32, height-32)

That should fix the error. Also you can place the draw stars code in the refresh function so that it updates.

There are also a few minor changes to the draw stars that should be made:
Code: [Select]
bitmap = RPG::Cache.picture("star")#-----------------------------=[store bitmap]
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#----------=[bitmap box]
  for i in 0...$game_party.actors[0].sp#-------------------=[display layout]
    self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)#crash
  end
This code is not needed if you used the other piece of code that drew the empty stars. You simply need:
Also I made a mistake, the if statement should be less then or equal too. I've changed that in the following code.
Code: [Select]
for i in 0...$game_party.actors[0].maxsp#-------------=[show maxhp for hearts]
  if i <= $game_party.actors[0].sp#-------------------=[condition for graphics]
    # Draw a complete heart/star
    bitmap = RPG::Cache.picture("star") #------=[store the full star image file in bitmap]
  else
    # Draw an empty heart/star
    bitmap = RPG::Cache.picture("star container") #------=[store the empty star image file in bitmap]
  end
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height) #------=[create a new rectangle]
self.contents.blt(x, y, bitmap, src_rect) #------=[draw the image]
What this does is repeats the for loop as many times as your maxhp. So if you have maxhp of 10 but you currently only have 7hp it will go through the loop 10 times. The first 7 times, it will draw a full heart, due to the if statement, the next 3 times it will draw a empty heart.

This is because when i is less than or equal to 7 the if statement will be true and set the bitmap to the full star. Once i is greater than 7, the if statement will no longer be true and there for set the bitmap to the empty star.

You could even make the 'drawing stars' it's own function like so.

Code: [Select]
def draw_stars
  #insert the code that draws the stars (from above)
end

And then in the refresh function you have to call the draw_stars function

Code: [Select]
def refresh
  self.contents.clear
  draw_stars
  #other refresh code here (maybe have another separate function to draw hearts)
end

Also, you mentioned you would like to have the star empty down, and fill up... This can be done easily with the src_rect by changing the height value. Once you get this script all figured out and are more comfortable with it I can gladly help you with that.

Edit: Okay, so I quickly coded up a hearts and stars display script so that I can help you out better and I have one thing to correct.

The for loop should read for i in 1...$game_party.actors[0].maxsp + 1
The changes I made are bold.

This correctly displays the hearts :P.

Hope this all helps! I can answer any further questions you may have.
« Last Edit: September 18, 2009, 01:06:58 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - right on! thanks for sharing your wisdom...

ok so here's my latest attempt to the new picture using star script:
Spoiler for:
Code: [Select]
#picture stars SP meter!
class Window_Starrz < Window_Base
 
def initialize#---------------------------------------------------=[define load]
  super(-1, 100, 640, 96)#--------------=[x,y window position & x,y window size]

starrz = $game_variables[1]#to control amount of stars by variable.
opacity = 255 #opacity: 0= invisible to 255= solid
option = 1#info text, review the options above: 
 
      self.contents = Bitmap.new(width - 32, height - 32)
      self.contents.font.name = "Impact"#---------------------------=[FONT TYPE]
      self.contents.font.size = 24#---------------------------------=[FONT SIZE]
      self.z = 3000#-------------------------------------------------=[BLENDING]
      self.opacity = 200 #----------------------------------------=[WINDOW SKIN]

      bitmap = RPG::Cache.picture("star")#-----------------------------=[store bitmap]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#----------=[bitmap box]
      for i in 0...$game_party.actors[0].sp#-------------------=[display layout]
      self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)#
      @starrzz = starrz
      @opacity = opacity
      @option = option
      refresh
    end
    end
#######################################################################[refresh]
def refresh
  @starrzz = $game_variables[1]#----------------------------------=[Variable_ID]
  self.contents.clear
  for i in 0...$game_party.actors[0].sp#-------------------=[display layout]
  self.contents.blt(x + i * bitmap.width, y, bitmap, src_rect)#
 
  for i in 1...$game_party.actors[0].maxsp + 1 #--------=[show maxhp for hearts]
  if i <= $game_party.actors[0].sp#--------------------=[condition for graphics]
    # Draw a complete heart/star
    bitmap = RPG::Cache.picture("star")#-=[store full star image file in bitmap]
  else
    # Draw an empty heart/star
    bitmap = RPG::Cache.picture("star container")#--=[store empty star image file in bitmap]
  end
end
end
########################################################################[update]
  def update
    @value=$game_variables[1]#-------------=[to update current amount of Stars]
    $old_sp = $game_party.actors[0].sp#--------=[to update current amount of SP]
  end
 
#######################################################################[options]     
      if @option == 1
         self.contents.font.color.set(0, 0, 0)
   self.contents.draw_text(0 - 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 - 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 - 1, 160, 32, $game_party.actors[0].name, 0)
   self.contents.draw_text(0 + 1, 7 + 1, 160, 32, $game_party.actors[0].name, 0)
         self.contents.font.color = normal_color
           self.contents.draw_text(0, 7, 160, 32, $game_party.actors[0].name, 0)
      elsif @option == 2
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@e}/#{@me}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@e}/#{@me}", 0)
      elsif @option == 3
         self.contents.font.color.set(0, 0, 0)
      self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@ho/100}/#{@starrzz}", 0)
      self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@ho/100}/#{@starrzz}", 0)
      self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@ho/100}/#{@starrzz}", 0)
      self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@ho/100}/#{@starrzz}", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@ho/100}/#{@starrzz}", 0)
      elsif @option == 4
         self.contents.font.color.set(0, 0, 0)
         self.contents.draw_text(0 - 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 - 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 - 1, 160, 32, "#{@l}%", 0)
         self.contents.draw_text(0 + 1, 7 + 1, 160, 32, "#{@l}%", 0)
         self.contents.font.color = normal_color
         self.contents.draw_text(0, 7, 160, 32, "#{@l}%", 0)
      end
   end
#############--------------------------------------=[alias method for Scene_Map]
# Scene_Map #
#############
class Scene_Map
 alias gface3_main main
   def main #MAIN
   @starrzz = Window_Starrz.new
   gface3_main
   @starrzz.dispose
end
 alias gface3_update update
   def update #UPDATE
   gface3_update

      @starrzz.refresh if $old_sp != $game_party.actors[0].sp
      @starrzz.visible = $game_switches[1]#---------------------=[Variable_ID]
      @starrzz.update
    end
  end
  end

I keep getting an undefined method 'main' for class 'Window_Starrz::Scene_Map'
(which I have defined in the alias section) was I to keep the old lines of code?
did I place too many "end" 's?

if you don't mind...could you post the working script you made for testing?
I'd like to see the layout... to understand the sequence/flow of coding a little bit better...
and compare it with this one to see what I've left out? pls

I do feel I'm getting close...and look forward to learning more.
now I understand "bitmap" "src_rect" and the arguments in the "self.contents.blt"

I'll keep messing around with it.... and thanks again for being patient with me! ~g

**
Rep:
Level 83
Detective Scrotes
Yea, I can post it.

Code: [Select]
class Window_Hearts < Window_Base
  def initialize
    super (-16, -16, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.opacity = 0
  end
  def update
    super
    refresh
  end
  def refresh
    self.contents.clear
    draw_star
    draw_heart
  end
  def draw_star
    x = 4
    y = 26
    y = 52 if $game_party.actors[0].maxhp > 10
    for i in 1...$game_party.actors[0].maxsp + 1
      if i <= $game_party.actors[0].sp
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("star")
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("star container")
      end
      x, y = 4, 78 if i == 11
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
      self.contents.blt(x, y, bitmap, src_rect)
      x += 26
    end
  end
  def draw_heart
    x = 4
    y = 0
    for i in 1...$game_party.actors[0].maxhp + 1
      if i <= $game_party.actors[0].hp
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("heart")
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("heart container")
      end
      x, y = 4, 26 if i == 11
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
      self.contents.blt(x, y, bitmap, src_rect)
      x += 26
    end
  end
end

class Scene_Map
  alias af_hc_hud_main main
  def main
    @hud_window = Window_Hearts.new
    af_hc_hud_main
    @hud_window.dispose
  end
  alias af_hc_hud_update update
  def update
    @hud_window.update
    af_hc_hud_update
  end
end

I did this really quick so I didn't comment it. So if there is any code you don't understand I will happily explain it to you.

Here is a screen shot of the result
Spoiler for:

Hope this helps you further understand.
« Last Edit: September 18, 2009, 04:51:21 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - you're awesome! I will take a look at this and study it line by line...
                 
                  my intentions are to learn how to script, not copy and paste.
                  so that in time, I maybe like you and MA giving script support to
                  eager to learn programming noobs like me...
                  ok it's study time! thanks a bunch "albertfish!"

**
Rep:
Level 83
Detective Scrotes
@albertfish - you're awesome! I will take a look at this and study it line by line...
                 
                  my intentions are to learn how to script, not copy and paste.
                  so that in time, I maybe like you and MA giving script support to
                  eager to learn programming noobs like me...
                  ok it's study time! thanks a bunch "albertfish!"
You are welcome, and I know that is why you wanted the code. Also that is the only reason I supplied you with the code because I knew would would use it to learn.

Good luck and again, I can answer any questions.

***
Rep:
Level 83
X-PLAT!
@albertfish - this was so fun! there was just a few lines of code in your script I didn't understand...
I had commented them with #----=[?]
Spoiler for:
Code: [Select]
class Window_Hearts < Window_Base#-----------------------------=[in game window]
  def initialize#-------------------------------------------------=[define load]
    super (-16, -16, 640, 160)#-----------=[x,y window position x,y window size]
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh#------------------------------=[call refresh command]
    self.opacity = 0#---------------------=[window skin opacity]
  end#------------------------------------=[end definition]
########################################################################[UPDATE]
  def update#-----------------------------=[define update]
    super#--------------------------------=[update the super window]
    refresh#------------------------------=[call refresh command]
  end#------------------------------------=[end definition]
#######################################################################[REFRESH]  
  def refresh#----------------------------=[define refresh]
    self.contents.clear#------------------=[clear bitmap]
    draw_star#----------------------------=[call to draw_heart]
    draw_heart#---------------------------=[call to draw_star]
  end#------------------------------------=[end definition]
####################################################################[DRAW STARS]  
  def draw_star#--------------------------=[define draw_star]
    x = 4 #-------------------------------=[draw x coordinates]
    y = 26 #------------------------------------=[draw y coordinates]
    y = 52 if $game_party.actors[0].maxhp > 10 #----------------------=[?]
    for i in 1...$game_party.actors[0].maxsp + 1 #----------=[for loop stars]
      if i <= $game_party.actors[0].sp #-----------------------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("star")#draw
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("star container")#draw
      end#----------------------------------------------=[end definition]
      x, y = 4, 78 if i == 11 #-------------------------------=[?]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?]
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements]
      x += 26 #---------------------------------------=[space icons evenly?]
    end#----------------------------------=[end 1st box]
  end#---------------------------------=[end 2nd box]
###################################################################[DRAW HEARTS]
  def draw_heart#-------------------------------------=[define draw_heart]
    x = 4 #-------------------------------=[draw x coordinates]
    y = 0 #------------------------------------=[draw y coordinates]
    for i in 1...$game_party.actors[0].maxhp + 1 #--=[for loop hearts]
      if i <= $game_party.actors[0].hp#----------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("heart")#draw
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("heart container")#draw
      end#-------------------------------------------------=[end definition]
      x, y = 4, 26 if i == 11#--------------------=[picture placement?]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?]
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements?]
      x += 26 #------=[second row?]
    end#-----------=[picture placement?]
  end#----------------------------------=[end 1st box]
end#----------------------------------=[end 2nd box]
###############################################################[SCENE_MAP ALIAS]
class Scene_Map#-------------------------=[Map Screen Processing]
  alias af_hc_hud_main main#-------------=[alias af_hc_hud]
  def main#------------------------------=[define main process]
    @hud_window = Window_Hearts.new#-----------=[call hud window]
    af_hc_hud_main#--------------------------=[call with alias]
    @hud_window.dispose#---------------------=[dispose/erase?clear?]
  end#-----------------------------------------=[end definition]
  alias af_hc_hud_update update#-------------[aliased update]
  def update#--------------------------------=[define update]
    @hud_window.update#------------------------=[call update]
    af_hc_hud_update#--------------------------=[call with alias]
  end#-----------------------------------------=[end definition]
end#-------------------------------------------=[end

I couldn't figure out how to assign each container to amount 50pts instead of 1pt.

other than that I feel really good now about how each script "speaks" to the system ^,^

could you verify my comments that I am 'getting it' ?

I'm going to try out your script now and see it in action (excited!)
~g

Edit: woo-hoo! experimenting!

« Last Edit: September 18, 2009, 07:05:05 PM by gameface101 »

**
Rep:
Level 83
Detective Scrotes
Glad it makes sense to you! You'll get a lot better with more experience.
I will add comments to the code you gave me to try to help you understand those parts.

Code: [Select]
class Window_Hearts < Window_Base#-----------------------------=[in game window]
  def initialize#-------------------------------------------------=[define load]
    super (-16, -16, 640, 160)#-----------=[x,y window position x,y window size]
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh#------------------------------=[call refresh command]
    self.opacity = 0#---------------------=[window skin opacity]
  end#------------------------------------=[end definition]
########################################################################[UPDATE]
  def update#-----------------------------=[define update]
    super#--------------------------------=[update the super window]
    refresh#------------------------------=[call refresh command]
  end#------------------------------------=[end definition]
#######################################################################[REFRESH] 
  def refresh#----------------------------=[define refresh]
    self.contents.clear#------------------=[clear bitmap]
    draw_star#----------------------------=[call to draw_heart]
    draw_heart#---------------------------=[call to draw_star]
  end#------------------------------------=[end definition]
####################################################################[DRAW STARS] 
  def draw_star#--------------------------=[define draw_star]
    x = 4 #-------------------------------=[draw x coordinates]
    y = 26 #------------------------------------=[draw y coordinates]
    # The following line of code shifts the row of stars down if the player has more than 10 hearts. This is so when the player only has
       9 hearts he stars are right underneath them and when the player has 11 or more hearts the stars y value is lower so they do not
       over lap the hearts.
    y = 52 if $game_party.actors[0].maxhp > 10 #----------------------=[?]
    for i in 1...$game_party.actors[0].maxsp + 1 #----------=[for loop stars]
      if i <= $game_party.actors[0].sp #-----------------------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("star")#draw  # store the image in the variable 'bitmap'
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("star container")#draw # store the image in the variable 'bitmap'
      end#----------------------------------------------=[end definition]
      # if the player has 11 stars go back to the left side of the screen and go down one row. This is so you get two rows of stars (zelda style)
      x, y = 4, 78 if i == 11 #-------------------------------=[?]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?] # Set the image's rectangle
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements] # Draw the image
      x += 26 #---------------------------------------=[space icons evenly?] # shift x position so that the icon does not overlap.
    end#----------------------------------=[end 1st box] # end of for loop
  end#---------------------------------=[end 2nd box] # end of if statement
###################################################################[DRAW HEARTS]
  def draw_heart#-------------------------------------=[define draw_heart]
    x = 4 #-------------------------------=[draw x coordinates]
    y = 0 #------------------------------------=[draw y coordinates]
    for i in 1...$game_party.actors[0].maxhp + 1 #--=[for loop hearts]
      if i <= $game_party.actors[0].hp#----------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("heart")#draw # store the image in the variable 'bitmap'
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("heart container")#draw # store the image in the variable 'bitmap'
      end#-------------------------------------------------=[end definition]
      x, y = 4, 26 if i == 11#--------------------=[picture placement?] # refer to above
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?]  # refer to above
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements?]  # refer to above
      x += 26 #------=[second row?]] # refer to above
    end#-----------=[picture placement?] # end for loop
  end#----------------------------------=[end 1st box] # end if statement
end#----------------------------------=[end 2nd box] # end class Window_Hearts
###############################################################[SCENE_MAP ALIAS]
class Scene_Map#-------------------------=[Map Screen Processing]
  alias af_hc_hud_main main#-------------=[alias af_hc_hud]
  def main#------------------------------=[define main process]
    @hud_window = Window_Hearts.new#-----------=[call hud window]
    af_hc_hud_main#--------------------------=[call with alias]
    @hud_window.dispose#---------------------=[dispose/erase?clear?] Gets rid of the window.
  end#-----------------------------------------=[end definition]
  alias af_hc_hud_update update#-------------[aliased update]
  def update#--------------------------------=[define update]
    @hud_window.update#------------------------=[call update]
    af_hc_hud_update#--------------------------=[call with alias]
  end#-----------------------------------------=[end definition]
end#-------------------------------------------=[end

Other than that you seem to understand the script.

***
Rep:
Level 83
X-PLAT!
@albertfish - thank you for taking the time to help me out...
                  you are like my kung fu master and I'm training to kick some @$$! ^,^

I know I get all the window positioning all lot better, it's the 'for loop' lines of code that threw me off...

in your script I'm still trying to use the same methods I've used before in making:
-an on/off switch
-a variable to control the amount of containers

I just haven't been able to get that working......?

can the graphics shrink/slide for each container as it fills or empties?
or will that require a little more coding??
(if I understand correctly, this script was just to display one graphic or another)

and how difficult would it be to have an option for vertical alignment??

once I learn to iron these items out the final goal will be:

to have an animation for when you completely fill or completely empty a container
that the filled will zoom in or the emptied will zoom out...

so there is an end to all of my questions! X-P
but no end in me returning the favor. ~g

edit: oh and for those viewing this thread here is the latest screen shot!
« Last Edit: September 18, 2009, 10:07:17 PM by gameface101 »

**
Rep:
Level 83
Detective Scrotes
in your script I'm still trying to use the same methods I've used before in making:
-an on/off switch
-a variable to control the amount of containers
Well... the players maxhp and maxsp are what is controlling the number of stars. It wouldn't be too hard to change that to a variable. As for the switch, again this would be very easy to do.

To create an on/off switch, I added 2 lines of code to the Scene_Map class.
Code: [Select]
class Scene_Map
  alias af_hc_hud_main main
  def main
    @hud_window = Window_Hearts.new
    @hud_window.visible = $game_switches[1] # <----- This line
    af_hc_hud_main
    @hud_window.dispose
  end
  alias af_hc_hud_update update
  def update
    @hud_window.update
    @hud_window.visible = $game_switches[1] # <----- This line
    af_hc_hud_update
  end
end

These lines set the visibility of the hud_window to the same boolean value as the switch 1. This means, when switch one is off(false) then the window visibility is also false.

As for using a variable to control the number of hearts, in the Window_Hearts class I change maxhp to $game_variables[num] where num is the number of the in-game variable that you want to use to set the number of hearts.

Quote
oh? and can the graphics shrink/slide for each container as it fills or empties?
or will that require a little more coding??
(if I understand correctly, this script was just to display one graphic or another)

I also created a script that does this, however it is a little more confusing. I will help you with this when you get all of your other functions working.

Quote
and how difficult would it be to have an option for vertical alignment??
This can be quite easy. In the initialize method of the Window_Hearts class create a variable similar to this:
Code: [Select]
def initialize
    super (-16, -16, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    @valign = 0
    refresh
    self.opacity = 0
  end
And then in the draw_hearts and draw_stars function do the following:
Code: [Select]
def draw_heart
    x = 4
    y = @valign
    ...
end
Code: [Select]
def draw_star
    x = 4
    y = 26 + @valign
    ...
end
Just fool around with that and I think you'll get it working :).
« Last Edit: September 21, 2009, 04:04:30 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - YES! oh I will! ^,^ it's study time!!! thanks to albertfish! man you're the best! ~g

edit:
Quote
I added 2 lines of code to the Scene_Map class.
I was trying to add this to the refresh and update sections...I get it...Scene_Map trumps
for it's the entire scene, not part of it. now the switch is marked off the list...check~

(currently working on the counter variable.)

another edit:
Quote
in the Window_Hearts class I change maxhp to $game_variables[num] where num is the number of the in-game variable that you want to use to set the number of hearts.
it loads fine, same number of hearts...?
Code: [Select]
#########################################################################[CLASS]
class Window_Hearts < Window_Base#-----------------------------=[in game window]
  def initialize#-------------------------------------------------=[define load]
    super (-16, 20, 630, 170)#170#-----------=[x,y window position x,y window size]
    self.contents = Bitmap.new(width - 32, height - 32)
    maxhp = $game_variables[101]#=================================={like this?]
    refresh#------------------------------=[call refresh command]
    self.opacity = 0#---------------------=[window skin opacity]
  end#------------------------------------=[end definition]
 

tinkering away...
« Last Edit: September 18, 2009, 11:44:02 PM by gameface101 »

**
Rep:
Level 83
Detective Scrotes
Like this

Code: [Select]
  def draw_heart
    x = 4
    y = 0
    for i in 1...$game_variables[num] + 1#-------------=[show maxhp for hearts]
      if i <= $game_party.actors[0].hp#-------------------=[condition for graphics]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("heart") #------=[store the full star image file in bitmap]
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("heart container") #------=[store the empty star image file in bitmap]
      end
      x, y = 4, 26 if i == 11
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height) #------=[create a new rectangle]
      self.contents.blt(x, y, bitmap, src_rect) #------=[draw the image]
      x += 26
    end
  end

***
Rep:
Level 83
X-PLAT!
@albertfish - oh in the 'draw heart definition! I was thinking "class" as in the first section...
I was just about to re-edit that post then bam! thanks for the quick response!

^^
8.8 -amazin!
 o
I was making it more complicated for myself but
this is what I came up with....before I read your latest post:
Spoiler for:
Code: [Select]
 def draw_star#--------------------------=[define draw_star]
    x = 17 #-------------------------------=[draw x coordinates]
    y = 12 #------------------------------------=[draw y coordinates]
    y = 52 if $game_variables[101] > 1#----------------------=[amount control]
for i in 1...$game_variables[102] + 1#-----------------------=[amount control]    
      if i <= $game_party.actors[0].sp #-----------------------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("star")#draw
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("star container")#draw
      end#----------------------------------------------=[end definition]
      
      x, y = 4, 78 if i == 1001 #-------------------------------=[11?]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?]
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements]
      x += 26 #---------------------------------------=[space icons evenly?]
    end#----------------------------------=[end 1st box]
  end#---------------------------------=[end 2nd box]
  

I've changed it back towards your example...

before we go into vertical alignment, could you show me how to
make the hearts and stars fill and drain? and assign hp/sp?
like for example each heart/star is worth a 100 HP/SP~g

EDIT:here's the latest screen shot! (switch works! variable amount works! working on vertical and fill/drain)

isn't it COOL!? thanks again to modern algebra for support on the first script (top display)
and a super BIG thanks to albertfish for lots of support and ultimately making a test script for me to learn from. (bottom display)



talk about progress!
« Last Edit: September 19, 2009, 01:52:24 AM by gameface101 »

**
Rep:
Level 83
Detective Scrotes
@albertfish - oh in the 'draw heart definition! I was thinking "class" as in the first section...
I was just about to re-edit that post then bam! thanks for the quick response!

^^
8.8 -amazin!
 o
I was making it more complicated for myself but
this is what I came up with....before I read your latest post:
Spoiler for:
Code: [Select]
 def draw_star#--------------------------=[define draw_star]
    x = 17 #-------------------------------=[draw x coordinates]
    y = 12 #------------------------------------=[draw y coordinates]
    y = 52 if $game_variables[101] > 1#----------------------=[amount control]
for i in 1...$game_variables[102] + 1#-----------------------=[amount control]    
      if i <= $game_party.actors[0].sp #-----------------------=[condition]
        # Draw a complete heart/star
        bitmap = RPG::Cache.picture("star")#draw
      else
        # Draw an empty heart/star
        bitmap = RPG::Cache.picture("star container")#draw
      end#----------------------------------------------=[end definition]
      
      x, y = 4, 78 if i == 1001 #-------------------------------=[11?]
      src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)#---=[box of arguements?]
      self.contents.blt(x, y, bitmap, src_rect)#---=[box of arguements]
      x += 26 #---------------------------------------=[space icons evenly?]
    end#----------------------------------=[end 1st box]
  end#---------------------------------=[end 2nd box]
  

I've changed it back towards your example...

before I start with the vertical alignment could you show me how to
make the hearts and stars fill and drain? and assign hp/sp?
like for example each heart/star is worth a 100 HP/SP~g
Yea you did it correctly, but there you put ---[11?] you're right, it should be 11 :P.

I will redo the script so that 1 heart = 100hp so that I don't give you examples with errors lol. I'll help you create the code to do that though.

Okay, I worked out the logic... Here is to show you that it works (you can't access the source code yet. We will try to rebuild this before I let you read the code since it can get confusing :P)

Demo attached, guy on left take sp away, guy on right takes hp away.

BTW: It's looking pretty good so far! Keep at it.
« Last Edit: September 19, 2009, 02:05:06 AM by albertfish »

***
Rep:
Level 83
X-PLAT!
@albertfish - you are a force to be reckoned with.
                  I downloaded the demo and gave it a try...yes this is what I'm talking about!
                  could you please make the containers 'fill from bottom to top' and
                  drain from 'top to bottom' as if it were liquid?
 
                  Yes, It's looking really good thanks to you   " /A\|L|3|=|R-T-><)))'> "

    



edit: @albertfish - double/triple/quadruple post! base upon the views in this thread...
                         there's a lot of silent students, if you know what I mean...
    
                         ok now I'm reviewing your most excellent tutorial ~((G
« Last Edit: September 26, 2009, 06:15:28 AM by gameface101 »

**
Rep:
Level 83
Detective Scrotes
@albertfish - you are a force to be reckoned with.
                  I downloaded the demo and gave it a try...yes this is what I'm talking about!
                  could you please make the containers 'fill from bottom to top' and
                  drain from 'top to bottom' as if it were liquid?
 
                  Yes, It's looking really good thanks to you   " /A\|L|3|=|R-T-><)))'> "

   
 

Yea that would be easy to do.

So, just to let you know the draining hearts, like in the demo, might get confusing while I explain it. The logic might be hard to understand at first (took me a few minutes and a few trials to solve it). So I will try to explain as best as I can.

I am currently writing an in depth tutorial that is design to try to show you how everything works step by step. This may take awhile but at the end I hope you will be able to write the script and get it working! I believe you will get this working pretty soon. So I will edit or post the tutorial after.

PS. Nice albertfish name thing :P.

**
Rep:
Level 83
Detective Scrotes
I know this is a double post, but I didn't want to tag this on to my last post since it is fairly long :P

So, to begin, the basic structure of the script remains the same. The only thing that we really need to do is to change how the code draws the images.

So, what do we want the script to do?
Well, we want this script to display partial hearts depending on how much hp the actor has. If each heart represents 100 hp, if the actor has 50 hp, only half of the heart will be displayed. So, we want to 'trim' or 'crop' the image proportional to the amount of hp the actor has. This is where the src_rect that we defined earlier comes into play.

As we alter the dimensions of the src_rect we will find we can cut off parts of the image and create the effect of a draining heart. Let's experiment with this.

Keeping the original code, let’s find the lines in the draw_hearts method that look like this:
Code: [Select]
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)

We are quite familiar with what this code does. This code draws the full image of the heart without clipping or cropping any of the image. The result is this:


But what if we changed some values of the src_rect? Let’s find out.
Let’s divide the width of the image by 2 and see what that gives us.
Code: [Select]
src_rect = Rect.new(0, 0, bitmap.width/2, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)

As you can see here, I did not change anything in the blt() function call. The only thing I changed was the dimensions of the src_rect. From here on I will omit the blt() function unless I make a change to it. The change that we made to the src_rect gives us this result:


Now what if we changed the height of the src_rect?
Code: [Select]
src_rect = Rect.new (0, 0, bitmap.width, bitmap.height/2)

This gives us:

So far so good right? We sort of got the result we want! But what happens if we change the x or y values?
Code: [Select]
src_rect = Rect.new(0, 12, bitmap.width, bitmap.height)


As you can see, this shifted the image upwards and as a result it trimmed off the top of the image. This shows two layers of hearts to show you what it actually looks like and that I didn’t just trim the image.
Now following that logic, it would make sense that if we changed the x value that it would shift the image horizontally trimming the side of the image right? Well let’s take a look.
Code: [Select]
src_rect = Rect.new(12, 0, bitmap.width, bitmap.height)

Turns out that our assumption is correct!

Well now that we have a grasp on what happens when we alter the dimensions of the src_rect we can continue. This is very important to understand before getting further into the logic of the script.

Part 2
Now we get into the hard stuff. The logic here may be difficult to understand why and how it works, but I will try my best to explain. Now I will give you the code bits at a time and explain what it does. It will be your job to piece them back together correctly, and get the script working.

But before we begin first this is first! We must go into the data base and give the actor a bunch of hp and sp. I set both hp and sp to over 1000 so that I can make sure the two image layers work.

Now we must modify the for loop and some code before it. Switching to the draw_star method briefly we had a line of code that originally said:
Code: [Select]
y = 52 if $game_party.actors[0].maxhp > 10

This positioned the stars down a line when there are two rows of hearts. We must make a quick edit to this since the actor now has hundreds of hp! There is a simple way to do this:

Code: [Select]
y = 52 if $game_party.actors[0].maxhp > 1000

This simple change is needed because each heart represents 100 hp, so 10 hearts * 100 hp = 1000.

Okay, back to the draw_heart method. We must modify the for loop as well so that loops the right amount of times. The logic in this loop may be confusing at first glance but the reasoning behind it is quite simple.
Code: [Select]
for i in 0...($game_party.actors[0].maxhp + 99) / 100

You might be asking yourself right now, “Why did he add 99 to the maxhp and divide by 100?” and the answer to this is really quite simple. Since the player may have 1000 hp, if we did not change this for loop, it would repeat 1000 times! We do not want that, we only want it to repeat about 10 times to show all the hearts. Knowing that, it makes a lot of sense why I would divide by 100, but why add 99?

The answer is because when you take the maxhp and divide it by 100, it stores that value as an integer. What this means is if you had 650 hp and you divide by 1000, the result will be 6, not 6.5. That is because when storing a floating point number (a number with a decimal point) into an integer, the decimal places are dropped off. The number is not rounded, so 6.99 would still become 6. But if our actor had 650 hp, we would want 6 full hearts to display and one half heart to display right? Well 650 / 100 gives us 6 so the for loop will only loop 6 times and display only the 6 full hearts. This is not our wanted result. This is why I added 99. If the actor has anywhere from 601 to 699 hp and we add 99, the resulting value will be between 700 and 798. Notice this never will go over 800, so when we divide by 100 we get 7! Good, now this will loop 7 times, that one problem out of the way. Also, if the actor only has 600 hp and we add 99, which gives us 699, then we divide by 100 we get 600 still. But if we added 100, then at 600, the loop will repeat 7 times. So that is where the 99 came from, any more or any less than that value would not work in all circumstances.

So what is the next problem? Well, we have the script drawing a full heart, and we have it drawing an empty heart, but we don’t have it drawing a partial heart. So we have to tell it to draw that! Also, we have to fix some of the numbers that have been changed since we now have a lot more hp.
Code: [Select]
if i < $game_party.actors[0].hp / 100

This should fix the if statement for the increase in hp. Now on adding in the code that will draw the partial heart.

First, before we jump right into writing the code, let’s think about what we need to do. Well, we need to calculate the proportion of the full heart to draw based on how much hp the actor has. We then need to trim the image correctly and have the empty heart get drawn in its play. However we do not want the empty heart and the full heart overlapping so we also need to trim the empty heart. We must trim the empty heart the exact opposite of the full heart so that they line up seamlessly.

So now that we know what we must accomplish where do we put the code? Well if we look at out if statement that determines what type of heart to draw we see that:
Code: [Select]
if i < $game_party.actors[0].hp / 100

This says, if the loop number is greater than the actors current hp (rounded down to the nearest hundredth since it is divided by 100, so 683 becomes 6 which only resembles 600hp) draw a full heart. If the loop number is greater than that draw an empty heart. The empty heart however should only be drawn if the full 100 hp is gone from that heart. So we can modify this if statement with an else if statement. An else if is very similar to an else statement where when the first condition is false it moves on and checks if the next condition is true. Else statements have no condition and will always execute if no other part of the if statement executes. But an else if statement have a new condition that must be true to execute. Let’s take a look that the syntax of this.
Code: [Select]
if false
  print “Hello”
elsif true
  print “Yay”
else
  print “elseeee”
end

If we were to execute this if statement, what do you think the output would be? The answer is Yay. This is because the first condition is false there for print “Hello” will not execute, the next condition is true so  print “Yay” will execute. Since that if executed, the else will not execute and therefore print “elseeee” will not execute.

So let’s use this to create an if statement where we can place the code to draw the partial heart.
Code: [Select]
elsif i < ($game_party.actors[0].hp + 99) / 100

Again we see that I added 99. This is simply because, if hp = 650, then hp/100 = 6. So in the original if statement, this will be true and draw a full heart, and if that is true then the elsif will never execute. So if hp=650 6 full heart will be draw and we know that hp must be at least 600. If the hp > 600 then we must draw a partial heart. That is what this else if says, since 650 + 99 = 749 / 100 = 700.

This is quite a bit to read, and learn from all at once. So let’s just try to make sure we understand everything before advancing. To check our understanding of this let’s try something.

Using the provide else if statement try to code it so it draws the correct number of full hearts, and for the partial heart, just use a different graphic for now so you know that the code is executing properly. Once the code executes correctly we will move on, and code the algorithm that will trim the images correctly.
« Last Edit: September 19, 2009, 05:38:05 AM by albertfish »