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.

Simple Script Finish - Half Complete

Alright... I was given this script from OptimistShadow over two months ago, and haven't gotten any help since... I really need this to get my game moving again.

This script is supposed to allow me to create menu selections based on switches... like a Bestiary, but switch-based rather than enemy-based. For example, if a certain switch is on, a selection will appear on a selection screen. If it isn't, it will be absent when the screen is shown.

Apparently this is the Window script... what I need is the Scene half of the script. Any help would be GREATLY appreciated. Thanks again - DarkLordX.

Code:
#==============================================================================
# ** Window_Album
#------------------------------------------------------------------------------
#  This window displays albums that the player has.
#==============================================================================
ALBUMS = [1,2,3,4,5]
class Window_Album < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 64, 640, 416)
    @column_max = 2
    @albums = ALBUMS
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Add item
    for i in 0..@albums.size - 1
      if $game_party.item_number(i) > 0
        @data.push($data_items[i])
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    case item
    when RPG::Item
      number = $game_party.item_number(item.id)
    when RPG::Weapon
      number = $game_party.weapon_number(item.id)
    when RPG::Armor
      number = $game_party.armor_number(item.id)
    end
    if item.is_a?(RPG::Item) and
       $game_party.item_can_use?(item.id)
      self.contents.font.color = normal_color
    else
      self.contents.font.color = disabled_color
    end
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end
 
Well, to help more...

1. How do you want to access the scene? Via menu or a button press while on the map?

2. SDK or non-SDK? (but I guess it's non-SDK)

So far, those are the only things I can think about :P
 
The script is called through an event.

.. should probably be SDK compatible.


Since I just realized that the script mentions albums and the like, I should probably explain what I want to use this script for...

My game includes a jukebox system in which you can find, win, buy, or sometimes steal various albums throughout the game. Once you have an album, you can insert it into a jukebox. The jukebox will show that album in your collection based on a switch modified when the album is inserted. Once an album is available, you can also choose to play any album in your collection.

The problem is this... In the insertion menu, I need an album to appear only if it's in your inventory; in the play menu, I need the album to appear only if it's already been inserted. (Based on a switch)

I hope this helps.. if you need any more information, feel free to ask.
 

OS

Sponsor

Hello, DarkLordX.

Give me a few minutes, and I'll make this better for you...

I see a few things that could be even better. I'll have it done before I log off tonight.

EDIT 2:

It's almost done.

EDIT 3:

Okay, I haven't fully tested it's ability to play music, but I did test the menus, and they work thus far. If you have any issues, just PM me with them, and I'll fix them the best I can. If I can lose some work this weekend I may rewrite it entirely to make it more efficient and pretty.

Replace the first script I gave you with this:
Code:
#==============================================================================
# ** Window_Album
#------------------------------------------------------------------------------
#  This window displays albums that the player has.
#==============================================================================
ALBUMS = [1,2,3,4,5]
class Window_Album < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(source)
    super(0, 64, 640, 416)
    @source = source
    @column_max = 2
    @albums = ALBUMS
    refresh
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Add item
    if @source.instance_of?(Game_Party)
      for i in 0..@albums.size - 1
        if $game_party.item_number(i) > 0
          @data.push($data_items[i])
        end
      end
    else
      for i in 0..@albums.size - 1
        if $game_system.albums_in_jbox.include?(i)
          @data.push($data_items[i])
        end
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    opacity = self.contents.font.color == normal_color ? 255 : 128
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
end

Then add this beneath that one:
Code:
class Game_System
  attr_accessor :albums_in_jbox
  alias os_album_init initialize
  def initialize
    os_album_init
    @albums_in_jbox = []
  end
end

class Scene_Album
  def initialize
    @inserting = false
    @retrieving = false
  end
  
  def main
    $spriteset = Spriteset_Map.new
    s00 = "Play"
    s01 = "Insert"
    s02 = "Retrieve"
    s03 = "Exit"
    @choose_action = Window_Command.new(160,[s00,s01,s02,s03])
    s11 = "Play Music"
    s12 = "Back"
    @choose_action2 = Window_Command.new(160,[s11,s12,s03])
    @choose_action2.active = false
    @choose_action2.visible = false
    @owned_albums = Window_Album.new($game_party)
    @owned_albums.visible = false
    @owned_albums.active = false
    @juke_albums = Window_Album.new($game_system.albums_in_jbox)
    @juke_albums.visible = false
    @juke_albums.active = false
    @help_window = Window_Help.new
    @help_window.visible = false
    @owned_albums.help_window = @help_window
    @juke_albums.help_window = @help_window
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    $spriteset.dispose
    @choose_action.dispose
    @choose_action2.dispose
    @owned_albums.dispose
    @juke_albums.dispose
    @help_window.dispose
  end
  
  def update
    $spriteset.update
    @choose_action.update
    @choose_action2.update
    @owned_albums.update
    @juke_albums.update
    @help_window.update
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      if @choose_action.active
        @choose_action2.active = false
        @choose_action2.visible = false
        @choose_action.active = false
        @choose_action.visible = false
        @owned_albums.visible = false
        @owned_albums.active = false
        @juke_albums.active = false
        @juke_albums.visible = false
        $scene = Scene_Map.new
      elsif @choose_action2.active
        @choose_action2.active = false
        @choose_action2.visible = false
        @choose_action.active = true
        @choose_action.visible = true
        @owned_albums.visible = false
        @owned_albums.active = false
        @juke_albums.active = false
        @juke_albums.visible = false
      else
        @choose_action2.active = true
        @choose_action2.visible = true
        @choose_action.active = false
        @choose_action.visible = false
        @help_window.visible = true
        @owned_albums.visible = false
        @owned_albums.active = false
        @juke_albums.active = false
        @juke_albums.visible = false
      end
      return
    end
    if Input.trigger?(Input::C)
      if @choose_action.active
        case @choose_action.index
        when 0 # Play
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @choose_action.active = false
          @choose_action.visible = false
          @choose_action2.active = false
          @choose_action2.visible = false
          @juke_albums.active = true
          @juke_albums.visible = true
        when 1 # Insert
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @retrieving = false
          @choose_action.active = false
          @choose_action.visible = false
          @owned_albums.active = true
        when 2 # Retrieve
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @retrieving = true
          @choose_action.active = false
          @choose_action.visible = false
          @juke_albums.active = true
          @juke_albums.visible = true
        when 3 # Exit
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @choose_action2.active = false
          @choose_action2.visible = false
          @choose_action.active = false
          @choose_action.visible = false
          @owned_albums.visible = false
          @owned_albums.active = false
          @juke_albums.active = false
          @juke_albums.visible = false
          $scene = Scene_Map.new
        end
        return
      elsif @choose_action2.active
        case @choose_action2.index
        when 0 # Play
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @choose_action2.active = false
          @choose_action2.visible = false
          @juke_albums.active = true
        when 1 # Back
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @choose_action2.active = false
          @choose_action2.visible = false
          @choose_action.active = true
          @choose_action.visible = true
          @owned_albums.visible = false
          @owned_albums.active = false
          @juke_albums.active = false
          @juke_albums.visible = false
        when 2 # Exit
          # Play decision SE
          $game_system.se_play($data_system.decision_se)
          @choose_action2.active = false
          @choose_action2.visible = false
          @choose_action.active = false
          @choose_action.visible = false
          @owned_albums.visible = false
          @owned_albums.active = false
          @juke_albums.active = false
          @juke_albums.visible = false
          $scene = Scene_Map.new
        end
        return
      elsif @owned_albums.active # Obviously Inserting
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        $game_party.lose_item(@owned_albums.index, 1)
        $game_system.albums_in_jbox = @owned_albums.index
        return
      elsif @juke_albums.active # Retrieving or Playing
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        if @retrieving
          $game_party.gain_item(@juke_albums.index, 1)
          $game_system.albums_in_jbox = @juke_albums.index
        end
        Audio.bgm_play("#{data_items[@juke_albums.index].name}")
        $scene = Scene_Album.new
        return
      end
    end
  end
end

To set the Jukebox to hold albums before hand, just do this:

$game_system.albums_in_jbox.push(album_id)

I think there may be a problem with the Help window (the long window at the top of the screen). If there is, let me know in a PM.

Peace!
 

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