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.

Alchemy 2.0--Incomplete

OS

Sponsor

EDIT: I fixed the display errors with the Item list. You will now see the items you have, and then the items you can attempt to make. But some new bugs have arisen that my attention needs. Peace Out!

Hello, everybody. I wrote this script last night, and I believe that there is little more I can do to it at my current scripting level. So here is the INCOMPLETE Version. It works to an extent, but a few (several) things need to be done/fixed.

INTRODUCTION


This script is an Alchemy Script. It is basically used to Transmute one item into an other with the same Element Tag and size. Later this script should allow fusing two smaller items into one item with a size == item1 + item2. But for now, it can only replace an item. Also, I accidently coded it to allow you to make an item you have in your inventory into a different item in your inventory. But this can be fixed later. Just look at the script, and if you want, finish it or fix the bugs. Sorry if it is bad to post stuff like this, but I want to see who is interested in it. (Note that this has nothing to do with my old Alchemy Modules).

Script

Game_Alchemy, Alchemy_Database, and Scene_Title edit command_new_game
Code:
class Scene_Title
  def command_new_game
    # Play decision SE
    $game_system.se_play($data_system.decision_se)
    # Stop BGM
    Audio.bgm_stop
    # Reset frame count for measuring play time
    Graphics.frame_count = 0
    # Make each type of game object
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    $game_alchemy       = Game_Alchemy.new
    # Set up initial party
    $game_party.setup_starting_members
    # Set up initial map position
    $game_map.setup($data_system.start_map_id)
    # Move player to initial position
    $game_player.moveto($data_system.start_x, $data_system.start_y)
    # Refresh player
    $game_player.refresh
    # Run automatic change for BGM and BGS set with map
    $game_map.autoplay
    # Update map (run parallel process event)
    $game_map.update
    # Switch to map screen
    $scene = Scene_Map.new
  end
end

class Alchemy_Database
  def initialize
   #item = [item_id, element_id, size]
    a1   = [1, 17, 1]
    a2   = [2, 17, 2]
    a3   = [3, 17, 3]
    a4   = [26, 21, 6]
    a5   = [29, 19, 7]
    $data_alchemy = [a1, a2, a3, a4, a5]
  end
end

class Game_Alchemy < Alchemy_Database
  def initialize
    super()
    @alchemy = $data_alchemy
    @elements = $data_system.elements
    check_matter_existance(@alchemy)
  end
  
  def check_matter_existance(array)
    a = []
    #element_id = []
    for i in 0..array.length - 1
      element_id = array[i][1]
      if !array[i].empty? and @elements[element_id] != nil
        a << 1
      else
        a << 0
      end
    end
    for i in 0..array.length - 1
      if a[i] == 0
        array.delete_at(i)
      end
    end
    return array
  end
  
  def replace_material?(new_matter, old_matter)
    matter1 = @alchemy[new_matter][0]
    matter2 = @alchemy[old_matter][0]
    type1   = @alchemy[new_matter][1]
    type2   = @alchemy[old_matter][1]
    size1   = @alchemy[new_matter][2]
    size2   = @alchemy[old_matter][2]
    if matter1 != matter2 && type1 == type2 && size1 == size2
      return true
    else
      return false
    end
  end
end
Scene_Transmute and Scene_Alchemy
Code:
#==============================================================================
# ** Scene_Transmute
#------------------------------------------------------------------------------
#  This class performs Transmute screen processing.
#==============================================================================

class Scene_Transmute
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     menu_index : command cursor's initial position
  #--------------------------------------------------------------------------
  def initialize(menu_index = 0)
    @menu_index = menu_index
  end
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @spriteset = Spriteset_Map.new
    # Make command window
    s1 = "Transmute"
    s2 = "Exit"
    @command_window = Window_Command.new(160, [s1, s2])
    @command_window.index = @menu_index
    # 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
    @spriteset.dispose
    # Dispose of windows
    @command_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @command_window.update
    @spriteset.update
    # 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  # Transmute
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch to Scene_Alchemy
        $scene = Scene_Alchemy.new
      when 1  # Exit
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Switch back to the Map
        $scene = Scene_Map.new
      end
      return
    end
  end
end

#==============================================================================
# ** Scene_Alchemy
#------------------------------------------------------------------------------
#  This class performs Alchemy screen processing.
#==============================================================================

class Scene_Alchemy
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    @help_window = Window_Help.new
    @item_window = Window_Item.new
    @item_list   = Window_Item_List.new
    @item_list.active = false
    @item_list.visible = false
    @item = nil
    @item2 = nil #Used in Transmutation
    @item_chosen = false
    # Associate help window
    @item_window.help_window = @help_window
    # 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
    @item_window.dispose
    @item_list.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    @help_window.update
    @item_window.update
    @item_list.update
    # If item window is active: call update_item
    if @item_window.active && @item_chosen == false
      update_item1
      return
    end
    if @item_window.active && @item_chosen == true
      @item_window.visible = false
      @item_window.active = false
      @item_list.visible = true
      @item_list.active = true
      update_item2
      return
    end
    if @item_list.active == true && @item2 != nil
      transmute(@item, @item2)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item1
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Transmute.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
        @item = @item_window.item
      # If not a use item
      unless @item.is_a?(RPG::Item)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # If it can't be used
      unless $game_party.item_can_use?(@item.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      @item_chosen = true
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item2
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Transmute.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item2 = @item_list.item
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Transmute
  #--------------------------------------------------------------------------
  def transmute(start, product) #add Transmute:type later.
    @item_list.active = false
    @item_list.visible = false
    allowed = $game_alchemy.replace_material?(start, product)
    if allowed == true
      $game_system.play_se($data_system.decision_se)
      $game_party.lose_item(start, 1)
      $game_party.gain_item(product, 1)
      $scene = Scene_Transmute.new
    else
      $game_system.se_play($data_system.buzzer_se)
      $game_party.lose_item(start, 1)
      $scene = Scene_Transmute.new
    end
  end
end
FAQ

What is the deal with the Transmutation? I have to choose 3 items (instead of only 2), and then I get an error! Why is that?
A. I think it's a logic error, or I screwed up Scene_Alchemy's command_update or whatever. I'll fix it later.

FUTURE FEATURES

When complete and working, this script should:
  1. Allow Transmutation of One item into a different item [60%]
  2. Allow two small items to become 1 bigger item [0%]
  3. Check for Law of Equivilant Exchange [100%+error]
  4. Have a fully functioning menu [90%]
  5. Be compatible with most other scripts [I dunno...]
  6. Be bug free...(maybe) [12%]

If someone wants to try and complete the script, be my guest. But remember to credit me for most of the script, and Giarc Maj, becuase I wrote it for his FMA Fangame, Fullmetal Alchemist: --Working Title--. If anyone wants me to add features, lemme know!

Peace Out!
~Broken

EDIT: I will explain more about the script when I have more time!
 

OS

Sponsor

um...okay. I'll begin fixing some of the errors and I'll repost the edited portions. Peace Out!

~Broken
 

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