Scoobie101 Posted May 8, 2016 Share Posted May 8, 2016 Hello again Klei forums. I have yet another scripting question. How do I make it so my mod character crafts things with a different recipe? Like, normal characters craft straw hats with 12 grass but I want my character to craft it with only 6. Kinda like the green amulet but only with dress items. Link to comment Share on other sites More sharing options...
DarkXero Posted May 9, 2016 Share Posted May 9, 2016 13 hours ago, Scoobie101 said: Kinda like the green amulet but only with dress items. Alright, I did this: local character_prefab = "wilson" local character_tag = "scoobie101" local AllRecipes = GLOBAL.AllRecipes local RECIPETABS = GLOBAL.RECIPETABS local require = GLOBAL.require local STRINGS = GLOBAL.STRINGS local dress_recipes = {} local function AfterEverythingLoaded() for k, v in pairs(AllRecipes) do if v.tab == RECIPETABS.DRESS then dress_recipes[k] = v end end for k, v in pairs(dress_recipes) do local new_name = v.name.."_"..character_tag local new_ingredients = {} for m, n in pairs(v.ingredients) do table.insert(new_ingredients, Ingredient(n.type, math.ceil(n.amount / 2), n.atlas)) end for m, n in pairs(v.character_ingredients) do table.insert(new_ingredients, Ingredient(n.type, n.amount, n.atlas)) end local new_recipe = AddRecipe(new_name, new_ingredients, v.tab, v.level, v.placer, v.min_spacing, v.nounlock, v.numtogive, character_tag, v.atlas, v.image) new_recipe.sortkey = v.sortkey new_recipe.product = v.name STRINGS.NAMES[string.upper(new_name)] = STRINGS.NAMES[string.upper(v.name)] STRINGS.RECIPE_DESC[string.upper(new_name)] = STRINGS.RECIPE_DESC[string.upper(v.name)] end end AddSimPostInit(AfterEverythingLoaded) local function NoDressRecipes(inst) local _CanLearn = inst.replica.builder.CanLearn inst.replica.builder.CanLearn = function(self, recipename) return not dress_recipes[recipename] and _CanLearn(self, recipename) end end local function EditBuilderReplica(inst) inst:AddTag(character_tag) inst:DoTaskInTime(0, NoDressRecipes) end AddPrefabPostInit(character_prefab, EditBuilderReplica) Put it in modmain.lua. You only need to specify character_prefab (of your character), and character_tag (which will be given for the special recipes). This basically clones all the dress recipes and changes the ingredients, then makes the originals invisible to people playing your character. Link to comment Share on other sites More sharing options...
Scoobie101 Posted May 9, 2016 Author Share Posted May 9, 2016 Wow. That is a WALL of code, I never would've figured that out. Thanks :3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now