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.

[b]Cook Request[\b]

Hi everyone, this 16 years old newbie is in need. Can you help?

Introduction

First of all, I want to say sorry for my bad English. This request is made because of less of my knowledge in RGSS (still learn).

As you know, cooking is combining two or more materials to make a cook. To make a cook, we need tool and material, and recipe too. You can found those things at shop or someone give you.

The purpose of this request is to complete my newest game and as a media for me to learn Ruby, especially RGSS.

Dictionary
- Material: Item that you need to make a cook. This Item mustn’t be listed in Item Database but script.
- Recipe: Item you need to make a cook. Contain materials list and step-by-step for making a cook.

Syntax
Syntax for Materials and Recipes in script could be anything.
Materials must contain:
- Name, identifier.
- Price, it will be used in shop.
- Type, value must be ‘Tool’ or ‘Material’
- Description.

Recipes must contain:
- Name, identifier.
- Components, listed here materials you need to make this recipe become true.
- Description.


My Script

This script is adapted from Prexus’ PrexCraft script for crafting. But, this script still needs improvement. I need shop processing for this script. I could be easy to make shop for Item in Database. But, Material is Item that can’t be used for independently. It must be combined with other materials to be an item that can be used. So, It can’t be from Database.

Instruction
If you want to add recipe to your book, use: $game_party.gain_recipe(name) # Change name to name of recipe you want.
Example: $game_party.gain_recipe(‘Baked Bread’)

If you want to add some material to your book, use: $game_party.gain_cook(item_id, n) # Item id is identifier for item in script, not database.(look at the script below).
Example: $game_party.gain_recipe(0, 10) # It will return 10 bread (if you don’t change database of script.)

If you want to remove recipe from your book, use: $game_party.remove_recipe(name) # Change name to name of recipe you want.
Example: $game_party.remove_recipe(‘Baked Bread’)

If you want to remove some material from your book, use: $game_party.lose_cook(item_id, n) # Explained by it name.
Example: $game_party.lose_cook(0, 10) # If your bread is n, and >= 10, your bread will become n -= 10. but, if n < 10, it will become n = 0.

When you need to call Stove Scene, use this: $scene = Scene_Cook.new
When you need to call Material List Scene, use this: $scene = Scene_Material_Cook_List.new
# Calling Material List Scene is useless because you can access it from menu.

Screenshot

When you want to cook something, you will see this window.
http://download352.mediafire.com/hmdyp2 ... +Stove.PNG[/img]
This window still doesn’t have material list window, confirmation box, and result description.
It will be hard for player to see manage the change.


This window display list of material you have.
http://download352.mediafire.com/vmyvl1 ... l+List.PNG[/img]
It still doesn’t have description window and any other user interfaces.
And, the list is still in one row.

Script
This is my script. Take a look at this, please…


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


What I Need Is…

Have you done with my script yet? Thanks a lot.

First, I need a scene that list materials and recipes player have.
It could be just like this:
http://download352.mediafire.com/detztl ... tebook.png[/img]


1. Material List: This window will display materials you have. If you don’t have any, this Window will display nothing.

2. Recipe List: This window will display recipes you have. If you don’t have any, this Window will display nothing.

3. Description: This window will display description of highlighted Material. (Description is written in module). If Material list is focus/active, this window displays highlighted Material description. If Recipe list is focus/active, this window displays highlighted Recipe description and display components you need to make highlighted recipe.

4. To switch between Material List Window and Recipe List Window, player can press a button (you can assign it whatever you want).

5. If it possible, you can add Drop Button for remove some materials. (I don’t really need it though).

Secondly, I need stove processing where you can bake some materials to make a new item.
It could be just like this:
http://download352.mediafire.com/w9nzdc ... rocess.png[/img]


Most left window display Recipe you have. This window is selectable so you can select a recipe you want.

Bottom-Left Window will display description of highlighted recipe.

Right window will display material you need to make cook.

And, Bottom-Right window is Confirmation Box.

Red colored text in component list window is item that still in need. Example, ‘Frying Pan   1/0’ mean, you have 0 Frying Pan, but it need 1 Pan.
Red colored text in recipe list window determines that you can’t make that cook.


(Components/materials must not from Database.)

Lastly, I need shop for buying materials.
It could be just like this:
http://download352.mediafire.com/qhmntn ... l+Shop.png[/img]


Closure

That’s all I need, before and after this request made, I want to say sorry to everyone who read this request because of mispronunciations. Please pardon me…

Thanks for your attention, Wahaha, and see you…

Sincerely Yours,




~Theodore Van Vermillious~
 

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