Partagez
Aller en bas
avatar
Yan master
Membre

Nombre de messages : 48
Age : 28
Distinction : aucune
Date d'inscription : 13/03/2015

Aide pour un scripte

le Sam 6 Fév 2016 - 3:12
Salut
Comment je suis nulle en scripte et programmation, s\'il vous plaît qlq peut m'expliquer comment faire fonctionner se scripte ?

scripte:
#------------------------------------------------------------------------------#
#  Galv's Variable Instance Bars
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.1
#------------------------------------------------------------------------------#
#  2012-12-04 - version 1.1 - font issue fixed
#  2012-12-04 - version 1.0 - release
#------------------------------------------------------------------------------#
#  First things first. This script is purely cosmetic. It doesn't control or
#  look after whatever it is you are increasing/decreasing and using the bar
#  to show. Eg. If you're bar reaches full, YOU will need to set up using events
#  what happens after it gets there. (See demo with an example of this)
#  An exception is the variable bar (see below).
#
#  The script can call a bar that will animate decreasing or increasing by
#  certain amounts based on your input and then disappear again afterward.
#  You can call a custom bar or a variable bar.
#
#  The custom bar increases/decreases
#  depending on the settings you give it. (It will not automatically adjust any
#  parameters, experience, etc. for you. You do that manually).
#
#  The variable bar will adjust the chosen variable automatically by the amount
#  you set in the script call.
#
#  These bars only work on the map.
#------------------------------------------------------------------------------#
#  INSTRUCTIONS:
#------------------------------------------------------------------------------#
#
#  Put script under Materials and above Main
#
#  Make your own graphics for the bars or use the dodgy ones I made from the
#  demo. They got in /Graphics/System/ folder.
#
#  There are lots of settings to set up the bar to appear where you want it.
#
#------------------------------------------------------------------------------#
#  SCRIPT CALLS
#------------------------------------------------------------------------------#
#
#  bar_c(current,target,max,min,text)  # Draw a custom bar.
#                                      # current = starting amount
#                                      # target = amount it will raise/lower to
#                                      # max = full bar amount
#                                      # min = empty bar amount
#                                      # text = text with bar
#
#  bar_v(var_id,bonus,max,min,text)  # Draw a bar based on variable change.
#                                    # This automatically changes the variable
#                                    # by the bonus and cannot exceed the max.
#                                    # var_id = ID of the variable
#                                    # bonus = Amount it will increase/decrease
#                                    # max = full bar amount
#                                    # min = empty bar amount
#                                    # text = text with bar
#
#  bar_colors(barcol1,barcol2,text)  # Change the 2 gradient colors of the bar
#                                    # and the text color.
#
#  bar_graphic("FileName")           # file in /Graphics/System to change to
#
#------------------------------------------------------------------------------#

($imported ||= {})["Galvs_Variable_Bar"] = true
module Galv_VarBar

#------------------------------------------------------------------------------#
#  SCRIPT SETTINGS
#------------------------------------------------------------------------------#

 ACTIVE_TIME = 100   # How long the bar takes to fill/change.

 POSITION_Y = 210    # Y position
 POSITION_X = 0      # X position. 0 is centered, so to move everything left,
                     # use a negative number. Positive number for right.
 Z_OFFSET = 0        # Z level offset.
 
                     
 TEXT_SIZE = 30          # Size of the text
 TEXT_COLOR = 0          # Color of the text
 TEXT_FONT = "Arial"     # Font of the text
 TEXT_ALIGN = 1          # 0 = left. 1 = center. 2 = right
 TEXT_Y_OFFSET = 10      # Tweak Y position of the text
 TEXT_X_OFFSET = 0       # Tweak X position of the text
 
 
 BAR_WIDTH = 300            # Width of the bar
 BAR_HEIGHT = 30            # Height of the bar
 BAR_IMAGE = "BarCover"     # Image in /Graphics/System/
 BAR_IMAGE_Y = 210          # Bar image Y position (screen relative)
 BAR_IMAGE_X = 0            # Bar image X position offset. 0 is centered.
 BAR_COLOR = [1,9]          # Default gradient colors for the bar
 

 INIT_U_SE = ["Up1", 100, 100]      # SE played once when bar appears
 RAISE_SE = ["Cursor2", 100, 100]   # Repeating SE when bar is increasing.
                                    # ["SE Name", Volume, pitch]
 
 INIT_D_SE = ["Down1", 100, 100]    # SE played once when bar appears
 LOWER_SE = ["Cursor2", 100, 70]    # Repeating SE when bar is decreasing.
                                    # ["SE Name", Volume, pitch]

 SE_SPEED = 2                       # speed that the repeating SE's repeat
 
#------------------------------------------------------------------------------#
#  END SCRIPT SETTINGS
#------------------------------------------------------------------------------#

end


class Game_Temp
 attr_accessor :varbar
 attr_accessor :vargraphic
 
 alias galv_varbar_temp_initialize initialize
 def initialize
   galv_varbar_temp_initialize
   # @varbar = [current,target,max,x,y,open,text,color1,color2,text_color,variable,min]
   @varbar = [0,0,100,false,"",
     Galv_VarBar::BAR_COLOR[0],
     Galv_VarBar::BAR_COLOR[1],
     Galv_VarBar::TEXT_COLOR,
     0,0]
   @vargraphic = Galv_VarBar::BAR_IMAGE
 end
end # Game_Temp


class Game_Interpreter
 def bar_c(current,target,max,min,text)
   $game_temp.varbar[0] = current
   $game_temp.varbar[1] = target
   $game_temp.varbar[2] = max
   $game_temp.varbar[3] = true
   $game_temp.varbar[4] = text
   $game_temp.varbar[8] = 0
   $game_temp.varbar[9] = min
 end
 
 def bar_v(var_id,bonus,max,min,text)
   $game_temp.varbar[0] = $game_variables[var_id]
   $game_temp.varbar[1] = $game_variables[var_id] + bonus
   $game_temp.varbar[2] = max
   $game_temp.varbar[3] = true
   $game_temp.varbar[4] = text
   $game_temp.varbar[8] = var_id
   $game_temp.varbar[9] = min
 end
 
 def bar_color(color1,color2,textcol)
   $game_temp.varbar[5] = color1
   $game_temp.varbar[6] = color2
   $game_temp.varbar[7] = textcol
 end
 
 def bar_graphic(file)
   $game_temp.vargraphic = file
 end
end # Game_Interpreter


class Scene_Map < Scene_Base
 
 alias galv_varbar_map_create_all_windows create_all_windows
 def create_all_windows
   galv_varbar_map_create_all_windows
   create_varbar_window
 end
 alias galv_varbar_map_update update
 def update
   galv_varbar_map_update
   @varbar_window.open if $game_temp.varbar[3]
 end
 def create_varbar_window
   @varbar_window = Window_VarBar.new
 end
 
end # Scene_Map < Scene_Base


class Window_VarBar < Window_Base
 def initialize
   super(window_x, window_y, window_width, window_height)
   self.opacity = 0
   self.contents_opacity = 0
   self.z = z + Galv_VarBar::Z_OFFSET
   @show_count = 0
   @fill_rate = 0
   refresh
 end
 def window_width
   return Galv_VarBar::BAR_WIDTH
 end
 def window_height
   return 130 #Galv_VarBar::BAR_HEIGHT
 end
 def window_x
   (Graphics.width - window_width) / 2 + Galv_VarBar::POSITION_X
 end
 def window_y
   Galv_VarBar::POSITION_Y
 end
 
 def update
   text_rect
   super
   if @show_count > 0
     refresh
     update_fadein
     @show_count -= 1
   else
     update_fadeout
   end
 end

 def update_fadein
   self.contents_opacity += 16
   @cover.opacity = self.contents_opacity if !@cover.nil?
 end

 def update_fadeout
   self.contents_opacity -= 16
   @cover.opacity = self.contents_opacity if !@cover.nil?
 end

 def open
   direction
   $game_temp.varbar[3] = false
   draw_cover if @cover.nil?
   refresh
   @show_count = Galv_VarBar::ACTIVE_TIME
   @fill_rate = fill_rate
   self.contents_opacity = 0 unless contents_opacity > 0
   self
   
   if $game_temp.varbar[8] > 0
     if @direction == 1
       $game_variables[$game_temp.varbar[8]] = [$game_temp.varbar[1],$game_temp.varbar[2]].min
     else
       $game_variables[$game_temp.varbar[8]] = [$game_temp.varbar[1],$game_temp.varbar[9]].max
     end
   end
 end

 def direction
   if $game_temp.varbar[0] < $game_temp.varbar[1]
     @direction = 1
     RPG::SE.new(Galv_VarBar::INIT_U_SE[0], Galv_VarBar::INIT_U_SE[1], Galv_VarBar::INIT_U_SE[2]).play
   else
     @direction = 0
     RPG::SE.new(Galv_VarBar::INIT_D_SE[0], Galv_VarBar::INIT_D_SE[1], Galv_VarBar::INIT_D_SE[2]).play
   end
 end

 def dispose
   @show_count = 0
   contents.dispose unless disposed?
   @cover.bitmap.dispose unless disposed? || @cover.nil?
   @cover.dispose unless disposed? || @cover.nil?
   super
 end
 
 def refresh
   contents.clear
   if @cgraphic != $game_temp.vargraphic
     if !@cover.nil?
       @cover.bitmap = Cache.system($game_temp.vargraphic)
       @cgraphic = $game_temp.vargraphic
     end
   end
   draw_varbar(0, 0, window_width)
   draw_heading(@text_rect.x, @text_rect.y, $game_temp.varbar[4]) if !@text_rect.nil?
   if $game_temp.varbar[0] < $game_temp.varbar[1] && @direction == 1
     if @show_count % Galv_VarBar::SE_SPEED == 0 && $game_temp.varbar[0] < $game_temp.varbar[2]
   return 0 if $game_temp.varbar[0] == $game_temp.varbar[9]
       RPG::SE.new(Galv_VarBar::RAISE_SE[0], Galv_VarBar::RAISE_SE[1], Galv_VarBar::RAISE_SE[2]).play
     end
     $game_temp.varbar[0] += @fill_rate
   elsif $game_temp.varbar[0] > $game_temp.varbar[1] && @direction == 0
     if @show_count % Galv_VarBar::SE_SPEED == 0 && $game_temp.varbar[0] > $game_temp.varbar[9]
       RPG::SE.new(Galv_VarBar::LOWER_SE[0], Galv_VarBar::LOWER_SE[1], Galv_VarBar::LOWER_SE[2]).play
     end
     $game_temp.varbar[0] += @fill_rate
   end
 end
 
 def draw_heading(x, y, text)
   contents.font.name = Galv_VarBar::TEXT_FONT
   contents.font.size = Galv_VarBar::TEXT_SIZE
   change_color(text_color($game_temp.varbar[7]))
   contents.font.bold = Font.default_bold
   contents.font.italic = Font.default_italic
   text = convert_escape_characters(text)
   pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
   process_character(text.slice!(0, 1), text, pos) until text.empty?
 end
 
 def text_rect
   @text_rect = Rect.new
   @text_rect.width = text_size($game_temp.varbar[4]).width
   @text_rect.height = Galv_VarBar::TEXT_SIZE
   if Galv_VarBar::TEXT_ALIGN == 0
     @text_rect.x = 0 + Galv_VarBar::TEXT_X_OFFSET
   elsif Galv_VarBar::TEXT_ALIGN == 2
     @text_rect.x = Galv_VarBar::BAR_WIDTH - @text_rect.width + Galv_VarBar::TEXT_X_OFFSET
   else
     @text_rect.x = (Galv_VarBar::BAR_WIDTH - @text_rect.width) / 2 + Galv_VarBar::TEXT_X_OFFSET
   end
   @text_rect.y = 0 + Galv_VarBar::TEXT_Y_OFFSET
   @text_rect
 end
 
 def fill_rate
   ($game_temp.varbar[1] - $game_temp.varbar[0]) / (Galv_VarBar::ACTIVE_TIME * 0.5)
 end

 def rate
   $game_temp.varbar[0].to_f / $game_temp.varbar[2].to_f
 end
 
 def draw_varbar(x, y, width = 124)
   draw_gauge(x, y, width, rate, text_color($game_temp.varbar[5]), text_color($game_temp.varbar[6]))
   change_color(system_color)
 end
 def standard_padding
   return 0
 end
 
 def draw_gauge(x, y, width, rate, color1, color2)
   fill_w = (width * rate).to_i
   gauge_y = (contents.height - Galv_VarBar::BAR_HEIGHT) / 2
   contents.fill_rect(x, gauge_y, window_width, Galv_VarBar::BAR_HEIGHT, gauge_back_color)
   contents.gradient_fill_rect(x, gauge_y, fill_w, Galv_VarBar::BAR_HEIGHT, color1, color2)
 end

 def draw_cover
   @cover = Sprite.new
   @cover.bitmap = Cache.system($game_temp.vargraphic)
   @cgraphic = $game_temp.vargraphic
   @cover.x = (Graphics.width - @cover.bitmap.width) / 2 + Galv_VarBar::BAR_IMAGE_X
   @cover.y = Galv_VarBar::BAR_IMAGE_Y
   @cover.z = z - 1
   @cover.opacity = 0
 end

end # Window_VarBar < Window_Base
Revenir en haut
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum