Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Darok on July 06, 2009, 03:15:38 pm

Title: [XP] Bars
Post by: Darok on July 06, 2009, 03:15:38 pm
Hi!
I have this Scipt, but it i want instead of showing the bars Hp and Sp, i want to show 2 Variables. This is the Scirpt:
#Script Creado por UliK
#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------
alias sk_bar_main main
def main
@bars = Window_Sk_Bars.new
sk_bar_main
@bars.dispose if @bars != nil
end
#-----------------------------------------------------------------
alias sk_bar_update update
def update
@bars.update
sk_bar_update
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize(font=0,size=15)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Sk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,-8,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,"HP")
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * actor.hp / actor.maxhp
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.hp*100)/actor.maxhp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(255,green+32,96,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------

#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------
alias sk_bar_main2 main
def main
@bars2 = Window_mk_Bars.new
sk_bar_main2
@bars2.dispose if @bars2 != nil
end
#-----------------------------------------------------------------
alias sk_bar_update2 update
def update
@bars2.update
sk_bar_update2
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize2(font=0,size=22)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_mk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,5,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,"SP")
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * actor.sp / actor.maxsp
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.sp*100)/actor.maxsp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(150,green-32,255,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------


If you can, add me to MSN becouse i want to learn how myself xD.
darok.rmxp@hotmail.com
Bye!
Title: Re: [XP] Bars
Post by: lilbrudder917 on July 23, 2009, 11:08:15 pm
Well, I saw that no one had fulfilled this request, let alone replied, so I decided to try scripting. I've tried before but failed many times, but I saw this and tried to make it, and got it working.

Anyway, here's the code:
#Script Creado por UliK
#Editted to use variables instead of HP and SP by lilbrudder917
#-----------------------------------------------------------------
# CONFIGURATION
#-----------------------------------------------------------------
VAR1       = 1      #Which variable for the first row?
VAR2       = 2      #Which variable for the second row?
$Var1_name = "VAR1" #Replacement for the word "HP", only 3-4 letters
$Var2_name = "VAR2" #Replacement for the word "SP", only 3-4 letters
VAR_MAX    = 20     #Maximum for the first variable
VAR_MAX2   = 25     #Maximum for the second variable

#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------

alias sk_bar_main main
def main
@bars = Window_Sk_Bars.new
sk_bar_main
@bars.dispose if @bars != nil
end
#-----------------------------------------------------------------
alias sk_bar_update update
def update
@bars.update
sk_bar_update
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize(font=0,size=15)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Sk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,-8,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,$Var1_name)
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * $game_variables[VAR1] / VAR_MAX
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.hp*100)/actor.maxhp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(255,green+32,96,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------

#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------
alias sk_bar_main2 main
def main
@bars2 = Window_mk_Bars.new
sk_bar_main2
@bars2.dispose if @bars2 != nil
end
#-----------------------------------------------------------------
alias sk_bar_update2 update
def update
@bars2.update
sk_bar_update2
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize2(font=0,size=22)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_mk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,5,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,$Var2_name)
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * $game_variables[VAR2] / VAR_MAX2
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.sp*100)/actor.maxsp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(150,green-32,255,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end

#-----------------------------------------------------------------
end
#-----------------------------------------------------------------


You can configure which variables to use for the top and bottom row, what the word says instead of "HP" and "SP", although since I don't really know how to change the positioning of the text (when I tried, the bar moved with it), so the limits on the word are 3 or 4 letters. Also, to make sure a variable is significant enough to actually change the bar (1/9000 won't do much), you can decide what the maximum is, depending on what you were using the bars for. Just be sure not to get over the limit, or the color will go further than the bar itself, but you probably knew that.

Anyway, yeah, here it is.
Title: Re: [XP] Bars
Post by: nathmatt on July 29, 2009, 02:59:43 pm
any way i could a maybe slight modified version of this for my escape bar just need it on my map at the top right when i call it
Title: Re: [XP] Bars
Post by: lilbrudder917 on August 02, 2009, 02:39:49 pm
Quote from: nathmatt on July 29, 2009, 02:59:43 pm
any way i could a maybe slight modified version of this for my escape bar just need it on my map at the top right when i call it


Actually, that's rather easy.

#Script Creado por UliK
#Editted to use variables instead of HP and SP by lilbrudder917
#-----------------------------------------------------------------
# CONFIGURATION
#-----------------------------------------------------------------
VAR1       = 1      #Which variable for the first row?
VAR2       = 2      #Which variable for the second row?
$Var1_name = "1" #Replacement for the word "HP", only 3-4 letters
$Var2_name = "2" #Replacement for the word "SP", only 3-4 letters
VAR_MAX    = 20     #Maximum for the first variable
VAR_MAX2   = 25     #Maximum for the second variable

#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------

alias sk_bar_main main
def main
@bars = nil
sk_bar_main
@bars.dispose if @bars != nil
end
#-----------------------------------------------------------------
alias sk_bar_update update
def update
#@bars.update
sk_bar_update
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize(font=0,size=15)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Sk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,-8,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,$Var1_name)
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * $game_variables[VAR1] / VAR_MAX
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.hp*100)/actor.maxhp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(255,green+32,96,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------

#-----------------------------------------------------------------
class Scene_Map
#-----------------------------------------------------------------
alias sk_bar_main2 main
def main
@bars2 = nil
sk_bar_main2
@bars2.dispose if @bars2 != nil
end
#-----------------------------------------------------------------
alias sk_bar_update2 update
def update
#@bars2.update@bars2 = Window_mk_Bars.new
sk_bar_update2
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_Base < Window
#-----------------------------------------------------------------
def sk_initialize2(font=0,size=22)
font = "Tahoma" if font == 0
self.contents = Bitmap.new(self.width-32,self.height-32)
self.contents.font.name = font
self.contents.font.size = size
end
#-----------------------------------------------------------------
def draw_text_outline(x,y,w,h,str,c=normal_color,a=0)
self.contents.font.color = Color.new(0,0,0,255)
self.contents.draw_text(x-1,y,w,h,str,a)
self.contents.draw_text(x+1,y,w,h,str,a)
self.contents.draw_text(x,y+1,w,h,str,a)
self.contents.draw_text(x,y-1,w,h,str,a)
self.contents.font.color = c
self.contents.draw_text(x,y,w,h,str,a)
end
#-----------------------------------------------------------------
end
#-----------------------------------------------------------------
class Window_mk_Bars < Window_Base
#-----------------------------------------------------------------
def initialize
super(444,5,206,96)
sk_initialize("Arial")
self.opacity = 0
end
#-----------------------------------------------------------------
def update
self.contents.clear
actor = $game_party.actors[0]
draw_text_outline(5,-6,64,26,$Var2_name)
draw_actor_hp(actor,30,0)
end
#-----------------------------------------------------------------
def draw_actor_hp(actor,x,y)
width = 128
y += 4
white = Color.new(255,255,255,255)
black = Color.new(0,0,0,255)
w = width * $game_variables[VAR2] / VAR_MAX2
# White border
self.contents.fill_rect(x+1, y-1, width-2, 5, white)

# Black back
self.contents.fill_rect(x+2, y, width-4, 3, black)

# Generating the color
val = 255 * ((actor.sp*100)/actor.maxsp)
green = 255 - val/100
color = Color.new(224,green,0,255)
w_color = Color.new(150,green-32,255,255)
if green > 64 then green -= 32
elsif green > 128 then green -= 64 end
# Making the bar
self.contents.fill_rect(x+2, y, w-4, 3, w_color)
end

#-----------------------------------------------------------------
end
#-----------------------------------------------------------------



I just commented "@bars.update" and "@bars2.update" and had @bars = nil and @bars2 = nil. Then, in a Common Event I had 2 Conditional Branches. If Switch 1 is on, @bars = Window_Sk_Bars.new and @bars.update, else @bars = nil. If Switch 2 is on, @bars2 = Windows_mk_Bars.new and @bars2.update, else @bars2 = nil. Then, on a map, have a Parallel Process to call the Common Event. Then, when you want the bar(s) to appear, turn on the switch(es). When you want them gone, turn them off. However, they won't disappear until another Scene is opened and closed. For example, the Menu. I don't know if there is a way to stop that.
Title: Re: [XP] Bars
Post by: nathmatt on August 02, 2009, 05:29:16 pm
i have a question what are you aliasing is this an add_on to something ?
Title: Re: [XP] Bars
Post by: Aqua on August 02, 2009, 05:30:50 pm
Scene_Map...
It was 2 lines above it... o.o
Title: Re: [XP] Bars
Post by: nathmatt on August 02, 2009, 05:33:21 pm
lol i feel retarded i should have realized that i use them in my blizz abs add_on

edit1: I will play around with it to see if i can get it exactly how i want it and integrate it in my script
i need to learn how to make bars my self but i cant find any thing to explain how you make them

edit2: got how i want it now just to to integrate it