Jump to content

Recommended Posts

 Shortly, a mod that stop food spoiling after being done on a drying rack and in the crock pot. This is what I have.

PrefabFiles = {	"meatrack","cookpot",}function NoSpoil_Rack(inst) 	if inst.components.dryer and inst.components.dryer.spoiltask then	    inst.components.dryer.spoiltask:Cancel()	    inst.components.dryer.spoiltask = nil	    -- inst.components.dryer.spoiltargettime = nil	endendfunction NoSpoil_Pot(inst)	if inst.components.stewer and inst.components.stewer.spoiltask then	    inst.components.stewer.spoiltask:Cancel()	    inst.components.stewer.spoiltask = nil	endendAddPrefabPostInit("meatrack", NoSpoil_Rack)AddPrefabPostInit("cookpot", NoSpoil_Pot)

Can anyone help?

Link to comment
https://forums.kleientertainment.com/forums/topic/39602-helpwhat-did-i-wrong-here/
Share on other sites

What did you do wrong here?

 

Maybe you need to set a periodic task?

 

Why would I need a periodic task? I need a set it and forget it approach. What I think I need to do is add custom onload,onsave,ondoncecooking and oncontinuedone.

 

What I'm trying to do now is make the the component(stewer) use a custom local function based on the one present in the cookpot prefab, but the issue is, that function is referencing other local functions leading me eventually into an error.

 

I mean. I want to make inst.components.stewer.ondonecooking = custom_function. But first I need to copy the original function, but that leads into many other missing functions. And it ends with me having to load the cooking.lua script from the modmain, and I have no idea how to do that. I put a copy of it in the scripts folder of the mod, and wrote a require line, and it still gives me an error.

function NoSpoil_Pot(inst)

if inst.components.stewer then

inst.components.stewer.onspoil = nil

local oldFunc = inst.components.stewer.Harvest

inst.components.stewer.Harvest = function(inst, harvester)

inst.targettime = GetTime() --make it cooked just now

oldFunc(inst, harvester)

end

end

end

You shouldn't need a require line if you put a copy of the stewer component in your scripts directory. If you upload a copy of your mod, I can try to take a look at the code.

 

http://www.filedropper.com/nostewerspoilage

 

A copy of cooking.lua not stewer. What I want to do is to override "inst.components.stewer.ondonecooking = donecookfn". The current state of the mod (that's uploaded) will result in a crash because of the local functions. Ignore the custom components, those are a backup plan.

function NoSpoil_Pot(inst)	if inst.components.stewer then		inst.components.stewer.onspoil = nil		local oldFunc = inst.components.stewer.Harvest		inst.components.stewer.Harvest = function(inst, harvester)			inst.targettime = GetTime() --make it cooked just now			oldFunc(inst, harvester)		end	endend

 

Crashes, GetTime isn't defined.

 

Sure it is not, bacause it's in global space. I was hoping you could fix any little things that I missed. :)

function NoSpoil_Pot(inst)    if inst.components.stewer then        inst.components.stewer.onspoil = nil        local oldFunc = inst.components.stewer.Harvest        inst.components.stewer.Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime() --make it cooked just now            oldFunc(inst, harvester)        end    endend

 

Sure it is not, bacause it's in global space. I was hoping you could fix any little things that I missed. :-)

function NoSpoil_Pot(inst)    if inst.components.stewer then        inst.components.stewer.onspoil = nil        local oldFunc = inst.components.stewer.Harvest        inst.components.stewer.Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime() --make it cooked just now            oldFunc(inst, harvester)        end    endend

 

  Well, besides the character saying "I can't do that" after harvesting, it works. But when I tried applying the same principle to the Rack, I can't even harvest it, it goes into the animation and then says "I can't do that". This is what I have.

function NoSpoil_Rack(inst)     if inst.components.dryer then        inst.components.dryer.spoiltask = nil        local Function = inst.components.dryer:Harvest        inst.components.dryer:Harvest = function(inst, harvester)            inst.targettime = GLOBAL.GetTime()            Function(inst, harvester)        end    endend

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