bigpak Posted February 17, 2015 Share Posted February 17, 2015 Hello, I am trying to make an item to where it will return two items from cooking an item, is this possible? If so what do I do, I have no idea, however I suspect it will involve changing the cookable component. Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/ Share on other sites More sharing options...
Mobbstar Posted February 18, 2015 Share Posted February 18, 2015 Set the function oncooked in the cookable component (source: unofficial DS API Docs) It gets two variables: item and chef. It should be sufficient to do something like this (no guarrantee):local function GiveTwo(item, chef)if chef and chef.components.inventory then --assure there is a guy to give this tochef.components.inventory:GiveItem(SpawnPrefab(item.prefab))endend Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614290 Share on other sites More sharing options...
Blueberrys Posted February 18, 2015 Share Posted February 18, 2015 @bigpak, It gets two variables: item and chef. It should be sufficient to do something like this (no guarrantee): local function GiveTwo(item, chef) if chef and chef.components.inventory then --assure there is a guy to give this to chef.components.inventory:GiveItem(SpawnPrefab(item.prefab)) end end A few corrections. The oncooked fn actually gets 3 variables. (from cookable.lua)self.oncooked(self.inst, cooker, chef)The item passed in here is the uncooked item's instance, not the cooked item. Giving that to the player won't give two cooked items, but one cooked and one uncooked item. You might also want to check for spoilage rate, etc. Instead of doing it manually, you could just create a new uncooked prefab and pass it into the cook function.item_inst.components.cookable.oncooked = function(item, cooker, chef) -- Attach a variable to keep track of how many have been cooked if not item.components.cookable.cook_amt then item.components.cookable.cook_amt = 1 end -- Only execute if we haven't reached the limit (otherwise it'll cook infinitely) if item.components.cookable.cook_amt < 2 then -- Spawn new uncooked item of the same type new_item = SpawnPrefab(item.prefab) -- Set the cook_amt for the new item as 1 more than current new_item.components.cookable.cook_amt = item.components.cookable.cook_amt + 1 -- Cook the new item cooked_item = new_item.components.cookable:Cook(cooker, chef) -- Give the cooked item to the player if cooked_item then chef.components.inventory:GiveItem(cooked_item) end -- Remove the uncooked item we spawned new_item:Remove() endend Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614331 Share on other sites More sharing options...
bigpak Posted February 18, 2015 Author Share Posted February 18, 2015 (edited) Ok, where would I go about editing this, sorry im still new. Other thing I wanted to add was I don't want the items to be cooked, I literally want it to return prefabs, so lets say a pot. I'm working on a food mod and with some help I got the crafting to return stuff, but now I need it for a fire and im not sure where to go about doing this. Apologies for being clueless Edited February 18, 2015 by bigpak Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614339 Share on other sites More sharing options...
Blueberrys Posted February 18, 2015 Share Posted February 18, 2015 @bigpakHmm. Not sure if I understood correctly. You want the player to receive some arbitrary times when something specific is cooked? Like for example, if you cook a fish, you get a cooked fish and two twigs?local function fish_postinit(inst) inst.components.cookable.oncooked = function(item, cooker, chef) -- Might wanna check if chef exists and has an inventory chef.components.inventory:GiveItem(SpawnPrefab("twigs")) chef.components.inventory:GiveItem(SpawnPrefab("twigs")) endendAddPrefabPostInit("fish", fish_postinit) Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614341 Share on other sites More sharing options...
bigpak Posted February 18, 2015 Author Share Posted February 18, 2015 Lets say I have a pot with some water in it, I want it to return the pot one item, and salt another item. I am making an overhaul of the food system, so there will be complex recipes, flour, dough, etc. Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614344 Share on other sites More sharing options...
Blueberrys Posted February 18, 2015 Share Posted February 18, 2015 @bigpak Uhm.. I still don't understand, sorry.Do you want to make something like the crock pot, where you can put in multiple ingredients to make something else?What do you mean by "return the pot"? Do you want the pot to be given to the player when they try to cook something? That seems really strange (and kinda funny) the way I'm imagining it. o.o Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614348 Share on other sites More sharing options...
bigpak Posted February 18, 2015 Author Share Posted February 18, 2015 (edited) Sorry, I mean literally having a item called a pot, thats in your inventory. It's filled with water, you boil it/cook it over the campfire, just like any other cookable product, it gives you back the pot and salt. Its simple, you cook an item and it gives you two things back. EDIT: sigh I'm an idiot, the method you supplied above, the one with the twigs and the chef component works, I'm just an idiot. Sometimes I feel like I should just stop because of the silly mistakes Edited February 18, 2015 by bigpak Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614360 Share on other sites More sharing options...
Mobbstar Posted February 18, 2015 Share Posted February 18, 2015 Sorry, I mean literally having a item called a pot, thats in your inventory. It's filled with water, you boil it/cook it over the campfire, just like any other cookable product, it gives you back the pot and salt. Its simple, you cook an item and it gives you two things back. We thought you wanted the same product twice. What you're trying to do should be even easier, the function I gave you is almost useable. Set the cooking product to the pots prefab name, and change "item.prefab" in my function to the salts prefab name. (you can also add conditions for what to make when boiled. I'd mention it since you are trying to go advanced) Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614366 Share on other sites More sharing options...
bigpak Posted February 18, 2015 Author Share Posted February 18, 2015 Yeah but where do I edit that code, I'm an idiot sorry . Does it go in a component, a function in modmain or a prefab? I can understand blueberrys mostly because its simple and effective, but I don't understand what you posted, sorry, can you explain please? Sorry to be a pest. Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614368 Share on other sites More sharing options...
Corrosive Posted February 19, 2015 Share Posted February 19, 2015 @bigpak, Set the function oncooked in the cookable component He's referring to the cookable component of your pot prefab. Think about what you want to do for a moment-- component: Do you want to change ALL instances of "oncooked" on every cookable prefab? Probably not. modmain: Do you want to modify the functionality of "oncooked" on the cookable component of already existing prefabs ( through AddPrefabPostInit() )? Probably not. prefab: Do you want to modify the functionality of "oncooked" for the prefab that your mod is defining? Yes! Here's all you need to do: In the pot prefab's initialization function, add the cookable component. After that, override the default oncooked method of the prefab's cookable component by pointing it to a new function like this: inst.components.cookable.oncooked = function(item, cooker, chef) if chef and chef.inventory then chef.components.inventory:GiveItem(SpawnPrefab("pot")) chef.components.inventory:GiveItem(SpawnPrefab("salt")) end end Link to comment https://forums.kleientertainment.com/forums/topic/51108-getting-more-than-one-item-from-cooking-something/#findComment-614499 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