Group: Member
Posts: 42
Type: Developer
RM Skill: Beginner
Just like the title says. Okay, here's the recipes instructions from the advanced crafting system.
Hide/Show
#------------------------------------------------------------------------------ # # This class defines a recipe object for use with the crafting system # #------------------------------------------------------------------------------
#----------------------------------------------------------------------------- # # name: Name of item that the recipe makes # ingredients[]: An array of the ingredients used to make the item # ingAmounts[]: An array containing the amount of each ingredient needed # itemCreated: An int representing the item to be created # createdAmount: The amount of items to be created by the recipe normally # criticalItem: The item that is created if the recipe is a critical success # critAmount: Amount of the critical item created on a critical success # critChance: Chance this recipe will be criticaled. This is modded by # the party's average intelligence when the crafting system # creates the recipe. # difficulty: int 0 to 9 where 0 is easiest and 9 is most difficult #----------------------------------------------------------------------------- def initialize( name, ingredients, ingAmounts, itemCreated, createdAmount, criticalItem, critAmount, critChance, difficulty, bonusStat, bonusInterval, category) @name = name @ingredients = ingredients @numOfIngredients = ingredients.length @ingAmounts = ingAmounts @itemCreated = itemCreated @createdAmount = createdAmount @criticalItem = criticalItem @criticalName = criticalItem.name @critAmount = critAmount @critChance = critChance @difficulty = difficulty @bonusStat = bonusStat @bonusInterval = bonusInterval @category = category @discovered = false
#-------------------------------------------------------------------------- # Recipe behavior customization starts here. # # @allowDiscoveryByItems: Allows recipes to be discovered when # ingredients of the recipe have been found # @requireAllItems: Requires all items of a recipe to be found # before the recipe will be revealed. # @allowStatBonuses: Allows bonus critical chance from the party's # current stats. # @requireStatThreshold: Requires an amount of the bonus stat in order # to craft the item. # @requireTools: Requires the presence of crafting tools to # make an item. #-------------------------------------------------------------------------- @allowDiscoveryByItems = true @requireAllItems = false @allowStatBonuses = true @requireStatThreshold = false @requireTools = true end
#---------------------------------------------------------------------------- # Determines if the item is currently able to be crafted by the party #---------------------------------------------------------------------------- def isCraftable?
#check to see if the party has enough of each needed ingredient for x in 1..@numOfIngredients if $game_party.item_number(@ingredients[x-1]) < @ingAmounts[x-1] @disabledReason = "You don't have enough of the required ingredients!" return false end end
#check to see if the party has the right tools if @requireTools requiredTools = $game_crafting.tools(@category) for tool in requiredTools if not $game_party.has_item?($data_items[tool]) @disabledReason = "You don't have a required tool!" return false end end end
#now check to see if the party has the neccessary stat if @requireStatThreshold avgStat = totalStat / $game_party.members.length if avgStat < $game_crafting.difficulties(@bonusStat)[@difficulty] case @bonusStat when 0 @disabledReason = "The party is not strong enough to make this item yet!" when 1 @disabledReason = "The party is not hardy enough to make this item yet!" when 2 @disabledReason = "The party is not smart enough to make this item yet!" when 3 @disabledReason = "The party is not swift enough to make this item yet!" end return false end end
#if we didn't return yet, then the party has enough of each ingredient #and is smart enough to figure out how to put everything together return true end
#---------------------------------------------------------------------------- # Determines if the recipe has been discovered by the party. # Recipes reveal when at least one ingredient is discovered or if they # Are found in the gameworld from a book, npc or other method #---------------------------------------------------------------------------- def isDiscovered? #check the flag first! if @discovered return true end
#now check inventory for at least one item of each ingredient. include #equiped items! If we have it, then set the flag before returning. if @allowDiscoveryByItems totalItemsFound = 0 for x in 1..@numOfIngredients if $game_party.has_item?(@ingredients[x-1], true) totalItemsFound += 1 if not @requireAllItems @discovered = true return true end end end if totalItemsFound == @numOfIngredients @discovered = true return true end end
#discovered flag is false and the party doesn't have any of the ingredients return false end
#---------------------------------------------------------------------------- # These methods check the created item's type #---------------------------------------------------------------------------- def makesWeapon? return @itemCreated.is_a?(RPG::Weapon) end
def makesArmor? return @itemCreated.is_a?(RPG::Armor) end
def makesItem? return @itemCreated.is_a?(RPG::Item) end
#---------------------------------------------------------------------------- # this will set discovered to true. this is so game NPCs, books or other # events can grant recipes that the party does not have ingredients for yet #---------------------------------------------------------------------------- def setDiscovered @discovered = true end
#---------------------------------------------------------------------------- # This will execute the crafting recipe, removing the components and adding # the result to the party's inventory #---------------------------------------------------------------------------- def make #remove ingredients for x in 1..@numOfIngredients $game_party.lose_item(@ingredients[x-1], @ingAmounts[x-1]) end
#make item! if rand(100) < totalCritChance $game_party.gain_item(@criticalItem, @critAmount) @criticaled = true else $game_party.gain_item(@itemCreated, @createdAmount) end end
def calcCriticalChance if @allowStatBonuses # set stat bonus avgStat = (totalStat / $game_party.members.length) statBonus = avgStat - $game_crafting.difficulties(@bonusStat)[@difficulty] statBonus /= @bonusInterval totalCritChance = @critChance + statBonus else totalCritChance = @critChance end if totalCritChance > 100 totalCritChance = 100 end
return totalCritChance end
#---------------------------------------- # Returns the party's total intelligence #---------------------------------------- def totalStat x = 0 total = 0 case @bonusStat when 0 while x < $game_party.members.length total += $game_party.members[x].base_atk x += 1 end when 1 while x < $game_party.members.length total += $game_party.members[x].base_def x += 1 end when 2 while x < $game_party.members.length total += $game_party.members[x].base_spi x += 1 end when 3 while x < $game_party.members.length total += $game_party.members[x].base_agi x += 1 end end
return total end
#--------------------------------------- # Returns the recipe icon index #--------------------------------------- def icon_index(critical = false) if critical return @criticalItem.icon_index else return @itemCreated.icon_index end end
#-------------------------------------------- # Resets the recipe critical flag to normal #-------------------------------------------- def resetCriticaled @criticaled = false end
end
Here's my customized recipe category list.
Hide/show
#-------------------------------------------------------------------- # # This class implements the custom crafting system. The instanced # variable name is $game_crafting # #--------------------------------------------------------------------
#---------------------------------- # Init the system. #---------------------------------- def initialize initRecipes initDifficulties initCategories end
#----------------------------------------------------------------------------- # creates the array for difficulty level comparisons. # Current party must have an average of this int in order to make the item #----------------------------------------------------------------------------- def initDifficulties @atkThresholds = [25, 40, 55, 70, 85, 100, 115, 130, 145, 160] @defThresholds = [25, 40, 55, 70, 85, 100, 115, 130, 145, 160] @spiThresholds = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250] @agiThresholds = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250] end
#----------------------------------------------------------------------------- # Defines the text and required tools of each category #----------------------------------------------------------------------------- def initCategories #--------------------------------------------------------------------------- # Type in the names of your crafting categories here. As you can see, you # are not required to use all 10 spaces! Just make sure to have a comma # after the quotations for every item EXCEPT the last. #--------------------------------------------------------------------------- @categoryLabels = [ #Category 0 "Cooking",
#Category 1 "Sewing",
#Category 2 "Pharmacy",
#Category 3 "Jewelry",
#Category 4 "Rock Polishing",
#Category 5 "Battle Items",
#Category 6 "Materials",
#Category 7 #Category 8 ] #--------------------------------------------------------------------------- # Each number refers to the RPG::Item index of the required tool. You # should have the same number of categories here as you did above! # Make sure there is a comma after every bracket pair [] EXCEPT the last! #--------------------------------------------------------------------------- @requiredTools = [ #Category 0 [73,74,75],
#Category 1 [77,76],
#Category 2 [80,81,82],
#Category 3 [83,84,85],
#Category 4 [88,89],
#Category 5 [86,87],
#Category 6 [86,87],
#Category 7 #Category 8 ] #--------------------------------------------------------------------------- # This is the text that appears in the help box of the crafting menu # when hovering over a category label. Same rule for commas! #--------------------------------------------------------------------------- @categoryText = [ #Category 0 "Cook up great concoctions and delicacies.",
#Category 1 "Sew your own clothes.",
#Category 2 "Brew drinks, medicine, and other useful substances.",
#Category 3 "Polish beautiful gems and create jewelry.",
#Category 4 "Shine up rocks to reveal beautiful gems",
#Category 5 "Create items of mass destruction. Meant for battle.",
#Category 6 "All other materials for crafting are created here.",
#Category 7 #Category 8 ] @categoryStates = [] end
#--------------------------------------------------------------------------- # Get the recipe list from the file (include a recipes.txt in Data folder) #---------------------------------------------------------------------------- def initRecipes @recipes = [] x = 0 fileName = "Data/recipes.txt"
if File.exists?(fileName) recipeFile = File.new(fileName, "r") buildRecipeList(recipeFile) exportData else @recipes = load_data("Data/recipes.rf") end end
def buildRecipeList(recipeFile) while (line = recipeFile.gets) thisRecipe = createNewRecipe(line) @recipes.push(thisRecipe) unless thisRecipe == nil end end
def exportData fileName = "Data/recipes.rf" if File.exists?(fileName) File.delete(fileName) end file = File.new(fileName, "wb") Marshal.dump(@recipes, file) end #---------------------------------------------------------------------------- # returns a new Recipe object. the recpies.txt file should have data in the # following format: # # name: Name of the item being created # itemType: 0 for item, 1 for weapon, 2 for armor. The normal # and critical form MUST be the same item type! # numOfIngs: number of different ingredients from 1 to 9 # ingreds 01..2999: the item indexes of the ingredients. the first # character determines the item type for each # ingredient. 0 for item, 1 for weapon, 2 for armor # amounts 1..999: amount of each ingredient # normalItem: index of item created on normal success # normalAmount: amount of normal item created on success # criticalItem: item created from a critical success # critAmount: amount of crit item created # critChance: chance to crit (out of 100) # difficulty: integer 0 to 9 where 0 is easiest and 9 is hardest # bonusStat: The statistic that will be used to calculate the # bonus critical chance. 0 for attack, 1 for defense, # 2 for spirit, 3 for agility. # bonusInterval: The amount of the bonus stat it takes to get a 1% # higher critical chance # category: The type of crafting (smithing, woodworking, etc.) # As an integer from 0 to 9! # # The file allows for empty lines and comments using '#' to start a line # Here's some example lines from the file: # # #Leather Working # Rough_Leather 0 1 0204 2 205 1 205 3 10 0 2 10 1 # # NOTE: whitespace in the name must be replaced with underscores!!! # #---------------------------------------------------------------------------- def createNewRecipe(stringToParse) #first check for nil and comments return nil if stringToParse == nil return nil if stringToParse.strip.empty? return nil if stringToParse.lstrip.index("#") != nil
#first parse out the text info #split at the whitespace attributes = stringToParse.split
name = attributes[0].gsub("_", " ") #the first position is name itemType = attributes[1].to_i #2nd is item type numOfIngs = attributes[2].to_i #3nd position is the num of ingredients x = 0 ingreds = [] #ingredients start at the 3rd position while x < numOfIngs number = attributes[x + 3] ingredientType = number[0,1].to_i index = number[1,number.length - 1].to_i case ingredientType #switch for ingredients when 0 ingreds.push($data_items[index]) when 1 ingreds.push($data_weapons[index]) when 2 ingreds.push($data_armors[index]) end x += 1 end y = 0 amounts = [] #amounts start after the ingredients while y < numOfIngs amounts.push(attributes[x + y + 3].to_i) y += 1 end currentIndex = x + y + 3 case itemType #switch for resulting items when 0 normalItem = $data_items[attributes[currentIndex].to_i] criticalItem = $data_items[attributes[currentIndex + 2].to_i] when 1 normalItem = $data_weapons[attributes[currentIndex].to_i] criticalItem = $data_weapons[attributes[currentIndex + 2].to_i] when 2 normalItem = $data_armors[attributes[currentIndex].to_i] criticalItem = $data_armors[attributes[currentIndex + 2].to_i] end normalAmount = attributes[currentIndex + 1].to_i critAmount = attributes[currentIndex + 3].to_i critChance = attributes[currentIndex + 4].to_i difficulty = attributes[currentIndex + 5].to_i bonusStat = attributes[currentIndex + 6].to_i bonusInterval = attributes[currentIndex + 7].to_i category = attributes[currentIndex + 8].to_i
#next, create the Recipe object, initialize it and return it! thisRecipe = Recipe.new(name, ingreds, amounts, normalItem, normalAmount, criticalItem, critAmount, critChance, difficulty, bonusStat, bonusInterval, category) return thisRecipe end
#---------------------------------------------------------------------------- # Returns the array of recipes that are available #---------------------------------------------------------------------------- def recipeList return @recipes end
#---------------------------------------------------------------------------- # Discovers the recipe at recipeIndex #---------------------------------------------------------------------------- def discover(recipeIndex) @recipes[recipeIndex].setDiscovered end
#---------------------------------------------------------------------------- # Returns the difficulties of the specified stat #---------------------------------------------------------------------------- def difficulties(stat) case stat when 0 return @atkThresholds when 1 return @defThresholds when 2 return @spiThresholds when 3 return @agiThresholds end end
#---------------------------------------------------------------------------- # Returns the array of required tools for the specified category #---------------------------------------------------------------------------- def tools(category) return @requiredTools[category] end
#---------------------------------------------------------------------------- # Returns the name of the statistic being requested #---------------------------------------------------------------------------- def statName(stat) case stat when 0 return "Attack" when 1 return "Defense" when 2 return "Intelligence" when 3 return "Agility" end end end
Here's what happens. I made Mushroom_Soup, right? Everything's fine. Except the fact that next to ingredients and what it makes, the icons are mismatched, but I can live with that. I thought I followed the instructions for everything else, but none of the other recipes are popping up when I meet all the requirements in-game for a recipe to show up. What gives? Am I just missing something really obvious? Or is there a certain place this has to be put for the script to work? (I have a feeling it's my recipe making that screwed it up.)