Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Script Analysis: My First Script Attempt

::: Simple Single Hero CMS ::: by Reverie's Eclipse [Rev1]

Screenshot:
http://img227.imageshack.us/img227/197/sshcms7pw.png[/img]

Script:
Code:
#(Default Settings)
#=============================================================================#
#                                                                         (1) #
#     ::: Simple Single-Hero CMS :::                     :: by Rev1 ::        #
#                                                                             #
#=============================================================================#
# Description: A simple script for a single character menu system.            #
#                                                                             #
# Instructions: Insert in a new class above Main.                             #
#=============================================================================#
#============================= Begin Script ==================================#
# The following portion allows you to change the main font and it's values.   #
#-----------------------------------------------------------------------------#
class Bitmap
if not method_defined?('original_draw_text')
  alias original_draw_text draw_text
  def draw_text(*arg)

    original_color = self.font.color.dup
    # SET TEXT SHADOW COLOR #
    self.font.color = Color.new(0, 0, 0, 255)
    # ( Red VALUE, Green VALUE, Blue VALUE, Saturation ); VALUE RANGE = 0-255 
    self.font.italic = false # TRUE = ITALIC; FALSE = NORMAL#
    self.font.bold = false # TRUE = BOLD; FALSE = NORMAL#
    
    # To change to a different/desired font type, delete where it says 
    # "Arial" in the line below, and enter the name of the font
    # you'd like to use in parenthesis ( examples: "Verdana" or "Tahoma" )
    self.font.name = "Arial" 
    
    self.font.size = 22 #CHANGES FONT SIZE# 
    #------ END ------------#   
    if arg[0].is_a?(Rect)
      arg[0].x += 2
      arg[0].y += 2
      self.original_draw_text(*arg)
      arg[0].x -= 2
      arg[0].y -= 2
    else
      arg[0] += 2
      arg[1] += 2
      self.original_draw_text(*arg)
      arg[0] -= 2
      arg[1] -= 2
    end

    self.font.color = original_color
    self.original_draw_text(*arg)

  end
 end
end
                            
#=============================================================================#
# ** Scene_Menu **
#------------------------------------------------------------------------------
#  This class performs menu screen processing.
#=============================================================================#
#                                                                             #
#  *REV1: The edits in this class simply reposition the command, status,      #
#  and gold windows; remove the playtime and steps windows altogether;        #
#  draws the map your character is on behind the menu; and removes the        #
#  the unnecessary update methods for the absent windows (playtime and steps) #
#                                                                             #
#=============================================================================#
class Scene_Menu
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    
    #EDIT: LINE ADDED : Draws parent map as background behind menu window
    @spriteset = Spriteset_Map.new

    # Make command window
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Save"
    s6 = "End Game"
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
    @command_window.index = @menu_index
    @command_window.x = 480
    @command_window.y = 0  
    # If number of party members is 0
    if $game_party.actors.size == 0
      # Disable items, skills, equipment, and status
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    # If save is forbidden
    if $game_system.save_disabled
      # Disable save
      @command_window.disable_item(4)
    end
    # Make gold window
    @gold_window = Window_Gold.new
    @gold_window.x = 480 
    @gold_window.y = 230 
    # Make status window
    @status_window = Window_MenuStatus.new
    @status_window.x = 0
    @status_window.y = 0
    
    #EDIT: WINDOW_STEPS & WINDOW_PLAYTIME HAVE BEEN REMOVED 
    
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    @command_window.dispose
    @gold_window.dispose
    @status_window.dispose
    # EDIT : LINE ADDED : DISPOSES MAP SPRITE
    @spriteset.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    # EDIT: GOLD_WINDOW AND STATUS WINDOW UPDATES REMOVED
    # If command window is active: call update_command
    if @command_window.active
      update_command
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when command window is active)
  #--------------------------------------------------------------------------
  def update_command
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to map screen
      $scene = Scene_Map.new
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # If command other than save or end game, and party members = 0
      if $game_party.actors.size == 0 and @command_window.index < 4
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Branch by command window cursor position
      case @command_window.index
      when 0  # item
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to item screen
        $scene = Scene_Item.new
      when 1  # skill
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Skill.new 
      #EDIT: STATUS WINDOW INACTIVE; GOES STRAIGHT TO SKILL MENU
      when 2  # equipment
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Equip.new 
      #EDIT: STATUS WINDOW INACTIVE; GOES STRAIGHT TO EQUIP MENU
      when 3  # status
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Make status window active
        $scene = Scene_Status.new 
      # EDIT: STATUS WINDOW INACTIVE;GOES STRAIGHT TO STATUS MENU
      when 4  # save
        # If saving is forbidden
        if $game_system.save_disabled
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to save screen
        $scene = Scene_Save.new
      when 5  # end game
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to end game screen
        $scene = Scene_End.new
       end
      return
    end
  end
end
#---------------------- END SCENE_MENU CLASS ---------------------------------#
#==============================================================================
# ** Window_MenuStatus **
#------------------------------------------------------------------------------
#  This window displays party member status on the menu screen.
#==============================================================================
#                                                                             #
#   *REV1: The only edit made here is the size (height) of the window so that #
#   it accomodates only one hero/character and it's refresh method.           #
#                                                                             #
#=============================================================================#
class Window_MenuStatus < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 480, 140)# <--------- EDIT: RESIZED THE VIEWPORT
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
    self.active = false
    self.index = -1
  end
  
  def refresh
    self.contents.clear
    @item_max = $game_party.actors.size
      # EDIT: SETS PARTY LIMIT SO THAT ONLY THE LEAD CHARACTER DISPLAYS #
                   # IN THE VIEWPORT AT ANY GIVEN TIME #
      i = 0
      x = 64
      y = i * 116
      actor = $game_party.actors[i]
      draw_actor_graphic(actor, x - 40, y + 80)
      draw_actor_name(actor, x, y)
      draw_actor_class(actor, x + 144, y)
      draw_actor_level(actor, x, y + 32)
      draw_actor_state(actor, x + 90, y + 32)
      draw_actor_exp(actor, x, y + 64)
      draw_actor_hp(actor, x + 236, y + 32)
      draw_actor_sp(actor, x + 236, y + 64)
   end

end  
                       
#--------------------- END WINDOW_MENUSTATUS CLASS ---------------------------#
#==============================================================================
# ** Scene_End **
#------------------------------------------------------------------------------
#  This class performs game end screen processing.
#==============================================================================

class Scene_End
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make command window
    s1 = "To Title"
    s2 = "Shutdown"
    s3 = "Cancel"
    @command_window = Window_Command.new(192, [s1, s2, s3])
    @command_window.x = 320 - @command_window.width / 2
    @command_window.y = 240 - @command_window.height / 2
    # EDIT : LINE ADDED : Draws Parent Map behind command window #
    @spriteset = Spriteset_Map.new
    # END EDIT #
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame Update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of window
    @command_window.dispose
    # EDIT  LINE ADDED : Disposes Spriteset_Map
    @spriteset.dispose
    # END EDIT #
    # If switching to title screen
    if $scene.is_a?(Scene_Title)
      # Fade out screen
      Graphics.transition
      Graphics.freeze
    end
  end
end  
#------------------------ END SCENE_END CLASS --------------------------------#
#=============================================================================#
# ** Window_Base **
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window

  #--------------------------------------------------------------------------
  # * Draw Name
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------

         # EDIT: ADDED [REV1] : HERO NAME TEXT/EFFECTS
  
  # NOTE: Here, if you wish to use an altogether different font (with it's own 
  # separate set of values) for your hero's name in menus, adjust the color 
  # values, the name of the font you wish to use, and set the desired effect 
  # (either bold and/or italic) to true/false.
  
  def draw_actor_name(actor, x, y)
    
    ############## FONT/FONT VALUES: #####################
    self.contents.font.name = "Arial"
    self.contents.font.color = Color.new(255, 255, 255, 255)
    self.contents.font.bold = false
    self.contents.font.italic = false
    self.contents.font.size = 22
    ######################################################
    
    self.contents.draw_text(x, y, 120, 32, actor.name)
  end
#-----------------------------------------------------------------------------#
  #--------------------------------------------------------------------------
  # * Make State Text String for Drawing
  #     actor       : actor
  #     width       : draw spot width
  #     need_normal : Whether or not [normal] is needed (true / false)
  #--------------------------------------------------------------------------  
  def make_battler_state_text(battler, width, need_normal)
    # Get width of brackets
    brackets_width = self.contents.text_size("[]").width
    # Make text string for state names
    text = ""
    for i in battler.states
      if $data_states[i].rating >= 1
        if text == "" 
          text = $data_states[i].name
        else
          new_text = text + "/" + $data_states[i].name
          text_width = self.contents.text_size(new_text).width
          if text_width > width - brackets_width
            break
          end
          text = new_text
      end
    end
   end 
    # If text string for state names is empty, make it invisible
    if text == ""
      if need_normal
        # EDIT: DISPLAYS NO TEXT WHEN CHARACTER'S CONDITION IS "NORMAL"
        text = ""  
      end
    else
      # Attach brackets
      text = "[" + text + "]"
    end
    # Return completed text string
    return text
  end
end  
#------------------------ END WINDOW_BASE CLASS ------------------------------#
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
#  This class handles the party. It includes information on amount of gold 
#  and items. Refer to "$game_party" for the instance of this class.
#==============================================================================

# THIS MAKES IT SO IT KEEPS THE FIRST HERO IN THE DATABASE IN YOUR PARTY.
# MEANING YOU CAN'T HAVE OTHER MEMBERS ADDED TO THE PARTY DURING THE GAME
# USING ANY EVENT COMMANDS (LIKE "CHANGE PARTY MEMBER"). 

# HOWEVER, IT IS IMPORTATNT TO BE SURE THAT YOUR INITIAL STARTING PARTY 
# IS SET TO ONE HERO *ONLY* OR THE OTHER MEMBERS *WILL* BE IN THERE WITH YOU 
# (FOR INSTANCE, DURING BATTLES) BUT INACCESSABLE THROUGH *ANY* MENUS OTHER 
# THAN THE BATTLE SCREEN SINCE THE CMS IS DESIGNED FOR ONE HERO...

# ...UNLESS YOUR CHARACTER IS A COOL SAMURAI WITH A DOG THAT FOLLOWS HIM 
# AROUND AND FIGHTS ALONG SIDE HIM IN EPIC BATTLES LIKE ANY GOOD DOG FOLLOWING 
# THE CODE OF BUSHIDO WOULD...

# OKAY...I'M JUST JOKING AROUND THERE xD...TRY IT OUT THOUGH. YOU'LL SEE WHAT
# I MEAN...
class Game_Party  
  
  def add_actor(actor_id)
    # Get actor
    actor = $game_actors[actor_id]
    # If the party has less than 1 members and this actor is not in the party
    if @actors.size < 1 and not @actors.include?(actor)
      # Add actor
      @actors.push(actor)
      # Refresh player
      $game_player.refresh
    end
  end                          
end
#------------------------ END GAME_PARTY CLASS -------------------------------#
###############################################################################
#___________________________   END SCRIPT   __________________________________#
###############################################################################
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top