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.

A few script requests (XP)

topdod

Member

I want to limit how many saves lots there are available to the player to just the 3 saves slots


I also need a new menu. I need my menu to only have the Items and end game available


Finally I need to have an energy bar that drains a certain amount when you do various things say doing a job would waste some energy
and when the bar is empty or too low to do anything else you would have to go to bed


If anyone can help me out it would be a big help
 
topdod":2dsmwwr8 said:
I want to limit how many saves lots there are available to the player to just the 3 saves slots

Here ya go... paste this above main, or right below Scene_File

Code:
 

#==============================================================================

# ** Scene_File

#------------------------------------------------------------------------------

#  This is a superclass for the save screen and load screen.

#  Modified to allow 1 - 4 slots.

#  Set SLOTS to the number of slots you want.

#==============================================================================

 

class Scene_File

  SLOTS = 1

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     help_text : text string shown in the help window

  #--------------------------------------------------------------------------

  def initialize(help_text)

    @help_text = help_text

  end

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make help window

    @help_window = Window_Help.new

    @help_window.set_text(@help_text)

    # Make save file window

    @savefile_windows = []

    for i in 0..SLOTS - 1   ###

      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i)))

    end

    # Select last file to be operated

    @file_index = $game_temp.last_file_index

    @savefile_windows[@file_index].selected = true

    # 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

    @help_window.dispose

    for i in @savefile_windows

      i.dispose

    end

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Update windows

    @help_window.update

    for i in @savefile_windows

      i.update

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Call method: on_decision (defined by the subclasses)

      on_decision(make_filename(@file_index))

      $game_temp.last_file_index = @file_index

      return

    end

    # If B button was pressed

    if Input.trigger?(Input::B)

      # Call method: on_cancel (defined by the subclasses)

      on_cancel

      return

    end

    # If the down directional button was pressed

    if Input.repeat?(Input::DOWN)

      # If the down directional button pressed down is not a repeat,

      # or cursor position is more in front than 3

      if Input.trigger?(Input::DOWN) or @file_index < SLOTS - 1 ###

        # Play cursor SE

        $game_system.se_play($data_system.cursor_se)

        # Move cursor down

        @savefile_windows[@file_index].selected = false

        @file_index = (@file_index + 1) % SLOTS ###

        @savefile_windows[@file_index].selected = true

        return

      end

    end

    # If the up directional button was pressed

    if Input.repeat?(Input::UP)

      # If the up directional button pressed down is not a repeat、

      # or cursor position is more in back than 0

      if Input.trigger?(Input::UP) or @file_index > 0

        # Play cursor SE

        $game_system.se_play($data_system.cursor_se)

        # Move cursor up

        @savefile_windows[@file_index].selected = false

        @file_index = (@file_index + SLOTS - 1) % SLOTS  ###

        @savefile_windows[@file_index].selected = true

        return

      end

    end

  end

  #--------------------------------------------------------------------------

  # * Make File Name

  #     file_index : save file index (0-3)

  #--------------------------------------------------------------------------

  def make_filename(file_index)

    return "Save#{file_index + 1}.rxdata"

  end

end

 

I also need a new menu. I need my menu to only have the Items and end game available

This will shorten the main menu and leave a blank space. Please make a sketch or edit a screen capture of the main menu to show what you want.


Finally I need to have an energy bar that drains a certain amount when you do various things say doing a job would waste some energy
and when the bar is empty or too low to do anything else you would have to go to bed

Where do you want the energy bar to be displayed?
What do you want low energy to prevent the player from doing?
What happens if the player gets to energy 0, and doesn't find a bed?
How do you want to control the max amount of energy the player has? Is is static, or does it increase with level?

You will need to put some more thought & detail into some of these requests. Please read How to Make a decent Request
 

topdod

Member

Thank you for the save slot script


I made a small example of what I think would be a good menu for what I'm trying to do




clicking items would open the item window to it's normal size and same goes for end game.




As for the energy bar
the energy bar would be displayed on screen most of the time
times when it would not show is when going to sleep or a cut scene takes place.

The low energy is to stop the player from doing too much in one day
Lets say your energy is 20/200 and you try to do something that requires 30 energy
a message would appear saying something like "I'm too tired to do this"

The player can work a variety of jobs to earn money, having an energy bar would stop the player from doing too much in one day
you see I'm putting a time limit in the game so you only have so many days until the end.
I guess a good example of this would be Harvest moon, doing certain things waste different amounts of energy


If the player is too tired and fails to find a bed nothing happens
Most of the game takes place around one village so you will always be near your home


As for increasing the bar, I was thinking that I would at 200 and you could buy certain things that would fill it back up
say buying juice from the local shop would restore certain amounts of energy depending on the item


I hope this a better explanation of what I'm looking for
I'm not very good at explaining things
>_>
 
First off I'd like to thank you for keeping me occupied for an hour while I was sick! :biggrin: So here are the scripts for your menu, just follow these instructions and you should be fine.

Okay first off you'll need this code (Credits to rey meustrus for this part). You paste this script just under Window_Command.

Code:
#===============================================================================

# ¦ Window_Command

#-------------------------------------------------------------------------------

#   Written by mewsterus

#===============================================================================

 

class Window_Command2 < Window_Selectable

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_reader   :column_max

  attr_reader   :commands

  #-----------------------------------------------------------------------------

  # Make the window

  #-----------------------------------------------------------------------------

  def initialize(width, commands, column_max = 2, align = column_max == 1 ? 0:1)

    h = commands.size % column_max == 0 ? commands.size / column_max * 32 :

                                          commands.size / column_max * 32 + 32

    super(0, 0, width, h + 32)

    @column_max = column_max

    @item_max = commands.size

    @commands = commands

    @align = align

    self.contents = Bitmap.new(width - 32, h)

    refresh

  end

  #-----------------------------------------------------------------------------

  # @ Refresh the window

  #-----------------------------------------------------------------------------

  def refresh

    # Return if Window is Not Initialized

    return if self.contents.nil?

    # Deletes Existing Contents

    self.contents.dispose

    # Recreates Contents

    h = @item_max % @column_max == 0 ? @item_max / @column_max * 32 :

                                       @item_max / @column_max * 32 + 32

    self.contents = Bitmap.new(width - 32, h)

    for i in 0...@item_max

      draw_item(i, normal_color)

    end

  end

  #-----------------------------------------------------------------------------

  # @ Draw choice

  #-----------------------------------------------------------------------------

  def draw_item(index, color)

    cursor_width = self.width / @column_max - 32

    x = index % @column_max * (cursor_width + 32)

    y = index / @column_max * 32

    rect = Rect.new(x + 4, y, cursor_width - 8, 32)

    self.contents.font.color = color

    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))

    self.contents.draw_text(rect, @commands[index], @align)

  end

  #-----------------------------------------------------------------------------

  # @ Disable choice

  #-----------------------------------------------------------------------------

  def disable_item(index)

    draw_item(index, disabled_color)

  end

  #-----------------------------------------------------------------------------

  # * Command

  #-----------------------------------------------------------------------------

  def command(index = self.index)

    return @commands[index]

  end

  #-----------------------------------------------------------------------------

  # * Commands

  #-----------------------------------------------------------------------------

  def commands=(commands)

    # Return if Commands are the Same

    return if @commands == commands

    # Reset Commands

    @commands = commands

    # Resets Item Max

    @item_max = @commands.size

    # Refresh Window

    refresh

  end

  #-----------------------------------------------------------------------------

  # * Column Maximum

  #-----------------------------------------------------------------------------

  def column_max=(column_max)

    # Return if Column Maximum is the Same

    return if @column_man == column_max

    # Reset Column max

    @column_max = column_max

    # Refresh Window

    refresh

  end

  #-----------------------------------------------------------------------------

  # * Width

  #-----------------------------------------------------------------------------

  def width=(width)

    # Return if Width is the Same

    return if self.width == width

    # Reset Width

    super(width)

    # Refresh Window

    refresh

  end

end

 

Now you'll need this script which is for your menu. You can choose to either paste it above Main or replace your Scene_Menu with it, either will work.

Code:
#==============================================================================

# ** Scene_Menu

#------------------------------------------------------------------------------

#  This class performs menu screen processing.

#==============================================================================

 

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

    # Make the map, the background

    @spriteset = Spriteset_Map.new

    # Make command window

    s1 = $data_system.words.item

    s2 = "End Game"

    @command_window = Window_Command2.new(260, [s1, s2])

    @command_window.x = 220

    @command_window.y = 0

    @command_window.index = @menu_index

    # Make play time window

    @playtime_window = Window_PlayTime.new

    @playtime_window.x = 480

    @playtime_window.y = 0

    # Make steps window

    @steps_window = Window_Steps.new

    @steps_window.x = 480

    @steps_window.y = 96

    # Make gold window

    @gold_window = Window_Gold.new

    @gold_window.x = 480

    @gold_window.y = 192

    # 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

    @playtime_window.dispose

    @steps_window.dispose

    @gold_window.dispose

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    # Update windows

    @command_window.update

    @playtime_window.update

    @steps_window.update

    @gold_window.update

    # 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)

    # 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  # 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

  #--------------------------------------------------------------------------

  # * 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

    end

   end

 end

 

EDIT: Almost forgot about a slight error, when you exit the End screen it will try to go back to option 5 on the menu, if you want to change this to avoid a slight graphical error find line 56 in Scene_End should be;
Code:
$scene = Scene_Menu.new(5)
you can just change it to
Code:
$scene = Scene_Menu.new(1)
and that will be fixed.

This should work and if not give me a quick shout and I'll see what I can do to help you out.
 
Alright, here's the Energy Bar... Paste above main

Code:
 

#==============================================================================

# ** Energy Bar Addon

#------------------------------------------------------------------------------

#  Adds an Energy bar to the map

#

#  Use  $game_system.energy_bar = 0  to turn it off, 1 to turn it back on

#

#  @max_energy defaults to 200

#

#  To increase or decrease energy:

#  $game_party.increase_energy(n)

#  $game_party.decrease_energy(n)

#

#  Default position is 

#    self.x = 520

#    self.y = 0

#

#  29Jan09 - Brewmeister

#==============================================================================

 

#==============================================================================

# ** Game_System

#------------------------------------------------------------------------------

#  This class handles data surrounding the system. Backround music, etc.

#  is managed here as well. Refer to "$game_system" for the instance of 

#  this class.

#==============================================================================

 

class Game_System

  attr_accessor :energy_bar   # 1 if energy bar is on

  alias energy_bar_init initialize

  def initialize

    @energy_bar = 1

    energy_bar_init

  end

end

 

#==============================================================================

# ** 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.

#==============================================================================

 

class Game_Party

  #--------------------------------------------------------------------------

  # * Public Instance Variables

  #--------------------------------------------------------------------------

  attr_reader   :energy                   # party energy level

  attr_reader   :max_energy

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  alias topdod_init initialize

  def initialize

    @energy = @max_energy = 200

    topdod_init

  end

  def increase_energy(amount)

    @energy = [@energy + amount, @max_energy].min

  end

  def decrease_energy(amount)

    @energy = [@energy - amount, 0].max

  end

end

 

#==============================================================================

# ** Sprite_Energy_Bar

#------------------------------------------------------------------------------

#  This sprite is used to display the energy bar.

#==============================================================================

 

class Sprite_Energy_Bar < Sprite

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super

    self.bitmap = Bitmap.new(120, 24)

    self.bitmap.font.name = "Arial"

    self.bitmap.font.size = 22

    self.x = 520

    self.y = 0

    self.z = 500

    @energy = 0

    @max_energy = $game_party.max_energy

    update

  end

  #--------------------------------------------------------------------------

  # * Dispose

  #--------------------------------------------------------------------------

  def dispose

    if self.bitmap != nil

      self.bitmap.dispose

    end

    super

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    # Set energy bar to visible if working

    self.visible = $game_system.energy_bar == 1

    # If energy bar needs to be redrawn

    if self.visible

      if @energy != $game_party.energy

        @energy = $game_party.energy

        # Clear window contents

        self.bitmap.clear

        # Draw energy bar

        self.bitmap.font.color.set(255, 255, 255)

        self.bitmap.draw_text(self.bitmap.rect, "E")

        full = @energy * 100 / @max_energy

        black = Color.new(0,0,0)

        green = Color.new(0,255,0)

        self.bitmap.fill_rect(18, 8, 102, 8, black)

        self.bitmap.fill_rect(19, 9, full, 6, green)

      end

    end

  end

end

 

#==============================================================================

# ** Spriteset_Map

#------------------------------------------------------------------------------

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

  alias topdod_init initialize

  alias topdod_dispose dispose

  alias topdod_update update

  def initialize

    @energy_bar = Sprite_Energy_Bar.new

    topdod_init

  end

  def dispose

    topdod_dispose

    @energy_bar.dispose

  end

  def update

    topdod_update

    @energy_bar.update

  end

end

 

ref: NNolund_world_map
 

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