Jump to content

Recommended Posts

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 to

chef.components.inventory:GiveItem(SpawnPrefab(item.prefab))

end

end

@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

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 by bigpak

@bigpak

Hmm. 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)

@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

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 :p

 

Edited by bigpak

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)

Yeah but where do I edit that code, I'm an idiot sorry :p. 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.

@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...