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.

My-Cooking Script

Status
Not open for further replies.
Hi all, this is My first Script I made for RMXP...


Code:
#BEGIN
#
#---------------------------------------------------------------------------------------------
#Cooking Module & Control Ver. 0.4
#By: Theodore Van Vermillious
#Since August 28th, 2008
#---------------------------------------------------------------------------------------------
#
#
#INTRODUCTION
#
#  As you know, crafting is really good idea in some games.
#  But, cooking is a good idea too.
#  Why I make this nonsense script?
#    - Because I am a maniacgamerfreak (ManiacGamer + GamerFreak = CrazyGamer)
#    - I need some script for my newest game, sorry but it still untitled.
#
#  Thanks for reading this unfiltered junk.
#
#HISTORY
#Ver 0.1
# Create core for this module
#
#Ver 0.2
#  Added some window for control
#  change hash table structure
#  Adapt PrexCraft module and script
#  Do major change at some aliased
#  Accessable Material Menu for Cook from Menu or Other
#
#
#CREDIT
#  If you wanna credit someone, please credit Me & Prexus.
#  Why? Because Prexus' PrexCraft inspiring me to create this script.
#
#NB : This script is on modest improvement. Why? Because I still learning RGSS…
#
#END

#--------------------------------------------------------------------------
# Name : Module_Cook
# Type : module
# Categorized : Main Controller. Control many of functions
# Description : Main module. Change at your own risk
#--------------------------------------------------------------------------
module Module_Cook
# Constants, DON'T CHANGE IT AT YOUR RISK
  USED = true # Used and vanished after effect
  UNUSED = false # Return to owner after cooking process
  
# MATERIALS SECTION
  # Cook List, add or your material for cook here.
  # You must be consistent, 1 to 2 to 3 to n...
  # Make sure, when you call script $game_party.gain_cook(item_id, n), item_id is listed here
  # Instead of looking at 'ID', remember position of materials.
  MATERIALS = [
  {
  'ID' => 0,
  'Name' => 'Bread',
  'Type' => 'Material',
  'Price' => 10
  },
  {
  'ID' => 1,
  'Name' => 'Mayonnaise',
  'Type' => 'Material',
  'Price' => 32
  },
  {
  'ID' => 2,
  'Name' => 'Spatula',
  'Type' => 'Tool',
  'Price' => 1000
  },
  {
  'ID' => 3,
  'Name' => 'Hot Sauce',
  'Type' => 'Material',
  'Price' => 20
  },
  {
  'ID' => 4,
  'Name' => 'Egg',
  'Type' => 'Material',
  'Price' => 5
  },
  {
  'ID' => 5,
  'Name' => 'Noodle',
  'Type' => 'Material',
  'Price' => 50
  },
  {
  'ID' => 6,
  'Name' => 'Frying Fan',
  'Type' => 'Tool',
  'Price' => 2500
  },
  {
  'ID' => 7,
  'Name' => 'Knife',
  'Type' => 'Tool',
  'Price' => 1500
  },
  {
  'ID' => 8,
  'Name' => 'Oven',
  'Type' => 'Tool',
  'Price' => 5000
  },
  {
  'ID' => 9,
  'Name' => 'Salt',
  'Type' => 'Material',
  'Price' => 20
  },
  {
  'ID' => 10,
  'Name' => 'Oil',
  'Type' => 'Material',
  'Price' => 13
  },
  {
  'ID' => 11,
  'Name' => 'Flour',
  'Type' => 'Material',
  'Price' => 22
  },
  {
  'ID' => 12,
  'Name' => 'Tomato',
  'Type' => 'Material',
  'Price' => 10
  },
  {
  'ID' => 13,
  'Name' => 'Pepper',
  'Type' => 'Material',
  'Price' => 12
  },
  {
  'ID' => 14,
  'Name' => 'Carrot',
  'Type' => 'Material',
  'Price' => 21
  },
  {
  'ID' => 15,
  'Name' => 'Pumpkin',
  'Type' => 'Material',
  'Price' => 96
  },
  {
  'ID' => 16,
  'Name' => 'Spinach',
  'Type' => 'Material',
  'Price' => 102
  },
  {
  'ID' => 17,
  'Name' => 'Strawberry',
  'Type' => 'Material',
  'Price' => 120
  },
  {
  'ID' => 18,
  'Name' => 'Whisk',
  'Type' => 'Tool',
  'Price' => 2100
  },
  {
  'ID' => 19,
  'Name' => 'Salmon',
  'Type' => 'Material',
  'Price' => 200
  },
  {
  'ID' => 20,
  'Name' => 'Pot',
  'Type' => 'Tool',
  'Price' => 6500
  }
  
  ]
  # End of Cook Item List

#RECIPES LIST SECTION
  # Format for adding recipe in this list is just like this.
  # {
  # 'Name' => 'name',
  # 'Result' => [item_id , quantity], #item_id = Id of item in database as the result.
  # 'Description' => 'Description',
  # 'COMPONENTS' => [[cook_id, qty, USED or UNUSED],[cook_id, qty, USED or UNUSED],...] #cook_id = Id of item in script. It explained before.
  # }, #end of this Recipe
  # {
  # 'Name' => 'name',
  # 'Result' => [item_id, quantity],
  # 'Description' => 'Description',
  # 'COMPONENTS' => [[cook_id, qty, USED or UNUSED],[cook_id, qty, USED or UNUSED],...]
  # } #end of last Recipe
  #Add comma after recipe.
  RLIST = [
  {
  'Name' => 'Baked Bread',
  'Result' => [33, 1],
  'Description' => 'Regular Bread baked in oven. Great for breakfast.',
  'COMPONENTS' => [[0, 1, USED],[7, 1, UNUSED],[8, 1, UNUSED]]
  },
  {
  'Name' => 'Omelet',
  'Result' => [34, 1],
  'Description' => 'Omelet.',
  'COMPONENTS' => [[2, 1, USED],[4, 1, UNUSED],[6, 1, UNUSED],[9, 1, USED],[10, 1, USED],[18, 1, UNUSED]]
  },
  {
  'Name' => 'Scramble Egg',
  'Result' => [35, 1],
  'Description' => 'Scramble Egg.',
  'COMPONENTS' => [[2, 1, USED],[4, 1, UNUSED],[6, 1, UNUSED],[9, 1, USED],[10, 1, USED]]
  },
  {
  'Name' => 'Hot Water',
  'Result' => [36, 1],
  'Description' => 'Water Bomb made from 10 litter of water and boiled in pot for 100 hours.',
  'COMPONENTS' => [[20, 1, UNUSED],[21, 10, USED]]
  }
  ]
  #  end of recipes list section
  #---------------------------------------------------------------------------------------------
  #Module_Cook.valid_recipe?(name)
  #check validation of recipe
  #---------------------------------------------------------------------------------------------
  def self.valid_recipe?(name)
    for recipe in RLIST
      return true if name == recipe['Name']
    end
    return false
  end
  
  #---------------------------------------------------------------------------------------------
  #Module_Cook.can_make?(name)
  #Get name of recipe and check it validation and then check components
  #---------------------------------------------------------------------------------------------
  def self.can_make?(name)
    return false unless self.valid_recipe?(name)
    for r in RLIST
      next unless name == r['Name']
      recipe = r
      return false unless recipe
    end
    for component in recipe['COMPONENTS']
      return false unless $game_party.cook_number(component[0]) >= component[1]
    end
      return true
  end
  #---------------------------------------------------------------------------------------------
  #Module_Cook.get_recipe(name)
  #Get name of recipe and check validation of it name
  #---------------------------------------------------------------------------------------------
  def self.get_recipe(name)
    return nil unless self.valid_recipe?(name)
    for recipe in RLIST
      return recipe if recipe['Name'] == name
    end
    return nil
  end
end
#--------------------------------------------------------------------------
# Name : Game_Party
# Type : class
# Categorized : Game Setup
# Description : Revised version of standard $game_party.
#--------------------------------------------------------------------------
class Game_Party
  attr_reader :recipe_got
  attr_reader :cook_item
  
  alias cooking_theo_init initialize
  
  def initialize
    cooking_theo_init
    @recipe_got = []
    @cook_item = {}
  end
  
  def cook_number(item_id)
    if valid_material(item_id)
      return @cook_item.include?(item_id) ? @cook_item[item_id] : 0
    end
    return nil
  end
  
  def valid_material(item_id)
    for materi in Module_Cook::MATERIALS
      return true if materi['ID'] == item_id
    end
    return false
  end
  
  def gain_recipe(name)
    @recipe_got.push(name) if Module_Cook.valid_recipe?(name) and !have_recipes(name)
  end
  
  def remove_recipe(name)
    @recipe_got.delete(name)
  end
  
  def gain_cook(item_id, n)
    @cook_item[item_id] = [[cook_number(item_id) + n, 0].max, 99].min
  end
  
  def lose_cook(item_id, n)
    gain_cook(item_id, -n)
  end
    
  def have_recipes(name)
    return @recipe_got.include?(name)
  end
end
#SCENE SECTION
#--------------------------------------------------------------------------
# Name : Scene_Menu
# Type : class
# Categorized : Scene
# Description : Menu.
#--------------------------------------------------------------------------
class Scene_Menu
  alias cook_theo_main main
  alias cook_theo_init initialize
  alias cook_theo_update update
  alias cook_theo_update_command update_command
  def initialize(menu_index = 0)
    cook_theo_init
  end
  def main
    s1 = $data_system.words.item
    s2 = $data_system.words.skill
    s3 = $data_system.words.equip
    s4 = "Status"
    s5 = "Save"
    s6 = "Exit"
    s7 = 'Cook Material'
    @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6, s7])
    @command_window.height = 224
    @command_window.index = @menu_index
    if $game_party.actors.size == 0
      @command_window.disable_item(0)
      @command_window.disable_item(1)
      @command_window.disable_item(2)
      @command_window.disable_item(3)
    end
    if $game_system.save_disabled
      @command_window.disable_item(4)
    end
    @playtime_window = Window_PlayTime.new
    @playtime_window.x = 0
    @playtime_window.y = 224
    @steps_window = Window_Steps.new
    @steps_window.x = 0
    @steps_window.y = 320
    @gold_window = Window_Gold.new
    @gold_window.x = 0
    @gold_window.y = 416
    @status_window = Window_MenuStatus.new
    @status_window.x = 160
    @status_window.y = 0
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @command_window.dispose
    @playtime_window.dispose
    @steps_window.dispose
    @gold_window.dispose
    @status_window.dispose
  end
  def update
    cook_theo_update
  end
  def update_command
    cook_theo_update_command
    if Input.trigger?(Input::C)
      case @command_window.index
      when 6
        $game_system.se_play($data_system.decision_se)
        $scene = Scene_Material_Cook_List.new('Menu')
      end
    end
    return
  end
end
#--------------------------------------------------------------------------
# Name : Scene_Cook
# Type : class
# Categorized : Scene
# Description : This Scene is main scene for executing your cook.
#--------------------------------------------------------------------------
class Scene_Cook
  #-----------------------------------------------------------------------------
  def main
    @recipe_list = Window_Reseplist.new
    @cook_desc = Window_Cook_Description.new
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      break if $scene != self
    end
    Graphics.freeze
    @recipe_list.dispose
    @cook_desc.dispose
  end
  #-----------------------------------------------------------------------------
  def item
    return @recipe_list.data[@recipe_list.index]
  end
  def description
    for recipe in Module_Cook::RLIST
      name = recipe['Name']
      descrip = recipe['Description']
      database = @recipe_list.data
      if database == name
          return descrip
      end
    end
  return ""
  end
  def update
    @recipe_list.update
    @cook_desc.update
    if @recipe_list.active
      update_help
    end
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      $scene = Scene_Map.new
      return
    end
    if Input.trigger?(Input::C)
      if cook(@recipe_list.data)
        $game_system.se_play($data_system.decision_se)
      else
        $game_system.se_play($data_system.buzzer_se)
      end
      @recipe_list.refresh
      return
    end
  end
  #-----------------------------------------------------------------------------
  def update_help
    return @cook_desc.set_text(self.item == nil ? "" : self.description)
  end
  #-----------------------------------------------------------------------------
  def cook(recipe)
    return false unless Module_Cook.can_make?(recipe)
    recipe = Module_Cook.get_recipe(@recipe_list.data)
    for component in recipe['COMPONENTS']
      $game_party.lose_cook(component[0], component[1]) if component[2]
    end
    recipe = Module_Cook.get_recipe(@recipe_list.data)
      $game_party.gain_item(recipe['Result'][0], recipe['Result'][1])
    return true
  end
end
#--------------------------------------------------------------------------
# Name : Scene_Material_Cook_List
# Type : class
# Categorized : Scene
# Description : Scene for displaying material we have got.
#--------------------------------------------------------------------------
class Scene_Material_Cook_List
  def initialize(type = nil)
    @type = type
  end
  def main
    @material_window = Window_materiallist.new(@type)
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @material_window.dispose
  end
  def update
    @material_window.update
    if @material_window.active
      update_material
      return
    end
  end
  def update_material
    if Input.trigger?(Input::B)
      $game_system.se_play($data_system.cancel_se)
      if @type == 'Menu'
        $scene = Scene_Menu.new(6)
      else
        $scene = Scene_Map.new
      end
      return
    end
  end
end

#WINDOW SECTION
#--------------------------------------------------------------------------
# Name : Window_Reseplist
# Type : class
# Categorized : Window
# Description : This window will list the recipe that you have got.
#--------------------------------------------------------------------------
class Window_Reseplist < Window_Selectable
  def initialize
    super(0, 80, 640, 400)
    self.contents = Bitmap.new(width - 32, height - 32)
    @data = []
    refresh
  end
  #-----------------------------------------------------------------------------
  def data
    return @data[self.index]
  end
  # Defining Refresh Function for this class
  def refresh
    self.contents.clear
    @data = []
    for recipe in $game_party.recipe_got
      @data.push(recipe) if Module_Cook.valid_recipe?(recipe)
    end
    @item_max = @data.size
    self.index = [[self.index, 0].max, @item_max].min
    for i in 0..@data.size
      data = @data[i]
      x = @data.size
      self.contents.font.color = (Module_Cook.can_make?(data) ? Color.new(0, 255, 0, 255) : Color.new(255, 0, 0, 255))
      self.contents.draw_text(x, i * 32, self.contents.width - x, 32, data.to_s)
    end
  end
end

#--------------------------------------------------------------------------
# Name : Window_Cook_Description
# Type : class
# Categorized : Window
# Description : This window will tell you about recipe you have.
#--------------------------------------------------------------------------
class Window_Cook_Description < Window_Base
  def initialize
    super(0, 0, 640, 80)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.contents.font.name = $defaultfonttype  # "Help" window font
    self.contents.font.size = $defaultfontsize
  end
  #--------------------------------------------------------------------------
  def set_text(text, align = 0)
    if text != @text or align != @align
      self.contents.clear
      self.contents.font.color = normal_color
      self.contents.draw_text(4, 0, self.width - 40, 32, text, align)
      @text = text
      @align = align
      @actor = nil
    end
    self.visible = true
  end
end
# Display Cook List in some manner of time
#--------------------------------------------------------------------------
# Name : Window_materiallist
# Type : class
# Categorized : Window
# Description : This window will list the material that you have got.
#--------------------------------------------------------------------------
class Window_materiallist < Window_Selectable
  def initialize(type)
    super(0, 0, 640, 480)
    self.contents = Bitmap.new(width - 32, height - 32)
    @data = []
    @cook_list = Module_Cook::MATERIALS
    @type = type
    refresh
  end
  #-----------------------------------------------------------------------------------
  def data
    return @data[self.index]
  end
  #-----------------------------------------------------------------------------------

  def refresh
    self.contents.clear
    item = @cook_list
    @data = []
    x = 0; y = 0
    for recipe in $game_party.cook_item
      @data.push('')
    end
    for recipe in $game_party.cook_item
      for name in @cook_list
        if name['ID'] == recipe[0]
          self.contents.draw_text(x + 28, y, 212, 32, name['Name'], 0)
          self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
          self.contents.draw_text(x + 256, y, 24, 32, recipe[1].to_s, 2)
          y += 32
        end
      end
    end
    @item_max = @data.size
    self.index = [[self.index, 0].max, @item_max].min
    for i in 0..@data.size
      data = @data[i]
      x = @data.size
      self.contents.draw_text(x, i * 32, self.contents.width - x, 32, data.to_s)
    end
  end
end

#by: Theodore Van Vermillious
 
This look pretty neat, haven't tried it thought but I guess it looks good anyway :P

Wait! How could this be your first script? or is it just your first released script?
 
Nonono I don't believe this. You said you were "inspired" by Prexus but I've compared both scripts side by side, and yours is a copy/paste of Prexus script with only a few minor edits. You removed a lot of things and changed the names of a couple of variables. That's all....
 
Status
Not open for further replies.

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