old_hp = $game_party.members[0].hp
@corazones.refresh if old_hp != $game_party.members[0].hp
old_hp = $game_party.actors[0].hp
@corazones.refresh if old_hp != $game_party.actors[0].hp
@corazones.visible = $game_switches[x]
corazones = 3
corazones = @value=$game_variables[2]
@hearts = $game_variables[2]
old_hp = $game_party.actors[0].hp
@corazones.refresh if old_hp != $game_party.actors[0].hp
heart = $game_variables[2]
@corazones.refresh if heart !=$game_variables[2]
@modern algebra - I tried including the code above to the refresh method in Scene_Map
along with a few other attempts... no luck.
Not in Scene_Map, in Window_Corazones
@hearts = $game_variables[2]
def refresh
def main #MAIN
@Corazones = Window_Corazones.new#######################################[insert]
gface1_main
@Corazones.dispose######################################################[insert]
end
alias gface1_update update
def update #UPDATE
gface1_update
old_hp = $game_party.actors[0].hp#######################################[insert]
$corazones.refresh if old_hp != $game_party.actors[0].hp##########[insert]
break
end
end
#[outline]
self.contents.fill_rect(i*14+1, 4, 1, 2, Color.new(255, 255, 255, @opacity))
would anyone possibly know how to make a "star shape" instead of a heart???I would suggest you just make a star shape image instead of getting the engine to draw a star itself.
I would like to use this for MP as well...? that's right "Star Containers for MP!"
still working on vertical alignment... ~g
- if i were to incorporate pictures, would I have to assign a graphic for each heart and star???
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
@stars.bitmap = RPG::Cache.picture("heart graphic")
so would I start with using something likeClose, however @stars.bitmap will give you an error if bitmap isn't a function of @stars.Code: [Select]@stars.bitmap = RPG::Cache.picture("heart graphic")
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
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'm trying to use these graphics now:You would only need another image if you wanted a blank heart to display when the actor gets hurt.
Heart Icon
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi29.tinypic.com%2Ft6wfpj.png&hash=fc789e2ff998ea4191dfac4570d2a50cb2c1b35f)
Star Icon
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi27.tinypic.com%2F14ay1pd.png&hash=f999a945fe3537c61e7048eee0bf186d8d825dd3)
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
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
def initialize#------------------------------------------------=[define load]
super(-1, 2, 640, 96)#--------------=[x,y window position & x,y window size]
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)
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
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]
def draw_stars
#insert the code that draws the stars (from above)
end
def refresh
self.contents.clear
draw_stars
#other refresh code here (maybe have another separate function to draw hearts)
end
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
@albertfish - you're awesome! I will take a look at this and study it line by line...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.
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!"
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
in your script I'm still trying to use the same methods I've used before in making: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.
-an on/off switch
-a variable to control the amount of containers
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
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)
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:
def initialize
super (-16, -16, 640, 160)
self.contents = Bitmap.new(width - 32, height - 32)
@valign = 0
refresh
self.opacity = 0
end
def draw_heart
x = 4
y = @valign
...
end
def draw_star
x = 4
y = 26 + @valign
...
end
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
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...?
#########################################################################[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]
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
@albertfish - oh in the 'draw heart definition! I was thinking "class" as in the first section...Yea you did it correctly, but there you put ---[11?] you're right, it should be 11 :P.
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:
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
@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-><)))'> "
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
src_rect = Rect.new(0, 0, bitmap.width/2, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
src_rect = Rect.new (0, 0, bitmap.width, bitmap.height/2)
src_rect = Rect.new(0, 12, bitmap.width, bitmap.height)
src_rect = Rect.new(12, 0, bitmap.width, bitmap.height)
y = 52 if $game_party.actors[0].maxhp > 10
y = 52 if $game_party.actors[0].maxhp > 1000
for i in 0...($game_party.actors[0].maxhp + 99) / 100
if i < $game_party.actors[0].hp / 100
if i < $game_party.actors[0].hp / 100
if false
print “Hello”
elsif true
print “Yay”
else
print “elseeee”
end
elsif i < ($game_party.actors[0].hp + 99) / 100
hp = ($game_party.actors[0].hp+99)/100*100
amount = 100 - (hp - $game_party.actors[0].hp)
amount = amount * bitmap.height / 100
amount *= bitmap.height
amount /= 100
amount = 24 – amount
src_rect = Rect.new(0, amount, bitmap.width, bitmap.height- amount)
self.contents.blt(x, y + amount, bitmap, src_rect)
src_rect = Rect.new(0, 0, bitmap.width, amount)
src_rect = Rect.new(0, 0, bitmap.width, bitmap.height)
self.contents.blt(x, y, bitmap, src_rect)
*I have commented the new edits with #-------=[new edit]You are one step ahead of me with doing the stars one :P. And lol about the forgetting thing.
as you can see I have both sp and hp ready for their algorithms... ~.^
(https://rmrk.net/proxy.php?request=http%3A%2F%2Fi38.tinypic.com%2F2u5f888.jpg&hash=e52bcf3b1019594fea3eaf5f503062745ade4b41)
I should have warned you...I learn just as fast as I can forget X-P ~g
amount = 24 – amount
This next line of code you will understand better later, but this is needed. Without this next line, the heart will empty from the bottom up(along with a couple other changes)!
Code:
amount = 24 – amount
Code: [Select]And then in the draw_hearts and draw_stars function do the following:def initialize
super (-16, -16, 640, 160)
self.contents = Bitmap.new(width - 32, height - 32)
$valign = 0
refresh
self.opacity = 0
endCode: [Select]def draw_heart
x = 4
y = valign
...
endCode: [Select]def draw_star
x = 4
y = 26 + valign
...
end
$valign = 0 #This is a global variable
@valign = 0 #This is an instance variable
valign = 0 #This is a local variable
VALIGN = 0 #This is a constant
Global variables can be accessed and changed anywhere. You do not need to define them in every class, hence the name global. The are defined by a $, for example:I always see that "$" because most scripts are called by using a 'global' variable ~ $scene = Super_Cool_Window.newCode: [Select]$valign = 0 #This is a global variable
Instance variables can be accessed my any method but only in the class in which they are defined in. If you create an instance variable in class Cool_Window, you can access it in the redraw method or the update method, but you cannot access it in class Notsocool_Window. Although you can set it up as a public instance variable to do so, however I will not go into this. Instance variables are defined by @, for example:so when you start a script, you use a "Class" and if there's a variable in that class you want to use in your scriptCode: [Select]@valign = 0 #This is an instance variable
Local variables can only be accessed in the method in which it was defined in. So if you create this variable in the refresh method, you can't access it in the update method. These are defined by putting nothing in front of it. For example:you make variables local not global if you only want it access in a certain part of codeCode: [Select]valign = 0 #This is a local variable
Constants are variables that do not get changed. For example the math number pi. This value is always 3.14159265..... These variables are defined by using upper case letters, for exampleok, I've seen this in scripts that use CONSTANTS for easy options such as BUTTON = XCode: [Select]VALIGN = 0 #This is a constant
#########################################################################[CLASS]
class Window_Hearts < Window_Base#-----------------------------=[in game window]
def initialize#-------------------------------------------------=[define load]
super (-16, 20, 340, 400)#------------=[x,y window position x,y window size]
self.contents = Bitmap.new(width - 32, height - 32)#--------------------=[?]
@valign = 50#-----------------------------------=[vertical alignment option]
refresh#---------------------------------------------=[call refresh command]
self.opacity = 50#------------------------------------=[window skin opacity]
end#---------------------------------------------------------=[end definition]
####################################################################[DRAW STARS]
def draw_star#---------------------------------------------=[define draw_star]
x = 17 #-----------------------------------------------=[draw x coordinates]
y = 26 + $valign #----------------------------------------=[vertical option]
# y = 12 #----------------------------------------------=[draw y coordinates]
###################################################################[DRAW HEARTS]
def draw_heart#-------------------------------------------=[define draw_heart]
x = 4 #------------------------------------------------=[draw x coordinates]
y = $valign #---------------------------------------------=[vertical option]
# y = 0 #-----------------------------------------------=[draw y coordinates]
def initialize
y = add(1, 2)
end
def add(num1, num2)
return num1 + num2
end
def valign
y = 10
end
def valign
y = add(-10, 50)
end
def add(num1, num2)
return num1 + num2
end
def initialize
@valign = 0
...
end
def draw_hearts
y = @valign
...
end
#########################################################################[CLASS]
class Window_Hearts < Window_Base#-----------------------------=[in game window]
def initialize#-------------------------------------------------=[define load]
@valign = 0#--------------------------------------=[vertical alignment option]
# super (-16, 20, 340, 100)#------------------------------=[vertical alignment]
super (-16, 100, 100, 340)#--------------=[x,y window position x,y window size]
self.contents = Bitmap.new(width - 32, height - 32)#--------------------=[?]
refresh#---------------------------------------------=[call refresh command]
self.opacity = 50#-------------------------------------=[window skin opacity]
end#---------------------------------------------------------=[end definition]
###################################################################[DRAW HEARTS]
def draw_heart#-------------------------------------------=[define draw_heart]
x = 4 #------------------------------------------------=[draw x coordinates]
y = @valign#---------------------------------------------=[vertical option]
# y = 0#------------------------------------------------=[draw y coordinates]